Electronics, Computers, at leisure time

Main menu

STM32CubeMX GCC Makefile project

Writing peripheral initialization code is probably the most tedious work in embedded development. It always successfully stops me from starting a new project. I believe engineers at STMicroelectronics share the same pain. Therefore they created STM32Cube firmware and STM32CubeMX graphical configuration tool, which turns numerous key strokes and page flips into just a few mouse clicks. STM32CubeMX is free software, but the initialization code it generates require compiler tools carrying hefty price tags, IARARM, Keil ARM-MDK, and Atollic TrueSTUDIO, to name the few. Fair enough these compilers do offer free editions with limited functionality. But I still prefer unrestricted, free tool that is easily scale-able for my current and future projects. Just like the GNU Make and ARM GCC toolchain I described in Opensource STM32 development.

UPDATE

Always get update from https://github.com/baoshi/CubeMX2Makefile The code is now based on SW4STM32 project output. Thanks various contributors to make this possible.

Deprived off electronics lab back in Singapore, a Chinese new year holiday here in Shanghai home is perfect for some software projects. I have little exposure with Python but after two days of Googling (through VPN) and copy/paste, a crude CubeMX2Makefile utility is ready, available at https://github.com/baoshi/CubeMX2Makefile (OOP aficionados please forgive my spaghetti styled code. It works is it?)

As the name suggests, the program converts STM32CubeMX project into a GNU Makefile. Here is a mini-HOWTO:

Make sure the Tool/IDE selection is TrueSTUDIO 4.3.1 (as of STM32CubeMX 4.6.0), and note down the “Toolchain Folder Location”. I found it necessary to empty the old “Toolchain Folder” before each code generation, otherwise the project file just keep growing regardless of settings (this could be a bug in STM32CubeMX). See update below.

Related

36 thoughts on “STM32CubeMX GCC Makefile project”

“Writing peripheral initialization code is probably the most tedious work in embedded development. It always successfully stops me from starting a new project”: Amen, brother! I’ve been switching between IDEs and microcontrollers, trying to find one that bootstraps a project well. I looked at CooCox and Rowley (not free, but only $150) and they are possibilities. Currently, I use Microchip PIC16s and PIC32s: the IDE is free and there are Code Configurators that get a project up and running. I’ve just started playing with Cypress PSoCs, and they seem to do a great job of configuring peripherals for you. My main concern about PSoC is there are very few DIP/SOIC/large pitch QFP packages (i.e. packages I can solder by hand).

Excellent! I literally just started banging my head against STM32CubeMX (after having done a few significant projects with StdPeriphLib) and I’d started writing something very similar to this. Now I don’t have to!

Awesome and thank for the all the work. To automate the process you can create a shortcut to the *.py file and store that with your projects. Then all you have to do is drag the project folder on top and it runs the script.
Matt

Thanks for this project – it’s surprising that ST doesn’t support the GCC toolchain in a more “direct” manner. I wonder if they’re doing so because of pressure from Keil, IARARM, and Attolic. In any case, this makes development that much more straight forward!

One note – it seems that the newest CubeMX has changed the default output path for the TrueSTUDIO directory structure. There is an added “Projects” folder. I just changed the path in your python script and it now works:

Many thanks for this helpful tool! To get the generated Makefiles running (Windows, GNU Tools ARM Embedded) I had to make some changes to your script file which can be found as a patch at http://codepad.org/FEC8WC2M

First of all, it seems to stumble over the mkdir -p .. ” command. At least I will get a folder called “-p”, how ever the folder build still gets generated.
But then I get this odd error:
Drivers/CMSIS/Device/ST/STM32F4xx/Source/Templates/system_stm32f4xx.c:287:1: fatal error: opening dependency file .dep/system_stm32f4xx.o.d: No such file or directory

Thanks. I need to add a contact page.
I can actually compile the code generated. So I guess the issue is something else. It could be possible that your make environment is not complete. Besides make.exe, you will need GNU shell utilities in the PATH. I have a package here: http://www.ba0sh1.com/wp-content/uploads/2013/05/make.zip
You may try this setup.

Great utility. I had to make some slight modifications to the generated Makefile to use it with the cmd.exe terminal on windows that comes with GNU make. The mkdir implementation doesn’t support command line options like -p. Also, there is no /dev/null mapping. Otherwise it worked flawlessly.

This works very well, and is a most welcome addition to my toolset. A couple of comments though: first, it seems to want the project saved as SW4 rather than TrueStudio (not a problem, but has it changed? and when?), and second that the linker command includes -specs=nano.specs and the build fails until I remove that switch.

Yes it has been changed to SW4STM32. This is in the history.txt file. -specs=nano.specs uses nanolib from GCC which reduces binary size. Maybe you can try update your ARM-GCC toolchain to have this recognized.

A little suggestion, having used this excellent tool a few times. It would suit Eclipse better if the c_defs were written as #defines in a .h file rather than as -D command line arguments, as the right sections would then get greyed out in the editor. I’d do it myself except I don’t speak Python!

This seems very nice!
Though im running into some problems, first it stops because it says it cant find any file named disc.map, and if i remove the part looking for that i get no rule for hex required by all.

Thanks for this great tool.
I just downloaded STM32CubeMx but it is now version 4.14.0. I am running it with SW4STM32 Outputs and it seems some changes happened as I had to modify the script to pick up the project Files and library directly from the Tool chain folder. However, even with these changes, it seems that the script no longer picks up the source files. C_SOURCES and ASM_SOURCES are empty. Could it be possible that the sources now need to be taken from .mxproject? I am willing to hack but as I haven’t worked with STM32CubeMx before, I would appreciate some pointers.

Me too, it seems that .cproject syntax generated by latest STM32CubeMX-4.18.0 has changed and the script cannot find necessary values – need an update. BTW latest STM32CubeMX has not any option for Truestudio version, only one choice