2020-10-16 05:38 AM
Dear ST Hello,
what is the best way to use CubeMX without any deleting functions in CubeIDE?
For code added to the main file, it's clear to use /**User */ comment guidelines but, for functions, should i create another file or module for my functions?
Thank you in advance,
S.Tairk,
Solved! Go to Solution.
2020-10-16 08:32 AM
You should add the functions in the User Code section:
/* USER CODE BEGIN 0 */
(..)
/* USER CODE END 0 */
Ensure that following option is checked : "Keep User Code when re-generating". In this case, the user sections defined by STM32CubeMX are preserved.
I recommend you to have a look at the UM1718 to show how to add the user code in different sections:
Note that when upgrading to a new version of STM32CubeMX, make sure to always backup your projects before loading the new project (especially when the project includes user code).
I hope that this brings some help to you.
Imen
2020-10-16 06:57 AM
Hello @NSemrHomeInit ,
You should set the Backup previously generated files when re-generating option :
Hope this helps you.
Please select my post as Best is answered your question, so that thread is marked as solved.
Imen
2020-10-16 07:37 AM
Yes this help me thank you for taking into consideration my question.
One more question please, may be i was not clear in the first post.
if i creat a function in the main.c file, how i could tell cubeMX to no delete it?
Thank you Imen.
2020-10-16 08:32 AM
You should add the functions in the User Code section:
/* USER CODE BEGIN 0 */
(..)
/* USER CODE END 0 */
Ensure that following option is checked : "Keep User Code when re-generating". In this case, the user sections defined by STM32CubeMX are preserved.
I recommend you to have a look at the UM1718 to show how to add the user code in different sections:
Note that when upgrading to a new version of STM32CubeMX, make sure to always backup your projects before loading the new project (especially when the project includes user code).
I hope that this brings some help to you.
Imen
2020-10-16 08:46 AM
You might be able to dig the earlier version you lost via windows "previous version" right-click of the file.
I might suggest putting stuff in your own .C file and then #include "mystuff.c" into the auto-generated file. Make sure to back things up all the same, as these tools have a habit of blowing things up. Ideally, put your working build in its own directory, regenerate in a sandbox, and merge to your live one
2020-10-16 09:13 AM
Work like a professional, two sandboxes, Thank you :).
2021-04-23 06:58 AM
As someone who just lost all his code due to the popup to generate code by the CubeMX, I would like the STM team to realize that the way this is done is not a feature at the moment, but a bug. This could be a feature, however, it is not a feature in its current state. This code generation should be handled in a different way, maybe not by prompting with the default being 'Yes' because some people are in a hurry (a temporary solution). The 'User code' comments to "resolve" this issue is like using duct tape on a broken leg. STM can do better.
2021-04-23 01:56 PM
2021-04-26 04:00 AM
Hi @KMoha.1,
I hear your frustration and I tag the CubeMx team to take actions/explanations if necessary.
Hi @Nawres GHARBI , @Khouloud OTHMAN , @Khouloud ZEMMELI,
Can you please review the feedback from @KMoha.1 .
Imen
2024-05-28 07:04 PM
Hello NSemrHomeInit,
Maybe you can set the property of your own source file and folder to read only. Then use generate function of CubeMX dose not delete those files. Just try