Posts for: #Cmake

CMake on STM32 | Episode 5: additional clean files

CMake on STM32 | Episode 5: additional clean files

In this episode, we will see that some files generated during the build are not deleted during the clean process and we will solve this issue with CMake, of course.

What is cleaned?

Once the build is done, we can have a look at the content of the output directory:

λ pwd
D:\cmake_stm32\cmake-build-debug

λ cmake --build .
...
[ 76%] Building C object CMakeFiles/nucleo-f413zh.out.dir/BSP/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.c.obj
[ 80%] Building C object CMakeFiles/nucleo-f413zh.out.dir/BSP/Src/main.c.obj
[ 84%] Building C object CMakeFiles/nucleo-f413zh.out.dir/BSP/Src/stm32f4xx_hal_msp.c.obj
[ 88%] Building C object CMakeFiles/nucleo-f413zh.out.dir/BSP/Src/stm32f4xx_it.c.obj
[ 92%] Building C object CMakeFiles/nucleo-f413zh.out.dir/BSP/Src/system_stm32f4xx.c.obj
[ 96%] Building ASM object CMakeFiles/nucleo-f413zh.out.dir/BSP/startup_stm32f413xx.s.obj
[100%] Linking C executable nucleo-f413zh.out
   text    data     bss     dec     hex filename
   7564      20    2668   10252    280c nucleo-f413zh.out
mingw32-make[2]: Leaving directory 'D:/cmake_stm32/cmake-build-debug'
[100%] Built target nucleo-f413zh.out
mingw32-make[1]: Leaving directory 'D:/cmake_stm32/cmake-build-debug'

λ ls -l
total 632
-rw-r--r-- 1 z19100018 1049089   1427 avr.  29 12:17 cmake_install.cmake
-rw-r--r-- 1 z19100018 1049089  53118 mai    1 12:26 CMakeCache.txt
drwxr-xr-x 1 z19100018 1049089      0 mai    2 15:13 CMakeFiles/
-rw-r--r-- 1 z19100018 1049089  42893 mai    1 12:42 Makefile
-rw-r--r-- 1 z19100018 1049089   7584 mai    2 15:13 nucleo-f413zh.bin
-rw-r--r-- 1 z19100018 1049089  11154 mai    1 12:42 nucleo-f413zh.cbp
-rw-r--r-- 1 z19100018 1049089  21433 mai    2 15:13 nucleo-f413zh.hex
-rw-r--r-- 1 z19100018 1049089 203655 mai    2 15:13 nucleo-f413zh.map
-rw-r--r-- 1 z19100018 1049089 289884 mai    2 15:13 nucleo-f413zh.out

λ ls -l CMakeFiles\nucleo-f413zh.out.dir\BSP\Src\
total 52
-rw-r--r-- 1 z19100018 1049089 18416 mai    2 15:13 main.c.obj
-rw-r--r-- 1 z19100018 1049089 14956 mai    2 15:13 stm32f4xx_hal_msp.c.obj
-rw-r--r-- 1 z19100018 1049089  6224 mai    2 15:13 stm32f4xx_it.c.obj
-rw-r--r-- 1 z19100018 1049089  7916 mai    2 15:13 system_stm32f4xx.c.obj

Yes, it was 15:13 when I built the project. Let’s clean it and see what files are still here and what files have been deleted.

CMake on STM32 | Episode 4: get ready for C++

CMake on STM32 | Episode 4: get ready for C++

I have been using C++ for the last 4 years… there is no way I get back to C! This episode is not about explaining why I think C++ is better than C. It is simply about running C++ on STM32 with CMake. By the way: we will make LEDs blink!

Adding user code in code generated by STM32CubeMX

If we change the MCU configuration with STM32CubeMX and generate the code again, the previous files are overwritten. How can we create our own program if everything is erased each time the code is generated?

CMake on STM32 | Episode 3: handle warnings in 3rd party files

CMake on STM32 | Episode 3: handle warnings in 3rd party files

Something funny happens sometimes with 3rd party files: they generate warnings when compiled with your project settings. If you have quality indicators about the build health (automatically updated by Jenkins maybe), this is quite annoying. If you compile with an option such as -Werror to treat warnings as errors, this is a blocking issue.

In this article, we will add compiler options that will raise warnings in ST’s generated files and we will ask CMake to suppress these warnings but only for these files.

CMake on STM32 | Episode 2: build with CLion

CMake on STM32 | Episode 2: build with CLion

In this article, you will learn how to build a CMake project for STM32 and download the software to the MCU with CLion, JetBrains’ IDE for C & C++.

In episode 1, we got a BSP along with the CMakeLists.txt:

Alt Text

Finally, we built the software from the command line.

To be honest, in my everyday life, I don’t use the command line. I use instead CLion because it is much more comfortable… Let’s try it!

CMake on STM32 | Episode 1: the beginning

CMake on STM32 | Episode 1: the beginning

This article is the first of a series dealing with CMake and STM32 microcontrollers. In fact, it is more about CMake on MCUs but I had to pick one for the examples.

Why CMake? Why STM32?

CMake is becoming the de-facto standard tool to build C and C++ projects. It is becoming so popular that it will probably be the build tool for Qt6:

For Qt 6, we aim to use CMake as a standard 3rd party build system to build Qt itself. CMake is by far the most widely used build system in the C++ world, and better integration with it is sorely needed.