STM32CubeMX for make and gcc

Using the STM32CubeMX eclipse plugin with gcc and make on linux

Windows no longer required

Project motivation

The manufacturer of my favourite microcontrollers (ST micro) updated their code generation tool STM32CubeMX several times since I made my first template. Their support for Linux and eclipse is now matured, even the ST-Link Updater is available now for Linux. I haven't tried this yet.

The tool generates code and projects for some commercial IDE and the new open STM32 IDE. This appears to work nicely on windows, linux support is offered for volunteers, which is great news for all friends of STM microcontrollers and Linux.

I still prefer to use my own Makefiles. So here's my way based on my Makefile framework:

  • Install your favourite Makefile based ARM bare metal toolchain
  • Get and install openocd
  • Install your favourite Eclipse CDT on your favourite linux
  • Get the plugin from STM (search for STSW-STM32095 or STM32CubeMX eclipse plugin)
  • Unzip the downloaded plugin to an empty directory, and add it to eclipse (Help->Install new software->local)
  • The STM32CubeMX should now be available as a perspective. Download the required Libraries (this example requires the latest STM32CubeF0 package)

  • Download my example: STM32F0 Cube MX Makefile example
  • Untar the example to an appropriate place
  • Import the folder "pwmtest1" as Existing Code as Makefile project
  • Import the folder "com" as Existing Code as Makefile project
  • Add "com" to the Project References of "pwmtest1"
  • You should now be able to open the Cube project file ("pwm1.ioc", in cubef0-ex/pwmtest1/cube/) using the CubeMX perspective. For code generation use the settings that I made for this project. Code generation should succeed using these settings, but is not necessary to compile the project. I've done this before. Note that I moved the "real main()" outside the generated "main.c", so there's minimal impact on the generated files. You'll just have to add the call to your main() just before the empty endless loop inside the generated main().

    Now use your favourite way to run the "pwmtest1" projects Makefile (located in "cubef0-ex/pwmtest1", use the default target).

    Check your openocd configuration files (the required one might not be provided with the standard openocd distribution, I've copied it from an other stm-nucleo board config file). Type "make flash" to program the example to a STM32F072 nucleo board.

    Run "screen /dev/ttyACM0 115200" to see the useless sprintf output of the example. You may have to update the ST-Link firmware to the lastest version to get this working.

    If you try to build your own project based on this, consider the following:

  • The STM HAL library is located in the folder "com/lib/STM32F0xx_HAL_Driver". The Makefile does not use the libraries copied or linked by CubeMX into the workspace. If you want to port this example to another STM32Fxxx chip, you'll have to put the appropriate libraries to "com/lib" and create a Makefile for this lib. Use the provided one as a starting point.
  • Same thing as above is true for the linker script. You'll have to provide your own or copy the created one to "com/ld".
  • For each target, create a Makefile in "pj", using the provided one as a starting point
  • BTW: Don't use the STM32 timers like I did here. Asynchronously reloading the compare value may confuse your attached hardware.


    Look here: The STM32 files for my other STM32 related pages.
    Table of contents ... und ein Zaehlpixel hab ich auch :-)