cancel
Showing results for 
Search instead for 
Did you mean: 

RTC in Standby on STM32WL

KS.6
Associate

Dear community

I'm working on a project using STM32WLE5J microcontroller. I would like to collect time from some external source and then keep it on the device. My problem is that the device loses its internal time after waking up from standby (e.g in the first cycle it counts from 0 to 30 seconds, then the device goes to sleep, it wakes up and again it begins to count from 0). I noticed that when reading from SSR register (by LL_RTC_TIME_GetSubSecond()) it gets cleared indeed.

Is there anything to set that I forget about? I wonder if the fact that device wakes up after Standby and makes all the initializations over and over again clears some data, and also RTC values.

Regards

2 REPLIES 2
Uwe Bonnes
Principal III

I suspect that your restart code at some point resets the RTC. Run in the debugger with a breakpoint at the very start and set a watchpoint on the register triggering RTC reset. Continue and look if that register is set. Or look in your code.

KS.6
Associate

Thank you for response. Indeed, the case was that the RTC initialization was resetting the RTC. If anyone struggles with this problem in the future.. the solution is to initialize RTC with MX_RTC_Init() only during the first program run. Later, after wakeup from standby you should instead use those two lines:

   hrtc.Instance = RTC;

   HAL_RTC_MspInit(&hrtc);

Then, the RTC timer isn't reset after wakeup from Standby and may continue measuring the time.