cancel
Showing results for 
Search instead for 
Did you mean: 

Issue RTC STM32F767 / STMCube verion 4.27.0 / STM32Cube FW_F7 V1.12.0

Hans T
Associate III

USSUE: RTC      STM32F767 / STMCube verion 4.27.0 / STM32Cube FW_F7 V1.12.0

Time and date are reset when the ARM is started.

if I compare the code with the STM32F405 and the STM32F767, then I see a difference:

the row "if(HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR0) != 0x32F2){" is missing by the stm32f767

Have I not set the settings of cubeMX something  correctly or is this a mistake in cubeMX ?

-----------------------STM32F405----------------------------

/* RTC init function */

void MX_RTC_Init(void)

{

 RTC_TimeTypeDef sTime;

 RTC_DateTypeDef sDate;

   /**Initialize RTC Only

   */

 hrtc.Instance = RTC;

if(HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR0) != 0x32F2){

 hrtc.Init.HourFormat = RTC_HOURFORMAT_24;

 hrtc.Init.AsynchPrediv = 127;

 hrtc.Init.SynchPrediv = 255;

 hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;

 hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;

 hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;

 if (HAL_RTC_Init(&hrtc) != HAL_OK)

 {

   _Error_Handler(__FILE__, __LINE__);

 }

   /**Initialize RTC and set the Time and Date

   */

 sTime.Hours = 0;

 sTime.Minutes = 0;

 sTime.Seconds = 0;

 sTime.DayLightSaving = RTC_DAYLIGHTSAVING_SUB1H;

 sTime.StoreOperation = RTC_STOREOPERATION_RESET;

 if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK)

 {

   _Error_Handler(__FILE__, __LINE__);

 }

 sDate.WeekDay = RTC_WEEKDAY_MONDAY;

 sDate.Month = RTC_MONTH_JANUARY;

 sDate.Date = 1;

 sDate.Year = 0;

 if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN) != HAL_OK)

 {

   _Error_Handler(__FILE__, __LINE__);

 }

   HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR0,0x32F2);

 }

}

-----------------------STM32F767----------------------------

/* RTC init function */

void MX_RTC_Init(void)

{

 RTC_TimeTypeDef sTime;

 RTC_DateTypeDef sDate;

   /**Initialize RTC Only

   */

 hrtc.Instance = RTC;

 hrtc.Init.HourFormat = RTC_HOURFORMAT_24;

 hrtc.Init.AsynchPrediv = 127;

 hrtc.Init.SynchPrediv = 255;

 hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;

 hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;

 hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;

 if (HAL_RTC_Init(&hrtc) != HAL_OK)

 {

   _Error_Handler(__FILE__, __LINE__);

 }

   /**Initialize RTC and set the Time and Date

   */

 //HAL_GPIO_WritePin(GPIOF,GPIO_PIN_11,1);

 sTime.Hours = 0;

 sTime.Minutes = 0;

 sTime.Seconds = 0;

 sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;

 sTime.StoreOperation = RTC_STOREOPERATION_RESET;

 if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK)

 {

   _Error_Handler(__FILE__, __LINE__);

 }

 sDate.WeekDay = RTC_WEEKDAY_MONDAY;

 sDate.Month = RTC_MONTH_JANUARY;

 sDate.Date = 1;

 sDate.Year = 0;

 if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN) != HAL_OK)

 {

   _Error_Handler(__FILE__, __LINE__);

 }

}

2 REPLIES 2
Hans T
Associate III

Its also by cubeMX 5.0.0 fw_F7_V1.13.0

WBOUG
Senior

Hi @Hans T​ 

Thanks for your feedback,

In fact, the idea is to let the user insert his own code using habitual USER TAGs when he doesn't want to re-initialize RTC peripheral.

As you can see, in CubeMX 4.26 version, we have added USER TAGs in the MX_RTC_Init(void) where user can add his own code.

static void MX_RTC_Init(void)

{

 /* USER CODE BEGIN RTC_Init 0 */

 /* USER CODE END RTC_Init 0 */

 RTC_TimeTypeDef sTime;

 RTC_DateTypeDef sDate;

 /* USER CODE BEGIN RTC_Init 1 */

 /* USER CODE END RTC_Init 1 */

  /**Initialize RTC Only 

  */

 hrtc.Instance = RTC;

 hrtc.Init.HourFormat = RTC_HOURFORMAT_24;

 hrtc.Init.AsynchPrediv = 127;

 hrtc.Init.SynchPrediv = 255;

 hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;

 hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;

 hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;

 if (HAL_RTC_Init(&hrtc) != HAL_OK)

 {

  _Error_Handler(__FILE__, __LINE__);

 }

  /**Initialize RTC and set the Time and Date 

  */

 sTime.Hours = 0;

 sTime.Minutes = 0;

 sTime.Seconds = 0;

 sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;

 sTime.StoreOperation = RTC_STOREOPERATION_RESET;

 if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK)

 {

  _Error_Handler(__FILE__, __LINE__);

 }

 sDate.WeekDay = RTC_WEEKDAY_MONDAY;

 sDate.Month = RTC_MONTH_JANUARY;

 sDate.Date = 1;

 sDate.Year = 0;

 if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN) != HAL_OK)

 {

  _Error_Handler(__FILE__, __LINE__);

 }

}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**

Also, in addition to the backup register, there are others solutions to remain the RTC initialization. It depends on user application. For example, you may also use RTC & PWR flags to determine whether RTC is already initialized or a HW/SW reset has been occurred. So, we can not force user to use backup register solution to remain

RTC initialization.

Hoping it helps you, please do not hesitate to contact me for further details.

Best Regards,

Wael