Skip to main content
PBoym.1
Associate
October 19, 2022
Question

Why the RTC reset when MCU reset ? (with VBAT still up and RTC_init cleaned)

  • October 19, 2022
  • 3 replies
  • 3870 views

CubeIDE : 1.7.0

CubeMX : 6.3

BSP : 1.12.1

chip : STM32WB55

I'm using the internal RTC of the STM32WB55. When the MCU is running the RTC works normally : the calendar can be set and the time is running correctly. When i shut the MCU power down (but still have the VBAT up), and turn it up again, the calendar of the RTC is reset.

I have cleaned the init generated by cubeMX and tried to use a light initialization (NVIC and clocks) when the backup register flag is set but nothing worked:

static void MX_RTC_Init(void)
{
 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.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
 hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
 if (HAL_RTC_Init(&hrtc) != HAL_OK)
 {
 Error_Handler();
 }
)

RTC config :

0693W00000UoMGpQAN.pngWhat should I have in my MX_RTC_Init() ?

Thanks,

This topic has been closed for replies.

3 replies

waclawek.jan
Super User
October 19, 2022

> tried to use a light initialization (NVIC and clocks) when the backup register flag is set

Show.

Make sure there is no backup domain reset before that, e.g. related to LSE setup.

Or simply ditch Cube altogether and write your own program.​

JW​

PBoym.1
PBoym.1Author
Associate
October 19, 2022

I just did the same thing that HAL_RTC_MSpInit() does :

__HAL_RCC_RTC_ENABLE();
 __HAL_RCC_RTCAPB_CLK_ENABLE();
/* RTC interrupt Init */
HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
HAL_NVIC_SetPriority(RTC_Alarm_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn);

MM..1
Super User
October 19, 2022