using cmake to quickly organizing your cubemx stm32 project
features:
- HAL/LL and some system library are built as static library so that each time you add your new files/library, you won't wait for a long time rebuilding HAL/LL lib
- generate compile_commands.json which can easily used by visual studio code's auto-complete system.
c_cpp_properties.json
may be edit as below
{
"configurations": [
{
"name": "ProjectName",
"cStandard": "c11",
"cppStandard": "c++11",
"intelliSenseMode": "macos-gcc-arm",
"compileCommands": "${workspaceFolder}/cmake_build/compile_commands.json"
}
],
"version": 4
}
- beta feature: automatically code import and pack to library(speed up code rebuild when sources change)
- STM32CubeMX(Generate with Makefile)
and have settings as below
- STM32CubeProgramer(Flash tool)
- CMake
- arm-none-eabi-gcc toolchain(strongly suggest)
- drag
CMakeLists.txt
from this rep to the root path of your project(which is generate automatically by STM32CubeMX) - edit your project name with below
project(A_NAME_THAT_YOU_LIKE)
- edit
${MCU_FLAGS}
to your hardware platform. if you don't know how to write, find them inMakefile
which generate by CubeMX
# cpu
CPU = -mcpu=cortex-m4
# fpu
FPU = -mfpu=fpv4-sp-d16
# float-abi
FLOAT-ABI = -mfloat-abi=hard
- check defines and include dir recording to your
Makefile
- edit your file and lib settings
- use it well
mkdir cmake_build # anyname\anywhere
cmake ../ # ../ is the dir with CMakeLists.txt
make -j # build with this arg to have max speed
make flash # flash to your device