You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
stm32/boards: Use LSI-matched RTC prescalers on Arduino boards.
The Arduino Giga, Nicla Vision, Opta and Portenta H7 have an accurate
external 32768Hz oscillator (a SiT1532, +-20ppm) on OSC32_IN, but their
stock Arduino MCUboot bootloader is built with Mbed's lse_available
disabled and reinitialises the RTC onto the LSI at every hard reset when
it finds any other clock source selected -- and the backup-domain reset
that requires wipes the calendar. Verified on a Nicla Vision: with the
RTC switched to LSE bypass (which does start and keep +-0ppm time while
running), every machine.reset() and deep-sleep wake came back on the LSI
with the calendar reset to the bootloader's 2021-01-01 epoch.
So these boards run the RTC from the LSI, but the prescalers divided by
32768, making the RTC about 2.3% slow -- over half an hour per day, far
beyond what rtc.calibration() can correct. Set the LSI prescalers to
divide by the LSI's nominal 32000 instead, and drop the
MICROPY_HW_RCC_RTC_CLKSOURCE override so the runtime prescaler selection
sees whichever source the bootloader provides: boards updated to an
LSE-enabled bootloader get the SiT1532 with 32768Hz prescalers
automatically, everything else stays on the corrected LSI.
Tested on an Arduino Nicla Vision (stock bootloader): -684ppm over 240s
measurements against the HSE-derived SysTick (previously -22300ppm
measured over two hours against NTP), time preserved through
machine.deepsleep(20000) and machine.reset(), and the microsecond
subsecond fields still exact (32000/64 = 500).
Signed-off-by: Kwabena W. Agyeman <kwagyeman@live.com>
0 commit comments