2025-05-26 2:06 AM
Hi, I’m using STM32CubeMX to configure peripherals and IAR Embedded Workbench for debugging. However, I’ve noticed that whenever I regenerate the code using CubeMX, the application code I previously wrote in IAR gets erased.
Is there any setting or configuration in CubeMX that prevents it from overwriting my application code when I regenerate code after making configuration changes?
Solved! Go to Solution.
2025-05-26 2:20 AM
Hello @curiocity
Keeping your application code inside USER CODE blocks or in separate files is necessary when regenerating code for IAR via CubeMX to prevent it from being overwritten.
KR,
Souhaib
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.
2025-05-26 2:20 AM
Hello @curiocity
Keeping your application code inside USER CODE blocks or in separate files is necessary when regenerating code for IAR via CubeMX to prevent it from being overwritten.
KR,
Souhaib
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.
2025-05-26 2:24 AM
Hi Souhaib, What do you mean by USER CODE blocks can you elaborate it
2025-05-26 5:56 AM - edited 2025-05-26 5:57 AM
Hello @curiocity
User code is the sections between USER CODE BEGIN and USER CODE END as shown below:
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* Configure the peripherals common clocks */
PeriphCommonClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
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.
2025-05-26 9:23 PM
@Souhaib MAZHOUD Thanks, That helped me