Skip to content

Various project templates for STM32G4 devices with unit tests

Notifications You must be signed in to change notification settings

jc-SpaceXp/STM32G4-Templates

Repository files navigation

STM32G4 Project Templates

Some basic project templates which are intended for the arm-none-eabi-gcc toolchain. Does include support for unit tests if you wish to use them. Otherwise remove the relevant dirs if you decide against testing. Look at other branches for different setups e.g. FreeRTOS support, CMSIS support instead of Libopencm3 etc.

The project itself is blinking the user LED on the STM32G431KB Nucleo device.

Tools

The following tools are needed to build this project

CMake

CLI (No Presets)

# Generation stage (unit tests and stm32 most be in different directories)
cmake . -B build -DCMAKE_TOOLCHAIN_FILE=arm-none-eabi.cmake
cmake . -B testbuild

# Generation stage w/ my cmake debugging prints
cmake . -B testbuild -DDEBUG_CMAKE=True

# Build stage
cmake --build build
cmake --build testbuild

# Flash to stm32 via st-flash (via generated makefile)
make -C build flash-write/fast
# Build and then flash erase stm32
cmake --build build --target all flash-erase

# Running tests via ctest
ctest --test-dir testbuild

Presets

# Generation stage
$ cmake --preset stm32
$ cmake --preset host-tests

# Build stage
$ cmake --build --preset stm32
$ cmake --build --preset host-tests

# Flash to stm32 via st-flash
$ cmake --build --preset stm32 --target=flash-write
# Build and then flash erase stm32
$ cmake --build --preset stm32 --target all flash-erase

# Running tests via ctest
$ ctest --preset host-tests

Submodules

CMSIS will also produce linker warnings due to newlib e.g. “_write is not implemented and will always fail”. There is quite a bit of a size overhead when pulling in all the CMSIS modules. An average project would be around ~100Mb.