cancel
Showing results for 
Search instead for 
Did you mean: 

The best way to convert non-CubeMX project to STM32CubeMX ?

eBirdman
Senior
Posted on July 10, 2018 at 19:25

Hello, can somebody share the most efficient steps to convert non-MX project to a STM32CubeMX structured one? Most (or all?) of the Cube examples are not MX-generated hence they are not structured accordingly. So far my procedure has been : start from generating my board configuration main template, then manually bringing the code which I need from Cube examples. After the imported code works I test it in terms of ability to reconfigure in CubeMX and it breaks the compilation quite often . This requires painstakingly go through the code yet again making changes, sometimes even in the driver files.

Is there any documentation or a post on the best practice to convert a working code to STM32CubeMX generated project?

#stm32cubemx #code-migration
6 REPLIES 6
Posted on July 10, 2018 at 20:59

Everytime I buy new nucleo shield or discovery board I face the same problem: need to integrate the BSP drivers / examples manually:

https://community.st.com/0D50X00009XkYoaSAF

 

However the latest CubeMX version is able to pre-initialize MCU resources required by the particular ST board.

I tested this feature on several boards and mostly works fine (some older STM32L1 Discovery boards are wrongly pre-initialized and there are some resource conflicts). So you only needs to focus on the APP call flow (the drivers are pre-initialized by the CubeMX).

Once you select ST board you can accept the question about the board pre-initialization...

Posted on July 11, 2018 at 05:09

Thank you Bogdan for your input. Following your post link I see that after configuring a new project for your MCU, you manually added new BSP drivers *.c and *.h to the project files and added them to the build configuration, then you add functions to the main().  I did similar steps for simple examples and it works but it was slow process. I&39ll need many functions to be added to a custom STM32 board.  Did you try to follow the 

Joly.Jeanne

recommendation to use the &39import&39 feature to import all the code from another example into your CubeMX pre-configured project (assuming that CubeMX generated all initialization routines for IOs and drivers you have chosen) ? I get errors. 

Posted on July 11, 2018 at 05:13

Bogdan could you please give your opinion on this (related) :

https://community.st.com/0D50X00009XkWj4SAF

Posted on July 11, 2018 at 07:21

It's slow. True. Perfectly the ST guys should create every example using CubeMX as a resource enabler, then they should use particular API.

But image they need to do for every example now. I would not expect it.

They moved to resource re-initialization approach (as I described yesterday).

I have tried to migrate simple projects suing export/import function - it mostly worked in my cases. But frankly, I did it for a test, not real project.

As far as I remember I needed to adjust some part of the project (clocking at least). There were some errors/warnings. But again, it was an exercise, not real (big) project migration.

Not sure if the process described here:

https://community.st.com/0D50X00009bMM6QSAW

adds any value. You cannot avoid resource configuration which is crucial.

I guess I have not helped too much in your case. It's more about 'fate' sharing;)

Posted on July 11, 2018 at 11:27

Hi Vlad,

Take a look to my tutorial that explains the concept of build variable and linked ressources under Eclipse environment (SW4STM32 or Atollic TrueStudio)

In order to not repeat the process for each project and save time, I use the following method:

I have a template project including BSP librarie even DSP lib if needed for a STM32 board (ex F7/F4 Discovery).

As all project files are linked on my local repo CubeMX except my source codes. I can then make a copy of my template project and implement the new code specific to my application.

https://community.st.com/0D50X00009bMM6aSAG

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Posted on July 13, 2018 at 02:36

In fact sharing the experience does add value. As a result of the accumulated information I am experimenting now with yet another method of merging the CubeMX configuration with other drivers and code examples into my custom board. I am trying to rid of all those 'START USER CODE' an 'END USER CODE' in my project files (keeping my files not changeable directly by CubeMX generation), yet still to use CubeMX reconfiguration when needed... if it works I will share in a new post...