cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L152RC RTC for freeRTOS Tickless mode

tim2
Associate II
Posted on October 01, 2014 at 10:43

 

 

The original post was too long to process during our migration. Please click on the attachment to read the original post.
4 REPLIES 4
chen
Associate II
Posted on October 01, 2014 at 11:39

Hi

I think your problem is a miss-understanding of what the register does :

''Thought this would be possible by calculating the difference between RTC reload value and the current value within RTC WUTR register. But the WUTR register always holds the reload value.''

The reference document (for a M4 but should be the same for M3 devices) :

''When the wakeup function is enabled, the down-counting remains

active in low power modes. In addition, when it reaches 0, the WUTF flag is set in

the RTC_ISR register, and the wakeup counter is automatically reloaded with its

reload value (RTC_WUTR register value).''

ie The WUTR register contains the count down value (I think in seconds but could be wrong) to the next time to toggle the wake IRQ - NOT the difference in time since going into sleep.

You may have to manage this manually : save the RTC time before entering Standby/Stop mode and read the RTC time on wake.

FYI, I just changed FreeRTOS to leave the SysTick running when I put the processor into Sleep. That way, I did not have to deal with correcting the OS SysTick count on wake and for my application, I do not think the extra 10% time spent just on servicing the SysTick IRQ is a great burden on the battery life.

tim2
Associate II
Posted on October 01, 2014 at 14:26

Hi,

Thank you very much for your quick response. You are right, RM0038 20.3.4 p.503 states:

''In addition, when it reaches 0, the WUTF flag is set in

the RTC_ISR register, and the wakeup counter is automatically reloaded with its

reload value (RTC_WUTR register value).''

In the application the system tick (generated by rtc wakeup interrupt) is running at 128Hz. Waking up every ~8ms will boost the current consumption. Therefor we have to use tickless mode (and adjust rtc wakeup interrupt) for saving as much energy as possible. Thus I will need to calculate the time spent in low power mode if an external interrupt occurs. I will post the corrected code as soon as I have tested the functionality.

Thank your very much! 

chen
Associate II
Posted on October 01, 2014 at 16:20

Hi

''In the application the system tick (generated by rtc wakeup interrupt) is running at 128Hz. Waking up every ~8ms''

Be careful with your terms!

I think you are referring to the RTC wake up period.

The SysTick is a core peripheral inside the ARM core itself. You set it's freq in FreeRTOS_Config.h and this sets the granularity of the context switching for FreeRTOS.

It is this timer that is stopped in Sleep, Stop and Standby modes. FreeRTOS uses this timer IRQ to maintain a system tick count, and it is this which must be adjusted.

tim2
Associate II
Posted on October 01, 2014 at 16:51

Hi, 

you are right. 

I have reconfigured FreeRTOS to use the RTC wakeup interrupt as RTOS heartbeat. Therefor the granularity set in FreeRTOS_Config.h is 128Hz. Thus I need to read out the elapsed time out of the rtc to adjust missed ticks when an external interrupt occurs during the time the device is in low power mode.