Bare metal STM32F4 examples for various modules
Bare metal STM32F4 examples to serve as starting points for projects. Educational purposes.
Some of the STM32F4xx family based processor headers are added in the include
folder to get register locations. CMSIS library is added for a general support. No extra HAL libraries is used except the selected projects described below.
Common startup functions are located in the include/startup_stm32f407vgtx.s
and include/system_stm32f4xx.c
files to be included in all projects.
First, clone the project using git clone --recurse-submodules https://github.com/fcayci/stm32f4-bare-metal
. The repository includes other repositories such as CMSIS
as submodules under lib
folder. You can alternatively clone the repository, then initialize and update the submodules with git submodule init
and git submodule update
commands.
There are two options for development. First one is to use STM32CubeIDE from ST. Second one is the setup your own development environment. Both options are supported with relevant project settings or makefiles.
makefile contains necessary build scripts and compiler flags for all projects. Individual settings can be changed from local makefiles from projects such as blinky makefile
Browse into any directory and run make
to compile.
cd projects/blinky
make
If everything is setup correctly, you should see the completed message.
Cleaning blinky
Building blinky.c
text data bss dec hex filename
852 8 1568 2428 97c blinky.elf
Successfully finished...
If you see any errors about command not found, make sure the toolchain binaries are in your PATH
. On Windows check the Environment Variables for your account. On Linux/macOS run echo $PATH
to verify your installation.
Run make burn
to program the chip.
...
.. Flash written and verified! jolly good!
Install the ST LINK drivers if you cannot see your board when make burn
is run.
Run make disass
/ make disass-all
to disassamble.
In order to debug your code, connect your board to the PC, run st-util
(comes with stlink utility) from one terminal, and from another terminal within the project directory run make debug
. You can then use general gdb commands to browse through the code.