NUCLEO_L073RZ no chance to Deep Sleep

Hello, I have no chance to get my device (NUCLEO_L073RZ) to deep sleep.

OS version: mbed-os-5.15
IDE: Mbed Studio Desktop
toolchain: GCC_ARM

mbed_app.json:
{

    "config": {

        "thread_stack_size": {"value": 1024},
        "main_stack_size": {"value": 1024}
    },
    "target_overrides": {
        "*": {

            "platform.stdio-convert-newlines": true,
            "platform.stdio-baud-rate": 115200,
            "platform.cpu-stats-enabled": true,
            "platform.memory-tracing-enabled": true,
            "target.stdio_uart_tx": "PA_9",
            "target.stdio_uart_rx": "PA_10",
            "target.lpticker_lptim": 0,
            "events.use-lowpower-timer-ticker": true
        }
    },
    "macros": []
}

main.cpp

#include "mbed.h"
#include "mbed_stats.h"

int main(void){

   while (1) { 
       wait_ms(4000);

       mbed_stats_cpu_t stats;
       mbed_stats_cpu_get(&stats);
       printf("Uptime: %llu ", stats.uptime / 1000);
       printf("Sleep time: %llu ", stats.sleep_time / 1000);
       printf("Deep Sleep: %llu\n", stats.deep_sleep_time / 1000);
   }
}

Console ouput:

Uptime: 15909 Sleep time: 15868 Deep Sleep: 0
Uptime: 19925 Sleep time: 19872 Deep Sleep: 0
Uptime: 23941 Sleep time: 23876 Deep Sleep: 0

As you see the Device never entered into deep sleep mode, I have no clue how I can enable the deep sleep when it enters into wait_ms().

I read a very well explained instructions (HERE) but doesn’t work on my device NUCLEO_L073RZ.

Could somebody help me to set my device into a deep sleep?

Thanks

Hi John,

Great write up but out of date, nice if he would revise it.

Check you compile output warnings, I think you will see …

Warning: ‘wait_ms’ is deprecated: ‘wait_ms’ is deprecated in favor of explicit sleep functions. To sleep, ‘wait_ms’ should be replaced by ‘ThisThread::sleep_for’ (C++) or ‘thread_sleep_for’ (C). If you wish to wait (without sleeping), call ‘wait_us’. ‘wait_us’ is safe to call from ISR context. [since mbed-os-5.14] [-Wdeprecated-declarations]

There’s some more information that may help you here regarding GPIO settings to reduce deepsleep mode current consumption, this is important on these ST’s…

Paul

Hi Paul, first of all thanks for your reply.

thread_sleep_for(4000); Does not modify the issue, also with that the device never enter in deep sleep.

It is for me like a mistery box, because I have not idea how to debug the power management. I mean the way to capture what is blocking to enter in deep sleep.

any idea will be welcome.

By the way I did a test with the new Mbed OS6 with exactly the same result.

Thank you.

Hello,
I discovered that enabling the “MBED_SLEEP_TRACING_ENABLED” I can trace the lock/unlock

mbed_app.json:
{
“config”: {
“thread_stack_size”: {“value”: 1024},
“main_stack_size”: {“value”: 1024}
},
“target_overrides”: {
“*”: {
“platform.stdio-convert-newlines”: true,
“platform.stdio-baud-rate”: 115200,
“platform.cpu-stats-enabled”: true,
“platform.memory-tracing-enabled”: true,
“target.stdio_uart_tx”: “PA_9”,
“target.stdio_uart_rx”: “PA_10”,
“target.lpticker_lptim”: 0,
“events.use-lowpower-timer-ticker”: true,
“target.macros_remove”: [“MBED_TICKLESS”]
}
},
“macros”: [“MBED_SLEEP_TRACING_ENABLED”]
}

This is the ouput I got:

LOCK: mbed_rtx_idle.cpp, ln: 148, lock count: 1

Sleep locks held:
[id: mbed_rtx_idle., count: 1]
LOCK: lp_ticker.c, ln: 462, lock count: 2
UNLOCK: mbed_rtx_idle.cpp, ln: 150, lock count: 1
UNLOCK: lp_ticker.c, ln: 332, lock count: 0
LOCK: mbed_rtx_idle.cpp, ln: 148, lock count: 1


Sleep locks held:
[id: mbed_rtx_idle., count: 1]
UNLOCK: mbed_rtx_idle.cpp, ln: 150, lock count: 0
LOCK: mbed_rtx_idle.cpp, ln: 148, lock count: 1

Sleep locks held:
[id: mbed_rtx_idle., count: 1]
UNLOCK: mbed_rtx_idle.cpp, ln: 150, lock count: 0
LOCK: mbed_rtx_idle.cpp, ln: 148, lock count: 1

It seems that here is the guilty:

mbed_rtx_idle.cpp

Why it is locking the deepsleep?
how to prevent the deepsleep locking?

Well… after 1 day I undestand that the “Debug” Bulild profile disable the deep sleep, after switched to “Release” the device go to deep sleep.
Why the hell that is not documented as a warning in the Power management section? My God!

image

Cheers

I have been saying this for some time now.
However the recent OS6 documentation is much better now, I have only just noticed this.

https://os.mbed.com/docs/mbed-os/v6.0/program-setup/build-profiles-and-rules.html

I would suggest to start at the beginning of the OS6 documentation and reading the whole lot, me included :slightly_smiling_face:

Hi Paul,

Actually the device is getting around 1200μA with the same main() and configuration.

Do you have an idea how to reduce it? or the way to debug what is taking this current?

Thank you

As always unexpected is the most expected, I was a hardware issue.
Now its taking around 30μA pretty decent :slight_smile:

Cheers

Thank you for your feedback. We’ve updated both the Mbed OS power management page and the Mbed Studio build profiles section to point to information about sleep in debug modes.