patrislav1 / ioc2cmake

Generate CMake build and vscode setup from STM32CubeMX project file

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ioc2cmake

This repository is deprecated, please use cubemx.cmake instead.

This is a small Python tool that allows building STM32CubeMX generated firmware with CMake. It parses STM32CubeMX *.ioc project files and generates CMake variables containing the appropriate settings for the microcontroller (include paths, compiler flags, etc.).

For VScode, 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 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. 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
  • STM32L471

Feedback and contributions welcome.

About

Generate CMake build and vscode setup from STM32CubeMX project file

License:MIT License


Languages

Language:Python 52.1%Language:CMake 47.9%