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.
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:
- Create a STM32CubeMX project, configure pins, peripherals and MiddleWare, then edit project settings as follows: (choose SW4STM32 instead of TrueStudio in the picture below)
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.
- Download the project from the Github repo below, extract files to a folder, say “C:CubeMX2Makefile”. Install Python 2.7 Win32 from www.python.org
c:CubeMX2Makefile>dir /b .gitattributes .gitignore CubeMX2Makefile.py CubeMX2Makefile.tpl readme.md
- From command prompt, execute CubeMX2Makefile.py, e.g,
c:CubeMX2Makefile>CubeMX2Makefile.py R:\411ProjTestF4 File created: R:\411ProjTestF4Makefile
- Cd into “Toolchain Folder Locaiton”, make project, i.e.,
R:\411ProjTestF4\>make ... arm-none-eabi-size build/TestF4.elf text data bss dec hex filename 5876 12 1056 6944 1b20 build/TestF4.elf arm-none-eabi-objcopy -O ihex build/TestF4.elf build/TestF4.hex
Refer to blog and below links for ARM GCC and make utility installation. It will be much easier to import the Makefile project into Eclipse CDT for code editing and debugging.
My packaged GNU Make for Win32: http://www.ba0sh1.com/wp-content/uploads/2013/05/make.zip