Skip to content

Commit d4c6b37

Browse files
authored
Merge pull request #14610 from jeromecoutant/DEV_SLEEP_TRACE
Power management stat : add verbosity level for MBED_SLEEP_TRACING_ENABLED
2 parents 41744c7 + 8e26a05 commit d4c6b37

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

platform/mbed_lib.json

+14
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,17 @@
114114
"value": null
115115
},
116116

117+
"deepsleep-stats-enabled": {
118+
"macro_name": "MBED_SLEEP_TRACING_ENABLED",
119+
"help": "Set to 1 to enable deepsleep lock stats",
120+
"value": null
121+
},
122+
123+
"deepsleep-stats-verbose": {
124+
"help": "Stats are logged at each step (need deepsleep-stats-enable)",
125+
"value": true
126+
},
127+
117128
"cthunk_count_max": {
118129
"help": "The maximum CThunk objects used at the same time. This must be greater than 0 and less 256",
119130
"value": 8
@@ -156,6 +167,9 @@
156167
}
157168
},
158169
"target_overrides": {
170+
"STM": {
171+
"deepsleep-stats-verbose": false
172+
},
159173
"EFM32": {
160174
"stdio-baud-rate": 115200
161175
},

platform/source/mbed_power_mgmt.c

+26-11
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
#include "platform/mbed_wait_api.h"
2929

3030
#include <stdio.h>
31+
#ifdef MBED_SLEEP_TRACING_ENABLED
32+
#include <string.h>
33+
#endif
3134

3235
#if DEVICE_SLEEP
3336

@@ -138,19 +141,27 @@ static sleep_statistic_t *sleep_tracker_add(const char *const filename)
138141

139142
static void sleep_tracker_print_stats(void)
140143
{
141-
mbed_error_printf("Sleep locks held:\r\n");
142-
for (int i = 0; i < STATISTIC_COUNT; ++i) {
143-
if (sleep_stats[i].count == 0) {
144-
continue;
145-
}
146-
147-
if (sleep_stats[i].identifier[0] == '\0') {
148-
return;
144+
if (sleep_manager_can_deep_sleep()) {
145+
mbed_error_printf("deepsleep unlocked");
146+
#ifdef MBED_DEBUG
147+
mbed_error_printf(" but disabled with MBED_DEBUG");
148+
#endif
149+
} else {
150+
mbed_error_printf("deepsleep locked by:");
151+
for (int i = 0; i < STATISTIC_COUNT; ++i) {
152+
if (sleep_stats[i].count == 0) {
153+
continue;
154+
}
155+
156+
if (sleep_stats[i].identifier[0] == '\0') {
157+
return;
158+
}
159+
160+
mbed_error_printf(" [%s x %u]", sleep_stats[i].identifier,
161+
sleep_stats[i].count);
149162
}
150-
151-
mbed_error_printf("[id: %s, count: %u]\r\n", sleep_stats[i].identifier,
152-
sleep_stats[i].count);
153163
}
164+
mbed_error_printf("\r\n");
154165
}
155166

156167
void sleep_tracker_lock(const char *const filename, int line)
@@ -164,7 +175,9 @@ void sleep_tracker_lock(const char *const filename, int line)
164175

165176
core_util_atomic_incr_u8(&stat->count, 1);
166177

178+
#if MBED_CONF_PLATFORM_DEEPSLEEP_STATS_VERBOSE
167179
mbed_error_printf("LOCK: %s, ln: %i, lock count: %u\r\n", filename, line, deep_sleep_lock);
180+
#endif
168181
}
169182

170183
void sleep_tracker_unlock(const char *const filename, int line)
@@ -179,7 +192,9 @@ void sleep_tracker_unlock(const char *const filename, int line)
179192

180193
core_util_atomic_decr_u8(&stat->count, 1);
181194

195+
#if MBED_CONF_PLATFORM_DEEPSLEEP_STATS_VERBOSE
182196
mbed_error_printf("UNLOCK: %s, ln: %i, lock count: %u\r\n", filename, line, deep_sleep_lock);
197+
#endif
183198
}
184199

185200
#endif // MBED_SLEEP_TRACING_ENABLED

targets/TARGET_STM/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,14 @@ Detailed sleep Mbed OS description : https://os.mbed.com/docs/mbed-os/latest/api
474474
- debug profile is disabling deepsleep
475475
- deepsleep can also be disabled by application or drivers using sleep_manager_lock_deep_sleep()
476476
- deep-sleep-latency value is configured to 4 by default for STM32
477+
- trace with MBED_SLEEP_TRACING_ENABLED macro is set by default with low verbosity
478+
```
479+
"target_overrides": {
480+
"*": {
481+
"platform.deepsleep-stats-enabled": true,
482+
"platform.deepsleep-stats-verbose": false
483+
},
484+
```
477485

478486

479487
### WiFi configuration

0 commit comments

Comments
 (0)