Lesson plan

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.

4 chapters, 7 lessons, about 7 hours, on the STM32F411 Black Pill. Every lesson runs in the browser, with nothing to install.

The unit

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.

Chapter 1. About 2 h

Reading the chip

The reference manual, the memory map and the clock gates.

LessonTimeWhat 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
  1. Registers by address
  2. A base and an offset
  3. A port with no clock
  4. Clock on, reset value back
  5. Blink through a pointer
  6. Read port C
  7. How to read a register page
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
  1. The lost write
  2. Open the gate
  3. Start the crystal
  4. Configure the PLL
  5. Switch over
  6. 96 MHz
  7. What the model does with clocks

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".

Chapter 2. About 1 h 55 min

Pins and time

GPIO registers and the Cortex-M SysTick.

LessonTimeWhat 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
  1. A pull-up from a register
  2. Two bits a pin
  3. Press KEY
  4. Active low
  5. Reading IDR
  6. Invert it
  7. Why BSRR
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
  1. The core’s own timer
  2. Twenty-four bits
  3. Count the ticks
  4. Ticks and toggles
  5. Polling or interrupt
  6. Blink faster

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".

Chapter 3. About 1 h 55 min

Peripherals by hand

A USART driver and timer PWM, register by register.

LessonTimeWhat 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
  1. A baud rate from a divider
  2. Send and receive
  3. Another line
  4. The pins
  5. 9600 baud
  6. What Serial adds
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
  1. Prescaler and reload
  2. Measure it
  3. Mode, preload, enable
  4. The LED breathes
  5. The usual mistakes
  6. 2 kHz
  7. Resolution and frequency

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".

Chapter 4. About 1 h 10 min

Boss project

A driver-free cubesat Morse beacon.

LessonTimeWhat 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
  1. Beacon on
  2. Dits and dahs
  3. The transmitter
  4. The light
  5. Uplink
  6. On repeat
  7. Change the tone
  8. Make it yours

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".

Your class

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.