# Stm32 RTC wakeup from standby

I am using an STM32L053C8 and I am trying to set up an RTC wakeup event, and while I am successful, I can only do it to a max time which is a couple of seconds. I need to put it in standby and wake up days later. At the moment I am using the low speed internal 40KHz as the RTC clock, eventually i will get a 32.768 crystal.

According to Carmine Noviello-Mastering STM32 i should be able to set the wakeup delay for a pretty long time. And while I do know it says using an external clock, using the internal one of a few Khz should still be able to provide a fairly decent delay for testing purposes. I just cannot figure it out. When I chose the 1Hz setting for the wake up clock, that only means it will use the RTC clock (40Khz)/(Asynch_prediv +1 x Synch_prediv+1) = new wake up clock frequency.It calls it 1Hz because it assumes you have set up the calendar to have a 1Hz frequency. Its too bad I can use the calendar as a wake up event.

• Which particular STM32 are you using? – Jan Dorniak Aug 19 '18 at 3:03
• opps forgot to mention it STM32L053C8 – Edwin Fairchild Aug 19 '18 at 3:38
• Almost the one I worked with - only difference is I had LQFP64 instead of LQFP48. Answer in progress. – Jan Dorniak Aug 19 '18 at 3:39
• And maybe edit your question. – Jan Dorniak Aug 19 '18 at 3:39
• As a side note: once you start making your own board consider adding a test point on PC13 - it has RTC calibration output – Jan Dorniak Aug 20 '18 at 10:44

The assumption about CK_SPRE being 1 Hz is caused by the fact that this is essential for correct timekeeping.

What you are missing are the wakeup counters (below wakeup clock in your screen). That is - the RTC counts the clock pulses (say coming from CK_SPRE) and only wakes you up when the count reaches the value set in wakeup counter. Assuming CK_SPRE is at 1 Hz this gives you a maximum wakeup period of 36 hours (as stated in the reference manual).

Now, where did those 48 days come from? Either the author somehow mistakenly multiplied the period by 2 ** 5 or he assumed that CK_SPRE is 1/32 Hz (which wrecks timekeeping).

There are two workarounds to this:

• software counter
• alarms

Software counters - simply use a variable in your code and do something like this in your main:

int i = 0;
while(true) {
sleep(WFE); // forgot exact code
++i;
if(i % 10 != 0)
continue;