diff --git a/platform/mbed_lib.json b/platform/mbed_lib.json index 6b03c00..fce62ea 100644 --- a/platform/mbed_lib.json +++ b/platform/mbed_lib.json @@ -114,6 +114,17 @@ "value": null }, + "deepsleep-stats-enabled": { + "macro_name": "MBED_SLEEP_TRACING_ENABLED", + "help": "Set to 1 to enable deepsleep lock stats", + "value": null + }, + + "deepsleep-stats-verbose": { + "help": "Stats are logged at each step (need deepsleep-stats-enable)", + "value": true + }, + "cthunk_count_max": { "help": "The maximum CThunk objects used at the same time. This must be greater than 0 and less 256", "value": 8 @@ -156,6 +167,9 @@ } }, "target_overrides": { + "STM": { + "deepsleep-stats-verbose": false + }, "EFM32": { "stdio-baud-rate": 115200 }, diff --git a/platform/source/mbed_power_mgmt.c b/platform/source/mbed_power_mgmt.c index 9d7724a..8da2c34 100644 --- a/platform/source/mbed_power_mgmt.c +++ b/platform/source/mbed_power_mgmt.c @@ -28,6 +28,9 @@ #include "platform/mbed_wait_api.h" #include +#ifdef MBED_SLEEP_TRACING_ENABLED +#include +#endif #if DEVICE_SLEEP @@ -138,19 +141,27 @@ static void sleep_tracker_print_stats(void) { - mbed_error_printf("Sleep locks held:\r\n"); - for (int i = 0; i < STATISTIC_COUNT; ++i) { - if (sleep_stats[i].count == 0) { - continue; - } + if (sleep_manager_can_deep_sleep()) { + mbed_error_printf("deepsleep unlocked"); +#ifdef MBED_DEBUG + mbed_error_printf(" but disabled with MBED_DEBUG"); +#endif + } else { + mbed_error_printf("deepsleep locked by:"); + for (int i = 0; i < STATISTIC_COUNT; ++i) { + if (sleep_stats[i].count == 0) { + continue; + } - if (sleep_stats[i].identifier[0] == '\0') { - return; - } + if (sleep_stats[i].identifier[0] == '\0') { + return; + } - mbed_error_printf("[id: %s, count: %u]\r\n", sleep_stats[i].identifier, - sleep_stats[i].count); + mbed_error_printf(" [%s x %u]", sleep_stats[i].identifier, + sleep_stats[i].count); + } } + mbed_error_printf("\r\n"); } void sleep_tracker_lock(const char *const filename, int line) @@ -164,7 +175,9 @@ core_util_atomic_incr_u8(&stat->count, 1); +#if MBED_CONF_PLATFORM_DEEPSLEEP_STATS_VERBOSE mbed_error_printf("LOCK: %s, ln: %i, lock count: %u\r\n", filename, line, deep_sleep_lock); +#endif } void sleep_tracker_unlock(const char *const filename, int line) @@ -179,7 +192,9 @@ core_util_atomic_decr_u8(&stat->count, 1); +#if MBED_CONF_PLATFORM_DEEPSLEEP_STATS_VERBOSE mbed_error_printf("UNLOCK: %s, ln: %i, lock count: %u\r\n", filename, line, deep_sleep_lock); +#endif } #endif // MBED_SLEEP_TRACING_ENABLED diff --git a/targets/TARGET_STM/README.md b/targets/TARGET_STM/README.md index 533d7ad..11c63ad 100644 --- a/targets/TARGET_STM/README.md +++ b/targets/TARGET_STM/README.md @@ -474,6 +474,14 @@ - debug profile is disabling deepsleep - deepsleep can also be disabled by application or drivers using sleep_manager_lock_deep_sleep() - deep-sleep-latency value is configured to 4 by default for STM32 +- trace with MBED_SLEEP_TRACING_ENABLED macro is set by default with low verbosity +``` + "target_overrides": { + "*": { + "platform.deepsleep-stats-enabled": true, + "platform.deepsleep-stats-verbose": false + }, +``` ### WiFi configuration