Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

bare-metal-stm32

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.

Why

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.

What's going in here

  1. linker script and startup code; vector table, copying .data, zeroing .bss
  2. blink an LED by writing GPIO registers directly
  3. SysTick so the delay is real milliseconds and not a guess
  4. a polling UART driver on USART2
  5. a small printf on top of that UART

Tools

  • arm-none-eabi-gcc and make (I'm running them in Ubuntu on WSL2)
  • Renode

Build

make

Status

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

Run

make
renode renode/run.resc

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

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages