I've implemented a faster way to automatically import CubeMX project into an Eclipse tool-chain based on the GNU ARM Plugin, as described either on this blog and in my book.
I've implemented a bare-bone python script that simply "translates" a CubeMX project for the SW4STM32 (aka AC6) tool-chain in a project generated with the GNU ARM plugin. The script can be downloaded from my github account. Let's see how this works.
First of all, we have to generate a new Eclipse project using the GNU ARM Plugin. Go to File->New->C Project and select "Hello World ARM Cortex-M C/C++ project. You can choose the project name you want. Click on “Next“. Here we assume "test1" as Eclipse project name.
If you are using a Nucleo, this table extracted from my book shows the right values for all Nucleo boards.
In the next step leave all parameters unchanged except for the last one: Vendor CMSIS name. Change it from DEVICE to stm32f4xx if you have a STM32F4 based board, or stm32f1xx for F1 boards, and so on. Please, be sure to use this pattern, otherwise the script simply doesn't work.
Now, use the CubeMX tool to configure your MCU according your needs. When finished, click on the Project->Generate code menu. In the Project Settings dialog give the name you want to the project and select an output directory where store the project. Here we assume that the CubeMX project name is "mymcu". Choose SW4STM32 as Toolchain/IDE (this is really important, to not skip this step) and generate the code.
Finally, to use the tool I've made, you can easily type the following command at terminal prompt:
$ python cubemximporter.py <path-to-eclipse-workspace>/test1 <path-to-cubemx-out>/mymcu
When finished, open the project "test1" in Eclipse, click with the right mouse button on the project root and choose "Refresh" (this will force the scan of the source tree, since it has been changed while the Eclipse project was closed). Finished. 🙂
Don't forget to update the file mem.ld, changing the FLASH origin address from 0x00000000 to 0x08000000.
The script now supports also the import of Middleware libraries (FatFS, FreeRTOS, LwIP).
The script is designed to work both in Python 2.7 and 3.x. It requires the lxml library.
Windows users can download a pre-compiled lxml package directly from here:
Linux and MacOS X users can install lxml using pip:
$ pip install lxml
Please, let me know if it worked for you 😉
48 comments
Traceback (most recent call last): File "/home/user/CubeMXImporter/cubemximporter.py", line 541, in cubeImporter.importHAL() File "/home/user/CubeMXImporter/cubemximporter.py", line 339, in importHAL self.addAssemblerMacros((self.HAL_MCU_TYPE,)) File "/home/user/CubeMXImporter/cubemximporter.py", line 129, in addAssemblerMacros self.__addOptionValuesToProject(macros, "ilg.gnuarmeclipse.managedbuild.cross.option.assembler.defs", False) File "/home/user/CubeMXImporter/cubemximporter.py", line 101, in __addOptionValuesToProject options[0]] # List all available values to avoid reinsert again the same value IndexError: list index out of range
I am a bit familiar to Python, but not enough to spot my problem..