Firmware for an STM32F407, written straight from the reference manual; no HAL, no CubeMX, no vendor IDE. Just C, a linker script I wrote myself, and a Makefile.
I don't own the board, so everything runs in Renode, which emulates the STM32F4 Discovery kit well enough to run real firmware on it. The same binary would go on the actual chip.
Most STM32 tutorials start with the HAL, which is fine, but it hides everything. I wanted to know what actually happens between reset and main(), and what "turn on the clock for GPIOD" means when it's just a bit in a register.
- linker script and startup code; vector table, copying
.data, zeroing.bss - blink an LED by writing GPIO registers directly
- SysTick so the delay is real milliseconds and not a guess
- a polling UART driver on USART2
- a small printf on top of that UART
arm-none-eabi-gccandmake(I'm running them in Ubuntu on WSL2)- Renode
makeThe LED blinks. include/stm32f407.h has the RCC and GPIO registers as structs, src/main.c turns on the GPIOD clock and toggles PD12 with a busy loop. The delay is just a counted loop for now so the timing is whatever it happens to be.
make
renode renode/run.rescThe script loads build/firmware.elf on Renode's Discovery kit and turns on logging for the green LED, so you see lines like gpioPortD.UserLED: LED state changed to True in the log.
Register addresses and the memory map I'm working from are in docs/notes.md.