Bare-metal STM32 lesson plan
Under the HAL on an STM32F411 Black Pill: the reference manual and its memory map, RCC and the PLL, GPIO registers, SysTick, a USART driver and timer PWM written by hand, and a cubesat Morse beacon with no driver but your own.
Objectives and materials
By the end, students can
- The reference manual, the memory map and the clock gates.
- GPIO registers and the Cortex-M SysTick.
- A USART driver and timer PWM, register by register.
- A driver-free cubesat Morse beacon.
Materials for the whole unit
- Frequency counter
- LED x 3
- Piezo speaker
- Pushbutton
- Resistor x 3
- STM32F411 Black Pill
Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.
Reading the chip
The reference manual, the memory map and the clock gates.
| Lesson | Time | What students do |
|---|---|---|
| The reference manualEvery peripheral is a block of addresses. Read registers straight from RM0383’s memory map, find their reset values, watch a port read 0 until its clock is on, and blink the LED through a raw pointer. | 60 min |
|
| Clocks and RCCA write to a port with its clock off is lost; the same write after RCC_AHB1ENR sticks. Then the PLL: PLLCFGR worked out for 84 MHz from the Black Pill’s 25 MHz crystal, and the switch to it, bit by bit. | 60 min |
|
Materials
- Frequency counter
- LED x 3
- Pushbutton
- Resistor x 3
- STM32F411 Black Pill
Check for understanding
Each student finishes "Clocks and RCC" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "What the model does with clocks".
Pins and time
GPIO registers and the Cortex-M SysTick.
| Lesson | Time | What students do |
|---|---|---|
| GPIO registersThe KEY button on PA0 with its pull-up set in PUPDR, read from IDR, and mirrored onto two LEDs through BSRR: one active low on PC13, one active high on PB12. MODER, PUPDR, IDR and BSRR, bit by bit. | 60 min |
|
| SysTickThe Cortex-M4’s own 24-bit timer, programmed directly: a reload for a 1 ms tick at 84 MHz, COUNTFLAG polled instead of an interrupt, the longest tick 24 bits allow, and an LED blinked by counting. | 55 min |
|
Materials
- Frequency counter
- LED x 3
- Pushbutton
- Resistor x 3
- STM32F411 Black Pill
Check for understanding
Each student finishes "SysTick" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Blink faster".
Peripherals by hand
A USART driver and timer PWM, register by register.
| Lesson | Time | What students do |
|---|---|---|
| USART by handUSART1 with no Serial library: PA9 and PA10 to alternate function 7, BRR worked out for 115200 baud at 84 MHz, and bytes sent and received by polling TXE and RXNE. A whole driver in forty lines. | 55 min |
|
| Timer PWM by handTIM3 channel 1 on PA6 set up register by register: the prescaler to 1 MHz, ARR for a 1 kHz period, CCR1 for the duty, PWM mode 1 with preload, and a frequency counter checking the result while the LED breathes. | 60 min |
|
Materials
- Frequency counter
- LED x 3
- Pushbutton
- Resistor x 3
- STM32F411 Black Pill
Check for understanding
Each student finishes "Timer PWM by hand" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Resolution and frequency".
Boss project
A driver-free cubesat Morse beacon.
| Lesson | Time | What students do |
|---|---|---|
| Boss: a cubesat Morse beaconA driver-free device: RCC, GPIO, SysTick, USART1 and TIM3 programmed by hand, not one Arduino call. It keys a callsign in Morse as an 800 Hz tone and the LED, and takes a new message from the ground station. | 70 min |
|
Materials
- Frequency counter
- LED x 2
- Piezo speaker
- Pushbutton
- Resistor x 2
- STM32F411 Black Pill
Check for understanding
Each student finishes "Boss: a cubesat Morse beacon" on their own, without opening the hints. The simulator checks 8 of its 8 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Make it yours".
Teach this unit as a class
Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.
The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.