cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX - User Code sections are deleted after regeneration

JAlth
Associate

Hi,

I am generating the basic initialization of my projects code with CubeMX. As far as I understood it, the user can insert "USER CODE" sections to prevent the automatic code generator from overwriting these code blocks.

In my case, I want to prevent the RTC from being initialized, in case it has already been initialized before.

CubeMX generates this code (pseudo code)

RTC.Time.Hours = 0;
RTC.Time.Minutes = 0;
RTC.Time.Seconds = 0;
RTC_Set_Time(RTC);
 
RTC.Date.Year = 2018;
RTC.Date.Month = 10;
RTC.Date.Day = 1;
RTC_Set_Date(RTC);

I Implemented the following check:

/* USER CODE BEGIN RTC_CheckInit 0 */
  if(RTC not configured yet)
  {
  /* USER CODE END RTC_CheckInit 0 */
RTC.Time.Hours = 0;
RTC.Time.Minutes = 0;
RTC.Time.Seconds = 0;
RTC_Set_Time(RTC);
 
RTC.Date.Year = 2018;
RTC.Date.Month = 10;
RTC.Date.Day = 1;
RTC_Set_Date(RTC);
/* USER CODE BEGIN RTC_CheckInit 1 */
  }
  /* USER CODE END RTC_CheckInit 1 */

But when I regenerate the code via CubeMX, my user code sections are getting deleted.

Did I get something wrong about these user code sections?

Thanks and greetings!

0 REPLIES 0