https://github.com/patrislav1/ioc2cmake
Generate CMake build and vscode setup from STM32CubeMX project file
https://github.com/patrislav1/ioc2cmake
cmake cubemx stm32 stm32cubemx vscode
Last synced: 7 months ago
JSON representation
Generate CMake build and vscode setup from STM32CubeMX project file
- Host: GitHub
- URL: https://github.com/patrislav1/ioc2cmake
- Owner: patrislav1
- License: mit
- Created: 2018-09-06T12:44:41.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2021-04-29T14:20:39.000Z (over 4 years ago)
- Last Synced: 2025-03-08T03:46:10.163Z (8 months ago)
- Topics: cmake, cubemx, stm32, stm32cubemx, vscode
- Language: Python
- Size: 24.4 KB
- Stars: 9
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ioc2cmake
## This repository is deprecated, please use [cubemx.cmake](https://github.com/patrislav1/cubemx.cmake) instead.
#
This is a small Python tool that allows building [STM32CubeMX](https://www.st.com/en/development-tools/stm32cubemx.html) generated firmware with [CMake](https://cmake.org/). It parses STM32CubeMX `*.ioc` project files and generates CMake variables containing the appropriate settings for the microcontroller (include paths, compiler flags, etc.).
For [VScode](https://code.visualstudio.com/), it generates a `c_cpp_properties.json` config file, containing the relevant include paths & compiler definitions - as well as `launch.json` and `settings.json` files for the debugger. (The [CortexDebug](https://github.com/Marus/cortex-debug) extension should be installed in order to use the debugger). With these config files, VScode can be used as an IDE for the firmware project.
### How it works
`ioc2cmake` is called at configuration stage from within the CMake script. It spits out a list of `key=value` pairs on stdout, which are captured by the CMake script and saved in variables. These variables are then used to configure the firmware build.
Because the STM32 MCU type, include paths etc. are not hardcoded in the `CMakeLists.txt` but generated at configure stage, firmware can be ported to different MCUs without changing the build script, and the build script can be reused on firmwares targeting other STM32 MCUs.
### Usage
Call `ioc2cmake` from the CMake script like this:
```
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/ioc2cmake.py
${CMAKE_SOURCE_DIR} # Path to source tree
${CMAKE_SOURCE_DIR}/cubemx-proj.ioc # Path to CubeMX project file
-s ${CMAKE_SOURCE_DIR}/app # Extra source folder
-i ${CMAKE_SOURCE_DIR}/app # Extra include folder
-t /opt/gcc-arm-none-eabi-7-2017-q4-major # Toolchain location
-v # Create vscode properties file
OUTPUT_VARIABLE ConfigContents
)
```
It needs the path to the source tree, path to the CubeMX `*.ioc` project file and the path to the [toolchain](https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads). It assumes the regular CubeMX generated source structure. Additional source and include directories can be added with `-s` and `-i` switches, respectively. (I like to put my written source files in other directories than the autogenerated ones, for better clarity).There is an example `CMakeLists.txt` in the repository demonstrating the use of `ioc2cmake`.
The firmware build can be set up like a regular CMake build.
It works with CubeMX LL drivers, HAL drivers, as well as with a mixed setup.
### Caveats
For Cortex-M7 MCUs, at the moment it always assumes a double-precision FPU, but there are M7's which have single precision only.
Tested on following MCUs / boards so far:
- STM32F407 / STM32F407G-DISC1
- STM32F767 / NUCLEO-F767ZI
- STM32L433 / NUCLEO-L433RC-P
- STM32L476 / NUCLEO-L476RG
- STM32L496 / NUCLEO-L496ZG
- STM32L431
- STM32L471Feedback and contributions welcome.