cancel
Showing results for 
Search instead for 
Did you mean: 

Why CUBEMX deletes User Code

UWall.1
Associate II

Hello

I am new to the CUBEIDE Universe and I guess this question has been asked a 1000 times but I can´t find an answer. I created a new project with cubeMX ( just a few GPIO outputs with LEDs) and build the C File. Then I wrote some defines and arrays. When I now edit the.ioc file because I want to change something, all my defines etc. are gone. Only my Code after while(1) stays. Is this a BUG oder did I something wrong. I wrote my #define right after the #include main.h.

1 ACCEPTED SOLUTION

Accepted Solutions
MM..1
Chief II
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
 
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
 
/* USER CODE END Includes */
 
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
 
/* USER CODE END PTD */
 
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */

for example you can place between BEGIN PD and END PD

View solution in original post

5 REPLIES 5
TDK
Guru

Only code between /* USER CODE BEGIN ... */ and /* USER CODE END ... */ is preserved.

> I wrote my #define right after the #include main.h.

This is not within a user code section.

If you feel a post has answered your question, please click "Accept as Solution".
MM..1
Chief II
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
 
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
 
/* USER CODE END Includes */
 
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
 
/* USER CODE END PTD */
 
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */

for example you can place between BEGIN PD and END PD

S.Ma
Principal

Overall, until version control tool can manage code blend within a source file, keep your code minimal here and call your functions placed in a source file YOU own and version control.

UWall.1
Associate II

Thank you. This helps me a lot

devinw
Associate II

I straight up just had it delete all my declarations BETWEEN the USER PV comment tags on a code regen refresh. So yeah, it can f**k you.

 

Back you stuff up, use version control, etc.. There are bugs in MX that can do that.