Example STM32 Project with CMake
This repository uses NUCLEO-STM32L452RE-P board.
The CMake toolchain file is obtained from vpetrigo/arm-cmake-toolchains
.
This repository is generated with STM32CubeMX, so you can regenerate the project if you want with cmake_test.ioc
file.
BUILD
To build the project don't forget to specify the toolchain in the cmake:
mkdir -p build/ && cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=../cmake/arm-gcc-toolchain.cmake
The ARM math library (libarm_cortexM4lf_math.a
) file is obtained from ARM CMSIS repository.
The STM32L4x2.svd
file is used for debugging, and is obtained from KEIL device pack inside CMSIS/SVD
directory. Or get it from posborne/cmsis-svd.
NOTES
This repository doesn't mean to be modular, if you want to use it for another board or project you need to customize the CMakeLists.txt
file.
If you want to customize this repository for another project, there are several things that needs to be changed:
- MCU device definition, in
CMakeLists.txt:11
. - MCU specific compiler flags, in
cmake/arm-gcc-flags.cmake:3-6
. If your MCU supports hardware fpu, you can set theFLOAT_ABI
variable to-mfloat-abi=hard
, otherwise set it to-mfloat-abi=softfp
. - Linker script, in
CMakeLists.txt:16
. - ARM FPU math library linkage, in
CMakeLists.txt:17
. Required if you set theFLOAT_ABI
variable to-mfloat-abi=hard
.
Also there are several config that is infered from MCU device definition, but not yet tested thoroughly:
- Startup file, in
CMakeLists.txt:18
. - HAL related directory, in
CMakeLists.txt:27-28
. - CMSIS related directory, in
CMakeLists.txt:21-23
.