cancel
Showing results for 
Search instead for 
Did you mean: 

replaced old code when update GPIO inform

KUSAGI
Associate II

Hi everyone,

I have problem when i try to change GPIO inform then i push "generate code". But it replace my old code.

can you let me know how to only update inform for code not replace old code?

thanks you and sory about my poor english!

1 ACCEPTED SOLUTION

Accepted Solutions
Peter BENSCH
ST Employee

I assume you were creating your code using STM32CubeMX or STM32CubeIDE, right?

Both are based on the same principles and by default should create the project with Keep User Code when re-generating enabled. Please double check your settings by opening the IOC file and navigating to Project Manager > Code Generator --> Keep User Code ...

If you check the generated code, you will find many comment lines like

/* USER CODE BEGIN <block_name> */

...

/* USER CODE END <block_name> */

while <block_name> can be Header, Includes, PTD, PD, etc.

If the above setting is enabled, changing and / or re-creating the project will not change your user code if it is between these comments.

Does it help?

Good luck!

/Peter

In order 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.

View solution in original post

3 REPLIES 3
Peter BENSCH
ST Employee

I assume you were creating your code using STM32CubeMX or STM32CubeIDE, right?

Both are based on the same principles and by default should create the project with Keep User Code when re-generating enabled. Please double check your settings by opening the IOC file and navigating to Project Manager > Code Generator --> Keep User Code ...

If you check the generated code, you will find many comment lines like

/* USER CODE BEGIN <block_name> */

...

/* USER CODE END <block_name> */

while <block_name> can be Header, Includes, PTD, PD, etc.

If the above setting is enabled, changing and / or re-creating the project will not change your user code if it is between these comments.

Does it help?

Good luck!

/Peter

In order 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.
KUSAGI
Associate II

Thanks for your reply,

in file IOD i set Project Manager > Code Generator --> Keep User Code ... already.

but old my code is not exist.

for example put 2 code lines as below:

 while (1)

 {

  /* USER CODE END WHILE */

HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_13);

HAL_Delay(200);

  /* USER CODE BEGIN 3 */

 }

//

when i push generate code again my code not exist only have the code line

/* USER CODE BEGIN <block_name> */

/* USER CODE END <block_name> */

0693W000003C01tQAC.png

Hello @Peter BENSCH​ ,

After researching i found the reason. Just put the code between 2 lines:

/* USER CODE BEGIN 3 */

/* USER CODE END 3 */

Thanks you!