RTC can get corrupted and always requires a backup domain reset.
I'm using STM32L433 and what happens on rare occasions is that the RTC somehow gets corrupted and runs at 60% of its normal speed. Software resets do not fix the problem. I finally figured this out, it requires a backup domain reset. This is the code I use to reset it:
SET_BIT(RCC->APB1ENR1, RCC_APB1ENR1_PWREN);
SET_BIT(RCC->APB1ENR1, RCC_APB1ENR1_RTCAPBEN);
for (uint32_t x = 0; x < 0x000fffff; x++) __NOP();
SET_BIT(PWR->CR1, PWR_CR1_DBP);
for (uint32_t x = 0; x < 0x000fffff; x++) __NOP();
SET_BIT(RCC->BDCR, RCC_BDCR_BDRST);
for (uint32_t x = 0; x < 0x000fffff; x++) __NOP();
CLEAR_BIT(RCC->BDCR, RCC_BDCR_BDRST);
for (uint32_t x = 0; x < 0x000fffff; x++) __NOP();I will be running this code from now on at startup to keep this from happening (well this is the fix if it were to happen again). Secondly I was able to reproduce the issue by ever so slowly turning up the voltage and near the 2.15V mark when the MCU starts running properly, then the issue often appears and each time the RTC gets into this mode where it runs at 60% speed. I checked the BOR level and it was set to 0. So my second fix, which would hopefully prevent this from occurring is to set it to BOR level 3 (2.5V threshold) in software.
Is this expected behavior and would you say I'm handling this correctly? It seems to be a rather odd issue to me.
