2022-03-27 07:29 AM
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.
2022-03-27 08:14 AM
Tell us about your hardware. Is this a "known good" board such as Nucleo or Disco, or your own? How is VBAT and NRST connected? Do you have properly connected all GND and VDD pins, including the analog ones? (If it's your own board, this question includes also "did you check for bad solder joints?")
JW
2022-03-27 08:39 AM
RTC shouldn't be flaky. In addition to the questions above, I would verify the LSE clock is stable. Consider using LSI (which should stable) as the clock source to see if you can replicate.
2022-03-28 08:09 AM
This board is a custom one that someone else made. The VBAT is connected to same as VDD, which is 3.3V nominal and the NRST pin is actually left floating. NJTRST goes through a 10k resistor and is then also floating. As far as I can tell all power pins are connected properly.
The solder joints are unlikely the problem because I tried it on 2 boards and this has been known on many other boards too. It happens rarely but once it happens it doesn't recover.
When reproducing (this is before enabling 2.5V BOR level 3), at about 2.10V the MCU starts to boot but doesn't have enough power yet so quickly resets over and over, many times per second. As I increase the voltage, it gets a little bit further in the boot process but also keeps resetting and a little more voltage it fully boots up and then I would often see the RTC having been corrupted.
I'm not using LSI but LSE with a 32 MHz crystal. I'm not even sure why there is an external crystal on this board, and actually the RTC does not have an external crystal, which probably would have benefitted from one for accuracy. The MCU is running at 80 MHz. This application does not need to conserve power.
2022-03-28 01:08 PM
Ah, I though you are using battery backup for RTC and it unexpectedly changes pace.
Rapid resets at marginally low VDD invite troubles. Both the explicit backup domain reset and using BOR sounds like a correct solution.
JW