Long time sleeping of the microcontroller

Hello RIOT-enthusiasts, I'm searching for a good way to bring a RIOT-system to lowest power modes for several minutes. As far as I understand the function of the xtimer is designed to provide the timebase for thread/task switching and providing short low-power-delays. It is therefore not designed to support slow clock timers inside low-power microcontrollers. Is this true? Can you give tell me your opinion about using the slow-clock timer simply inside the application? The idea is to bring the peripherals to lowest power mode, then stop all threads except the main thread, mask interrupts und stop then the microcontroller under the control of the application. The wakeup could happen by using an interrupt from the slow-clock-timer inside the CPU.

Is this a way which could work?

Best regards, Bernhard

Hi Bernard,

I have created two examples that leverages the low-power modes of the EFM32 MCU that I am working on.

Although this example is still very hardware dependent (because it is device-specific that the RTT can wakeup the MCU from sleep), I can get it down to 10µA in sleep (without other optimizations) with a wakeup time of ~2µs.

If you are interested, see https://github.com/basilfx/EFM2Riot/blob/master/dist/examples/sleep_wakeup/main.c, https://github.com/basilfx/EFM2Riot/blob/master/dist/examples/sleep_wakeup_measure/main.c and probably https://github.com/basilfx/EFM2Riot/blob/master/dist/cpu/efm32_common/lpm_arch.c too.

Kind regards, Bas

Hi Bernhard,

As far as I understand the function of the xtimer is designed to provide the timebase for thread/task switching and providing short low-power-delays. It is therefore not designed to support slow clock timers inside low-power microcontrollers.

That's partly true. There is a series of PRs [1 et al.] that aim to implement a slow/low power timer source for xtimer. I wanted to use them myself but unfortunately this work isn't finished yet.

Can you give tell me your opinion about using the slow-clock timer simply inside the application? The idea is to bring the peripherals to lowest power mode, then stop all threads except the main thread, mask interrupts und stop then the microcontroller under the control of the application. The wakeup could happen by using an interrupt from the slow-clock-timer inside the CPU.

I've used the realtime clock to wakeup the MCU after a sleep interval. I was using the famous samr21-xpro board and implemented the realtime timer (RTT) interface for it. With the peripherals configured correctly I could get my MCU down to several microamps too.

For the same board there is another long-standing PR [2] to implement low power states. I'm not sure about the current state of LPM in RIOT (didn't follow this for some time), but back then you needed to manipulate `lpm_prevent_sleeping` to put everything to sleep. But this will likely impact networking.

Cheers, Daniel

[1] xtimer: Add support for arbitrary frequency hardware timers (32768 Hz support) by jnohlgard · Pull Request #3990 · RIOT-OS/RIOT · GitHub [2] cpu/samd21: implement low power modes by LudwigKnuepfer · Pull Request #2309 · RIOT-OS/RIOT · GitHub