Description
Description
As discussed here How to Achieve Long Periods of Deep Sleep on STM32 #7156 and here deepsleep - LPTIM1 Vs RTC on STM32? it seems appropriate to use the RTC when enabling MBED_TICKLESS
on STM32L4.
In our application we also want to use the RTC for recording the time at which a sample is taken. To achieve this our communication protocol includes a method of sending the Unix time to the device.
In an attempt to alleviate the obvious short comings of sending the Unix time via a non-deterministic transport we've also implemented a RTC synchronisation command. In other words, our protocol includes a command to adjust the time by +/-127 s although it is done in a series of 0.5 s steps.
To implement the 0.5 s time adjustment we've used the 'RTC Synchronisation' feature. With the error checking removed and various simplifications made, our code looks a bit like:
void rtc_synch() {
uint32_t ShiftSecond = advance ? LL_RTC_SHIFT_SECOND_ADVANCE : LL_RTC_SHIFT_SECOND_DELAY;
uint32_t prediv_s = LL_RTC_GetSynchPrescaler( rtc );
uint32_t Fraction = (prediv_s + 1) / 2; // i.e. 0.5 second
LL_RTC_DisableWriteProtection( rtc );
LL_RTC_TIME_Synchronize( rtc, ShiftSecond, Fraction );
}
The time adjustment was originally implemented without MBED_TICKLESS
defined and it works. It still works when MBED_TICKLESS
is defined.
The problem comes when I switch the 'lpticker' from the LPTIM to the RTC using "target.lpticker_lptim": 0
in mbed_app.json
. In this mode something goes wrong and the application locks up when attempting to delay the RTC (I can advance the RTC).
I've done a bit of debugging and it appears to be stuck in SysTick_Handler
. My feeling is that sys tick is continually firing, it never gets cleared, and no normal code is being run. But, I don't understand how the RTC, sys tick, etc. hang together to really understand.
This is pretty complicated stuff but I'd be grateful if anyone has any thoughts.
Issue request type
[X] Question
[ ] Enhancement
[ ] Bug