STM32CubeIDE CMake integration
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-18 10:20 AM
Since it took a tremendous amount of effort in getting CMake working within STM32CubeIDE, I'd thought I'd share a method of getting it done. I've only tested this working in Windows. Many an hour could have been saved if ST, in their infinite wisdom, did not disable the Toolchain tree entry in the project C/C++ properties!
Disclaimer: I'm not an experienced Eclipse user, so there is a very good chance that the steps below are not the correct way of doing things, and in future, ST might lock-down or hide more UI rendering these steps useless - you have been warned!
There are a huge number of steps required, so this is not for the fainthearted!
Prerequisite: You must have an existing CMake GNU Arm project up and running, if not, find out how set one up, or use CLion to create a CMake project from an existing STM32CubeMX .ioc.
For the steps, I'm using the following folder layout (adjust to fit your preferences):
Source (source code, folders, etc)
build
.. this where I set CMake to run the builds..
cmake
gnu-arm-stm32.cmake
...
CMakeLists.txt
Tools
STM32CubeIDE
MyProject (the skeleton project created in the below steps)
.cproject
.project
svd
STM32F446.svd
Matthew.
Solved! Go to Solution.
- Labels:
-
STM32CubeIDE
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-18 10:20 AM
Requires: STM32CubeIDE 1.5.0+, CMake and Ninja-build installed
Install CMake plugins
- Help > Eclipse Marketplace : Install cmake4eclipse and CMake Editor
Ensure global Indexer settings are correct
- Window > Preferences > C/C++ > Indexer
- Restore Defaults
- Build configuration for the indexer: Use active build configuration
- Apply and close
Create skeleton STM32 project
- File > New > STM32 project
- Select target device
- Location: Create a new folder (MyProject) to hold the project separately from the source code (must outside the source code folder due to folder-link conflicts!)
- Targeted project type: Empty
- Finish
Switch toolchain builder to CMake
- Project > Close
- Open the new .project in a text editor
- Comment out MCUProjectNature
- <!-- <nature>com.st.stm32cube.ide.mcu.MCUProjectNature</nature> -->
- Project > Open
- Project > Properties > C/C++ Build > Tool Chain Editor
- Configuration: Debug
- Current builder: CMake builder
- Apply
- Repeat for all other configurations
- Apply and Close
- Project > Close
- Open .project in a text editor
- Un-comment MCUProjectNature
- <nature>com.st.stm32cube.ide.mcu.MCUProjectNature</nature>
- Project > Open
Switch indexer to use CMake providers
- Project > Properties > C/C++ General > Indexer
- Restore defaults
- Apply
- Project > Properties > C/C++ General > Preprocessor include paths... > Providers
- Deselect all current providers
- Select
- CMAKE_EXPORT_COMPILE_COMMANDS Compiler Built-ins
- CMAKE_EXPORT_COMPILE_COMMANDS Parser
- Apply
- Repeat for all other configurations
- Apply and close
Add root source code folder containing CMakeLists.txt
- Delete all the project folders and files (except Includes)
- New > Folder
- Advanced > Link to alternate location > Browse : Choose folder which holds the existing CMakeLists.txt (Source)
- Finish
- Project > Properties > Resource > Linked resources > Linked Resources: Convert linked source root to relative
Update Include and Source locations
- Project > Properties > C/C++ general
- Paths and symbols
- Source location
- Configuration: [All configurations]
- Add folder... : Select linked source root folder (Source)
- Delete previously existing project root folder
- Repeat for Release for all other configurations
- Apply
- Symbols
- Configuration: [All configurations]
- Delete all from all configurations
- Apply
- Includes
- Configuration: [All configurations]
- Remove Inc from all languages
- Apply
- Source location
- Apply and close
Configure CMake settings
- Project > Properties > C/C++ Build > Cmake4eclipse
- Configuration: [ All configurations ]
- Build output folder: set path (ie, Source/build/cmake-cubeide-${ConfigName} )
- Apply
- Configuration: Debug
- Cmake4eclipse > Symbols
- Set symbols (use your toolchain file here and any needed settings), ie:
- CMAKE_TOOLCHAIN_FILE:FILEPATH = ../cmake/gnu-arm-stm32.cmake
- CMAKE_BUILD_TYPE:STRING = Debug
- Apply
- Set symbols (use your toolchain file here and any needed settings), ie:
- Cmake4eclipse > Host OS overrides > Windows
- Buildscript generator: Ninja
- Apply
- Cmake4eclipse > Symbols
- Configuration: Release
- Cmake4eclipse > Symbols
- Set symbols (use your toolchain file here and any needed settings), ie:
- CMAKE_TOOLCHAIN_FILE:FILEPATH = ../cmake/gnu-arm-stm32.cmake
- CMAKE_BUILD_TYPE:STRING = RelWithDebInfo
- Apply
- Set symbols (use your toolchain file here and any needed settings), ie:
- Cmake4eclipse > Host OS overrides > Windows
- Buildscript generator: Ninja
- Apply
- Cmake4eclipse > Symbols
- Apply and close
Build all configurations to generate all outputs (.elf)
- Right-click project > Build configurations > Build all
Add debug launch entries
- Run > Debug configurations...
- Select STM32 Cortex-M C/C++ Application
- Create New launch configuration (top-leftmost icon)
- C/C++ Application > Search project: Choose built .elf file and Qualifier (path for debug output)
- Build:
- Build configuration: Debug
- [X] Enable auto build
- Debugger tab
- Setup SWV
- Suspend watchdog counters while halted: Enable
- Startup tab
- [X] Halt on exception
- Common
- Save as: (either)
- Shared file (stored next to .project)
- Local file (stored in {workspace_loc}/.metadata/.plugins/org.eclipse.debug.core/.launches
- Display in favorites menu: [X] Debug
- Save as: (either)
- Apply
- Repeat for all other configurations
- Apply, Close
Matthew.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-18 10:20 AM
Requires: STM32CubeIDE 1.5.0+, CMake and Ninja-build installed
Install CMake plugins
- Help > Eclipse Marketplace : Install cmake4eclipse and CMake Editor
Ensure global Indexer settings are correct
- Window > Preferences > C/C++ > Indexer
- Restore Defaults
- Build configuration for the indexer: Use active build configuration
- Apply and close
Create skeleton STM32 project
- File > New > STM32 project
- Select target device
- Location: Create a new folder (MyProject) to hold the project separately from the source code (must outside the source code folder due to folder-link conflicts!)
- Targeted project type: Empty
- Finish
Switch toolchain builder to CMake
- Project > Close
- Open the new .project in a text editor
- Comment out MCUProjectNature
- <!-- <nature>com.st.stm32cube.ide.mcu.MCUProjectNature</nature> -->
- Project > Open
- Project > Properties > C/C++ Build > Tool Chain Editor
- Configuration: Debug
- Current builder: CMake builder
- Apply
- Repeat for all other configurations
- Apply and Close
- Project > Close
- Open .project in a text editor
- Un-comment MCUProjectNature
- <nature>com.st.stm32cube.ide.mcu.MCUProjectNature</nature>
- Project > Open
Switch indexer to use CMake providers
- Project > Properties > C/C++ General > Indexer
- Restore defaults
- Apply
- Project > Properties > C/C++ General > Preprocessor include paths... > Providers
- Deselect all current providers
- Select
- CMAKE_EXPORT_COMPILE_COMMANDS Compiler Built-ins
- CMAKE_EXPORT_COMPILE_COMMANDS Parser
- Apply
- Repeat for all other configurations
- Apply and close
Add root source code folder containing CMakeLists.txt
- Delete all the project folders and files (except Includes)
- New > Folder
- Advanced > Link to alternate location > Browse : Choose folder which holds the existing CMakeLists.txt (Source)
- Finish
- Project > Properties > Resource > Linked resources > Linked Resources: Convert linked source root to relative
Update Include and Source locations
- Project > Properties > C/C++ general
- Paths and symbols
- Source location
- Configuration: [All configurations]
- Add folder... : Select linked source root folder (Source)
- Delete previously existing project root folder
- Repeat for Release for all other configurations
- Apply
- Symbols
- Configuration: [All configurations]
- Delete all from all configurations
- Apply
- Includes
- Configuration: [All configurations]
- Remove Inc from all languages
- Apply
- Source location
- Apply and close
Configure CMake settings
- Project > Properties > C/C++ Build > Cmake4eclipse
- Configuration: [ All configurations ]
- Build output folder: set path (ie, Source/build/cmake-cubeide-${ConfigName} )
- Apply
- Configuration: Debug
- Cmake4eclipse > Symbols
- Set symbols (use your toolchain file here and any needed settings), ie:
- CMAKE_TOOLCHAIN_FILE:FILEPATH = ../cmake/gnu-arm-stm32.cmake
- CMAKE_BUILD_TYPE:STRING = Debug
- Apply
- Set symbols (use your toolchain file here and any needed settings), ie:
- Cmake4eclipse > Host OS overrides > Windows
- Buildscript generator: Ninja
- Apply
- Cmake4eclipse > Symbols
- Configuration: Release
- Cmake4eclipse > Symbols
- Set symbols (use your toolchain file here and any needed settings), ie:
- CMAKE_TOOLCHAIN_FILE:FILEPATH = ../cmake/gnu-arm-stm32.cmake
- CMAKE_BUILD_TYPE:STRING = RelWithDebInfo
- Apply
- Set symbols (use your toolchain file here and any needed settings), ie:
- Cmake4eclipse > Host OS overrides > Windows
- Buildscript generator: Ninja
- Apply
- Cmake4eclipse > Symbols
- Apply and close
Build all configurations to generate all outputs (.elf)
- Right-click project > Build configurations > Build all
Add debug launch entries
- Run > Debug configurations...
- Select STM32 Cortex-M C/C++ Application
- Create New launch configuration (top-leftmost icon)
- C/C++ Application > Search project: Choose built .elf file and Qualifier (path for debug output)
- Build:
- Build configuration: Debug
- [X] Enable auto build
- Debugger tab
- Setup SWV
- Suspend watchdog counters while halted: Enable
- Startup tab
- [X] Halt on exception
- Common
- Save as: (either)
- Shared file (stored next to .project)
- Local file (stored in {workspace_loc}/.metadata/.plugins/org.eclipse.debug.core/.launches
- Display in favorites menu: [X] Debug
- Save as: (either)
- Apply
- Repeat for all other configurations
- Apply, Close
Matthew.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-18 10:33 AM
(optional) Add updated GNU Arm toolchain
- Window > Preferences > STM32Cube > Toolchain Manager: Select updated GNU Tools for STM32: Install
- Restart
- Window > Preferences > STM32Cube > Toolchain Manager: Select updated GNU Tools for STM32: Set default
- (...still waiting for ST to add the current GNU Arm 10-2020-q4-major...)
(optional) Exclude build folder files from indexing (might speed up indexing?)
- Right-click CMake build output folder > Properties > Resource > Resource Filters (here I'm using Source/build)
- Add Filter...
- Include only, Folders, Project relative path matches: (Regular expression:(
- Source/build/cmake-cubeide-.*
- Add Filter...
- Include only, Files and Folders, [X] All children, Project relative path matches: (Regular expression:(
- .*cmake-cubeide-.*\.(elf|a|obj|su|sizes|sym|map|dump)
- Add Filter...
- Exclude all, Folders, [X] All children, Name matches:
- CMakeFiles
(optional) Add J-Link debug launch entry
- Requires: CDT J-Link plugin (Help > Eclipse marketplace... > Search > Find : Eclipse Embedded CDT, install and select only 'J-Link debugging')
- Run > Debug configurations...
- Select GDB SEGGER J-Link Debugging
- Create New launch configuration (top-leftmost icon)
- C/C++ Application > Search project: Choose built .elf file and Qualifier (path for debug output)
- Replace -Debug with -${config_name:PROJECT_NAME}
- ie: Source/build/cmake-cubeide-${config_name:MyProject}/MyProject.elf
- Build:
- Build configuration: Use Active
- [X] Enable auto build
- Debugger tab
- Device Name: set device name (use J-Link GDB Server app to find correct name)
- GDB client setup
- Executable name: ${gnu_tools_for_stm32_compiler_path}\arm-none-eabi-gdb
- Startup tab
- [X] Enable SWO
- CPU freq: use core/HCLK clock frequency
- Port mask: 0x1F
- [X] Enable SWO
- Common
- Save as: (either)
- Shared file (stored next to .project)
- Local file (stored in {workspace_loc}/.metadata/.plugins/org.eclipse.debug.core/.launches
- Display in favourites menu: [X] Debug
- Save as: (either)
- SVD Path > File path: set svd path (ie, ${project_loc}\..\svd\STM32F446.svd)
- Apply, Close
I have noticed that sometimes the CMake settings do not get saved properly to the .cproject file, so I need to edit that file (xml) before sending it to source control.
If I get a free moment, I'll create a demo blinky project based on a Nucleo and post it here if there's any interest ;).
Matthew.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-21 11:33 PM
Hi @Community member​ ,
Thanks for this valuable contribution.
Don't hesitate to select your own reply as a Best Answer so that this topic will be closed and this will help other users find that answer faster.
-Amel
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-12-22 01:23 AM
Thanks @Amel NASRI​ - Done!
Matthew.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-05-27 11:27 AM
This is fantastic and worked perfectly for me to enable debugging with STM32CubeIDE using an existing CMake project and toolchain. I didn't have to modify any CMake stuff at all. Thanks so much!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-12-02 11:51 AM
Great guide thank you so much! Everything worked perfectly EXCEPT for run/debug configurations. When attempting to run, I get a pop-up window saying I have invalid project settings specifically unknown toolchain. Tried a few things but can't seem to get around this error. Any suggestions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-12-02 12:05 PM
Hi @Community member​ , I've given up on using CMake with STM32CubeIDE as too many changes were made to the IDE to keep it working with CMake. It would make more sense if ST themselves supported CMake in their IDE instead of having their end-users hack a solution together due to their Eclipse customisations. Knowing ST, this will be put on a backlog and it would be a small miracle if it saw the light of day. Sorry I can't be of help anymore on this 'fix'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-12-02 02:22 PM
No problem I completely understand. For anyone else stumbling on this thread, the workaround I found for run/debug configurations is creating another dummy STM32 project with nothing in it with run/debug configurations pointing to the main project's output location on disk. Not great as the run configurations can't force a compile of the selected configuration so you MUST build the required one yourself first from the main project.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-12-19 01:50 AM
Seems like the CMake integration stopped working at least with STM32CubeIDE 1.11.0. The last version I worked with was 1.9.0.
The first steps, to comment out the nature and then edit tool chains, there is no CMake builder available.
Can you point me in the direction where to look further?
