Showing results for 
Search instead for 
Did you mean: 

Is it possible to add custom USER CODE sections?

Associate III

We are using the ST MCSDK, it is very helpful. In MCSDK/MCLib/Any/Src there is a function called STM_FaultProcessing. It is auto generated by Cube. We have one line we want to add to it that turns an LED on alerting the user to a problem.

This works, but if we then auto generate code, it gets removed.

We attempted to put our own user code brackets around the line to protect it:


But the auto generation writes over it anyway.

Is there any way to insert custom USER CODE sections into areas that do not natively have these sections? If not, can anyone suggest (besides generate->diff->remodify) a good way to keep additions to the ST generated code?


USER CODE sections can't be user created. Workaround maybe needed with side effects to take care.

For example, find the master source directory which files will be copied at generation, and edit it.

Next library upgrade, pouf! In the meantime, you can edit the code without any user code as long as you track what you changes.

Otherwise, copy your project to safe haven, and compare the new generated code vs your reference for update. Windiff mastering required.

Yes, Windiff will likely be the path. Thanks...



Today is 2023 and next month is 2024 working on STM32U5A5 and note such as complex library, feature and stuff with some bug/issue in the code generator. Do you think it is about time to upgrade the feature to allow USER CODE sections that control or prevent overriding the modified code? or at least add a comment of the previous code before overridden code (below it) via an easy search pattern, ie //!!!PREVCODE: old code details (with enable/disable option)

Thank for consideration