2018-07-10 10:25 AM
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-migration2018-07-10 11:59 AM
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...
2018-07-10 10:09 PM
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.2018-07-10 10:13 PM
Bogdan could you please give your opinion on this (related) :
2018-07-11 12:21 AM
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;)
2018-07-11 04:27 AM
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.
2018-07-12 07:36 PM
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...