AnsweredAssumed Answered

STM32L0 RTC wakeup time offset (in STOP mode)

Question asked by KoenVV on Nov 12, 2015
Latest reply on Nov 12, 2015 by KoenVV

I'm using an STM32L051R8 clocked off HSI 16Mhz and with a 32.768KHz external crystal (LSE) that drives the RTC and an LPTIMER.

I have set the RTC to generate periodic wakeup interrupts every X seconds, just before I enter STOP mode by __WFI()  I enable the LPTimer. When woken up I read out the timer count to know how long I was in STOP mode. 

I always see a delta of -10ms between the expected time (ie: 1 second) and the LPtimer count (990ms). 
I tried different sleep times (RTC wakeup periods) and the offset keeps quite constant; it doesnt scale over time. 

1 second <-> 990ms LPtimer
2 seconds <-> 1991ms LPtimer
10 seconds <-> 9990ms LPtimer
60 seconds <-> 59991ms LPtimer

LPtimer is having a 32x prescaler off LSE so it should count 1024 ticks/sec. I convert from ticks to ms by (ticks *1000) /1024 

I checked with an oscilloscope and confirmed the actual time is less than 1 second (measured 995ms on scope). 

So my question now is: why is the timing offset by -10ms ? I would expect it to be a marginal positive offset as there is always some wakeup from stop mode latency, interrupt latency and it has to execute the IRQ for the RTC and then it can read out the LPTimer count twice before the calculation is made.

Is this a known issue? Which one is correct LPtimer or RTC?