9 years, 5 months ago.

Enabling RTC wake-up on STM32L0

Hi,

I'm trying to enable RTC periodic auto wake-up functionality on stm32l053r8, but the wake-up timer doesn't start. The code is roughly as follows:

I've modified the rtc_api.c and added new functions:

void rtc_wakeup(uint32_t period_ms){
     RtcHandle.Instance = RTC;
     HAL_RTCEx_SetWakeUpTimer_IT(&RtcHandle, period_ms*2, RTC_WAKEUPCLOCK_RTCCLK_DIV16);
}

uint32_t rtc_get_wakeup_counter(){
    return HAL_RTCEx_GetWakeUpTimer(&RtcHandle);    
}

which should allow to set wake-up with 1ms resolution (for 32000Hz clock- > 32000/16 => 2000 tics/s). The wake up event should result in an interrupt (HAL_RTCEx_WakeUpTimerEventCallback)

Then in the main function I call:

set_time(0); //to set up the RTC
rtc_wakeup(1000); //to have wake-up event each second

However, when I check the timer with

rtc_get_wakeup_counter()

It returns the same counter value (2000) all the time. It seems like the RTC wake-up clock was not enabled, however the rtc_read() functions gives proper timestamp updated each second. I've analyzed the stm32l0xx_hal_rtc_ex.c source files, and the functions for configuring wake-up timer seems to be consistent with the datasheet.

Is there anything I could missed ?

1 Answer

9 years, 5 months ago.

While I wouldn't know what the issue is with your code, there is this code: http://developer.mbed.org/users/Sissors/code/WakeUp/, which should most likely work on your device too. It also uses the RTC, but then the regular RTC instead of the wakeup timer (since all Nucleo targets have the regular ones, but not all got the wakeup part).

Thanks! Your solution is based on the "Alarm" function of the RTC. It may work as well, however I was particularly interested in using the wakeup timer, which doesn't need to be restarted after each wakeup event. The RTC alarm needs to be reconfigured after each wakeup, what takes some time and consumes energy.

Maybe someone from ST could give a clue, why the wakeup timer is not running after configuration.

posted by Tomasz T 29 Oct 2014

I don't think that time required will generally be a significant part of your energy usage though. Although it depends on your setup, and of course the wakeup timer is the intended one. I might actually support it in the future for those STMs who do have it :).

I might check it later on my F401, but one issue is that ST decided on not standardizing the functions between the different microcontrollers with the same peripheral.

posted by Erik - 29 Oct 2014

If you're interested in the details, then section 27.3.6 of the RM0367 may be a good start. I agree that the RTC periodic wake-up function is the most appropriate for periodically waking up the MCU and that's why I would like to use it instead of the alarm :)

posted by Tomasz T 29 Oct 2014

When you say it like that it makes alot of sense :P

But then I would also need to check if I can use a define or something to automatically check if there is a wakeup timer. I originally made it on the F030, and that one lacks the wakeup timer. Luckily there is the subsecond register, otherwise the accuracy would be really poor :). But thats something for my todo list.

posted by Erik - 29 Oct 2014