AnsweredAssumed Answered

Trouble setting RTC from LSI to LSE on STM32F4

Question asked by Gordon Williams on Sep 8, 2016
Latest reply on Sep 9, 2016 by Gordon Williams
Hi,

I have a problem where I'm trying to detect the presence of the low speed external oscillator, and to use it if it is installed. On bootup, it does the following:


   * Turn LSI on (it always defaults to off)
   * If RTC is set up already then great. Job done.
   * If not, set up the RTC with the LSI, but turn the LSE on
   * Around 1 sec later, in SysTick, check if the LSE is working
   * If it isn't, turn it off
   * If it is, reset backup domain, switch over to LSE and disable LSI

When I do this on STM32F1 it works great. On the STM32F4 it works fine for just the LSI, but when the LSE is installed it's left in a state where the registers say:

* LSI is off
* LSE in on, and working
* LSE is set as the RTC clock source
* RTC is enabled

However the RTC itself is no longer working.

Does anyone have any ideas what the problem could be? When I reset the backup domain (which I have to in order to switch the RTC over) could I have missed out some configuration?

The odd thing is that if I reset the board after this, everything comes up fine - so it's as if I got the RTC into some strange state.

RTC Initialisation code:

https://github.com/espruino/Espruino/blob/6ec6946bdbb7e35d19037615d421eda5d19a44f4/targets/stm32/jshardware.c#L1111

Code that runs after ~1 sec:

https://github.com/espruino/Espruino/blob/6ec6946bdbb7e35d19037615d421eda5d19a44f4/targets/stm32/jshardware.c#L736

And yes, one answer would be just to pause the whole MCU while I waited for the LSE - but I need a fast startup time and to be able to use the RTC during that time (so I have to run it off the LSI until the LSE has started).

Outcomes