sleep() on the STM32L073

22 Mar 2018

I have a STM32L073RZT6 running with no external crystals. I started the project with MBED and exported to Kyle uVision. The project works great and now I need to be able to put it to sleep for 3 seconds, wake the L073 to power up an RF transceiver to check for incoming packets, and then go back to sleep. I cannot leave the transceiver in low-power RX mode and use its interrupt output pin for incoming packets (takes too much power) so I must be able to achieve low-power (<1mA) operation via a sleep mode that the L073 can wake from using an internal peripheral.

If I call sleep() by itself the L073 goes to sleep and current draw for the system is great at 300uA. Problem is I currently cannot find a way wake the L073 from this sleep.

With this code I can use the sleep() function and use an interrupt to wake up but the current draw is about 5mA during sleep:

bool expired; void int_acq1() { expired=1; }

expired=0; Ticker MyTimer; MyTimer.attach(&int_acq1, 3.0); while(expired==0) sleep();

I am now running the latest version of MBED (5.7.6 or 159 in mbed.h).

Questions: 1. Why does sleep() behave differently, depending on the preceding line of code? If there is no Ticker code preceding the call to sleep then sleep is a very deep (300uA) sleep that will require wake with interrupt via GPIO pin (since all timers/peripherals in the L073 are off). With the Ticker code preceding the call to sleep() then current consumption is too high (5mA). 2. Where can I find documentation that explicitly explains this characteristic of sleep()? I have searched MBED and countless other places and found much on the sleep() function - but nothing on this specific topic of preceding code. 3. Is what I'm wanting to do even possible with MBED?

Thx, Don

19 Apr 2018

Hi Don,

The issue is that your timer is preventing the entry of deep sleep mode as described here: https://os.mbed.com/docs/v5.7/reference/sleep-manager.html

If you consult the datasheet for this part you'll see that the Low-power Timer (LPTIM), real-time clock (RTC) or even the independent watchdog should enable you to enter deep sleep and still wake up every 3 seconds.

Are any of these resources available in your design?

In Mbed 5.8 we have added a sleep/deep sleep profiler: https://os.mbed.com/docs/v5.8/reference/power-management.html

-Ralph, team Mbed