cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 - RTC time, date and Backup register BKPxR aren't saved after Power off

freecoder
Associate II

Hi,

We're faced to an issue in the RTC module. RTC registers: time, date and backup register aren't saved after power off ( we measured the VBAT supply is about 3v given by the supercapa), we used a magic number to ensure that data aren't reinitialized at each software startup:

freecoder_0-1753035720255.png

 

 

/** Initialize RTC Only
  */
  hrtc.Instance = RTC;
  hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
  hrtc.Init.AsynchPrediv = CFG_RTC_ASYNCH_PRESCALER;
  hrtc.Init.SynchPrediv = CFG_RTC_SYNCH_PRESCALER;
  hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
  hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
  hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
  if (HAL_RTC_Init(&hrtc) != HAL_OK)
  {
    Error_Handler();
  }

  /* USER CODE BEGIN Check_RTC_BKUP */
   if(HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR0) == 0x55AA)
   {
      // Time and Date are OK
      return;
   }
  /* USER CODE END Check_RTC_BKUP */

  /** Initialize RTC and set the Time and Date
  */
  sTime.Hours = 18;
  sTime.Minutes = 4;
  sTime.Seconds = 0;
  sTime.SubSeconds = 0x0;
  sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
  sTime.StoreOperation = RTC_STOREOPERATION_RESET;
  if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK)
  {
    Error_Handler();
  }
  sDate.WeekDay = RTC_WEEKDAY_THURSDAY;
  sDate.Month = RTC_MONTH_JUNE;
  sDate.Date = 20;
  sDate.Year = 24;

  if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN RTC_Init 2 */

  HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR0, 0x55AA);

 

 

Can you please give us some suggestions.

Thank you by advance,

Best regards,

 

1 ACCEPTED SOLUTION

Accepted Solutions
Sarra.S
ST Employee

Hello @freecoder

This is probably a hardware issue...

If VBAT drops below 1.55V, the backup domain won't function correctly, so the RTC register content will be lost;  are you sure the Vbat level is stable? can you share how VDDA/VREF+ is exactly connected?

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

2 REPLIES 2
Sarra.S
ST Employee

Hello @freecoder

This is probably a hardware issue...

If VBAT drops below 1.55V, the backup domain won't function correctly, so the RTC register content will be lost;  are you sure the Vbat level is stable? can you share how VDDA/VREF+ is exactly connected?

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.

Hi @Sarra.S ,

Thank you for your response.

Best regards,