RTC LSE/LSI selection
The patches offered by @chuckbook aimed to solve two problems. The first was an issue with oscillator initialisation, now subject to a PR. The second, by my (incomplete) understanding of the code, aimed to select the LSE or LSI oscillator at runtime. The aim of this issue is to solicit comments on the relevance and design of this proposed feature, notably from @chuckbook.
The LSI oscillator is a low precision RC oscillator internal to the chip, while the LSE is an oscillator requiring external components to achieve substantially improved accuracy. The LSE is implemented with a 32.768KHz crystal on the Pyboard.
To initiate the discussion I'd like to raise the following questions.
- Does the LSI have merit other than in extremely cost constrained systems? Is it relevant to actual or proposed MicroPython target boards? Or does it have other relevance e.g. fault tolerance?
- If it is relevant, is there a reason for performing the selection at runtime, rather than making it a target specific compile time option?
- If done at runtime, when should selection occur? At initial power up? On soft boot or recovery from standby? Or must the choice be iterated or event driven and, if so, in response to what events?
- If hardware containing an LSE can fall back to the LSI at runtime, from the user perspective this is a fault condition. I would submit that this should raise an exception.
stm32/rtc: Make sure RTC is using LSE on N6 MCUs.
Summary
On STM32N6 MCUs, it seems that the low-level boot process always enables the RTC in LSI mode. That even happens if the application switches to LSE mode and then does a reset: after the reset the RTC is switched back to LSI mode (I couldn't find mention of this in the ST datasheets, but maybe I missed something).
That behaviour messes up the logic in our driver to configure the RTC. This PR works around this issue by forcing the RTC to use LSE if the board enables LSE.
Testing
Tested on OPENMV_N6. Prior to this fix the RTC was always in LSI mode. Now it's always in LSE mode, even after a hard reset.