This template repository contains a CMakeLists.txt
and Visual Studio Code configuration for building STM32 projects with STM32CubeMX. The CMakeLists.txt
loads config from Makefile
generated by STM32CubeMX, providing most device-related parameters. Also utilizes CMake to generate Clangd and OpenOCD configs.
Please install these tools and add them to path
. On Windows, it is suggested to install them via Scoop.
gcc-arm-none-eabi
openocd
cmake
llvm
(Forclangd
andclang-format
)ninja
(For faster build speed)
Install these software from st.com:
- STM32CubeMX
- STM32CubeProgrammer (For ST-LINK drivers and utilties)
Also install these VSCode extensions:
ms-vscode.cpptools
llvm-vs-code-extensions.vscode-clangd
ms-vscode.cmake-tools
marus25.cortex-debug
- Create the STM32CubeMX project, configure the device, and select
Makefile
in Project Manager > Project > Toolchain / IDE - Click "Generate Code" and open the project folder.
- Put the
CMakeLists.txt
and.vscode
folder beside theioc
file. - Open the project folder with VSCode.
- Configure the CMake project with the CMakeTools extension. Select
[Unspecfied]
when prompted to select a kit. - Add custom options, source files and libraries into
CMakeLists.txt
. These changes will be preserved when regenerating project with STM32CubeMX. - To flash your device with ST-LINK, use the
Flash STM32
command in VSCode. - Debug your device in vscode with the
Debug STM32
debug profile.
Please notice that common .gitignore
for C/C++ will exclude binary libraries, causing linking failure after pulling from GitHub. You can retrieve these libraries by regenerating the project with STM32CubeMX.