STM32 & libopencm3 boilerplate
disclaimer
It is not a professional code example. It's only for personal needs to be able to very quickly setup something that is not meant to be perfect but only to work :).
It works with STM32L476 but it can be adjusted to any STM by changing some linker options and opencm3
settings.
prerequisites
- ARM toolchain (xpack - I used 10.3.1-2.3 version)
- Python >3.8 version (3.8.3 for me)
- ninja (from here - I used 1.10.2 version)
- openocd (from here - I used 20211118 version)
- cmake (from here - I used 3.18.6 version)
setup
- Download the repo to the
src
directory. - Create
local.cmake
file in.local
directory in source directory. Fill it with content specified inlocal-cmake-example
. - Create
build
directory on the same level assrc
directory. - Go to
build
directory. - Run cmake (
[path-to-cmake]/cmake.exe -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=[path-to-arm-none-eabi]/arm-none-eabi-gcc.exe -DCMAKE_CXX_COMPILER=[path-to-arm-none-eabi]/arm-none-eabi-g++.exe -G Ninja -DLOCAL_CFG=[path-to-project-sources]/.local/local.cmake [path-to-project-sources]
). - Run
ninja all
. - Run
ninja stm32.flash
. - Enjoy.
While running cmake the important part is: -G Ninja -DLOCAL_CFG=../src/.local/local.cmake
- use Ninja as generator and local.cmake
as file defining your specific paths.