2022-10-19 07:39 AM
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 :
What should I have in my MX_RTC_Init() ?
Thanks,
2022-10-19 08:03 AM
> 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
2022-10-19 08:07 AM
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);
2022-10-19 11:17 AM