5 years, 5 months ago.

power management time functions return 0

When I invoke the functions mbed_time_sleep(), mbed_time_deepsleep(), mbed_time_idle() and mbed_uptime(), I get 0 for each.

<<code>> printf("sleep time = %d\r\n", mbed_time_sleep()); printf("deep sleep time = %d\r\n", mbed_time_deepsleep()); printf("idle time = %d\r\n", mbed_time_idle()); printf("up time = %d\r\n", mbed_uptime()); <</code>>

DEVICE_LPTICKER is defined. I am using mbed-os-5.10.3. Is there anything else required to get the time values?

1 Answer

5 years, 5 months ago.

Hi Leon,

There might be some configuration parameters missed.

Please add below code snippet to mbed_app.json

mbed_app.json

"macros": [
        "MBED_ALL_STATS_ENABLED"
    ]

And using debug profile when compilation

command

mbed compile -t [TOOLCHAIN] -m [TARGET_MCU] --profile mbed-os/tools/profiles/debug.json

Please let me know if you have any questions!

- Desmond, team Mbed

Hi Desmond,

I did as you suggested and I still have the same problem.

    "macros": [
        "MBED_ALL_STATS_ENABLED=1"
    ],
plain text <<code>>
mbed compile -m MTS_DRAGONFLY_L471QG -t GCC_ARM --profile mbed-os/tools/profiles/debug.json

Every 5 seconds my application prints out:
sleep time = 0
deep sleep time = 0
idle time = 0
up time = 0

Leon

posted by Leon Lindenfelser 20 Nov 2018

Hi Leon,

I attach the code snippet I am using for testing this feature, could you try this one and let me know how it goes? Thanks.

get sleep time with this snippet

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

#if !defined(MBED_CPU_STATS_ENABLED) || !defined(DEVICE_LPTICKER) || !defined(DEVICE_SLEEP)
#error [NOT_SUPPORTED] test not supported
#endif

DigitalOut led1(LED1);

void print_stats()
{
    mbed_stats_cpu_t stats;
    mbed_stats_cpu_get(&stats);

    printf("%-20lld", stats.uptime);
    printf("%-20lld", stats.idle_time);
    printf("%-20lld", stats.sleep_time);
    printf("%-20lld\r\n", stats.deep_sleep_time);
}


// main() runs in its own thread in the OS
int main()
{
    printf("%-20s%-20s%-20s%-20s\r\n", "Uptime", "Idle Time", "Sleep time", "DeepSleep time");

    while (1) {
        led1 = !led1;
        print_stats();
        Thread::wait(3000);
    }

    return 0;
}
posted by Desmond Chen 21 Nov 2018

Hi Desmond,

It appears to work properly until I added a timer to loop for a couple seconds so I can see the stat times diverge. That's enough for now.

Thank you, Leon

posted by Leon Lindenfelser 27 Nov 2018