2025-10-20 2:48 AM - last edited on 2025-10-20 2:51 AM by Andrew Neil
I'm working on RTC smooth digital calibration on an STM32U575 board using the HAL function HAL_RTCEx_SetSmoothCalib(). I'm using the LSE (32.768kHz) as the RTC clock source.
I want to adjust a known RTC drift (e.g., 500ms) over time using the RTC’s smooth calibration feature. I understand that I can configure the calibration window to 32s, 16s, or 8s using the SmoothCalibPeriod parameter, and that I can add or subtract pulses (each approx 30.5µs) to speed up or slow down the RTC.
With a 32s window, each call to HAL_RTCEx_SetSmoothCalib() can adjust ~15.6ms max (512 pulses × 30.5µs). So, it should take about 1024s (500 / 15.6 = 32 calls every 32s) to fully adjust 500ms. With a 16s window, I expected the correction rate to double, since the same pulse change should now apply over a shorter time, and thus the 500ms adjustment should take ~512s (500/15.6 = 32 calls every 16s).
When I call the function with RTC_SMOOTHCALIB_PERIOD_32SEC, it behaves as expected (takes ~1024s to fully correct 500ms). But when I change the calibration window to RTC_SMOOTHCALIB_PERIOD_16SEC, the total correction over the same number of calls is less than expected. it adjusts only ~250ms instead of 500ms. It seems like the effective correction rate remains the same as 32s, and/or the settings aren’t applied each time as expected.
Is there any internal hardware limitation in STM32U575 (or STM32 in general) that causes 16s/8s window settings to behave like 32s? If so, what's the correct way to apply faster or more frequent RTC calibration?
2025-10-20 5:55 PM - edited 2025-10-20 5:58 PM
The rate of correction is the same regardless of period, according to the reference manual. You cannot increase the correction rate by reducing the duration.
If you want to change it faster, consider using HAL_RTCEx_SetSynchroShift.
2025-10-21 8:27 PM
Thanks for the clarification @TDK , that the correction rate remains constant regardless of the calibration period.
As a follow-up, what’s the practical significance of the 8s and 16s calibration windows then?
If reducing the window length (from 32s → 16s → 8s) doesn’t actually make the RTC correct faster, in what scenarios would we want to use the shorter periods?
2025-10-22 6:39 AM - edited 2025-10-22 6:41 AM
If your window is 32 s, you will have to wait 32 s before the clock has been fully adjusted. If you select an 8s window, you will only have to wait 8 s. It's giving you options.
If your correction is small, any window can work.