Skip to content

Commit 7e5e536

Browse files
author
deepikabhavnani
committed
Use mbed_error_printf instead of debug for ISR friendly prints
Internally in sleep tracing `debug` was used for trace prints, but all sleep API's are ISR safe and used in interrupts. This resulted in hardfaults / errors. Solution is to use `mbed_error_printf` instead for printing on UART
1 parent f83e1d2 commit 7e5e536

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

hal/mbed_sleep_manager.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@
2020
#include "platform/mbed_critical.h"
2121
#include "sleep_api.h"
2222
#include "platform/mbed_error.h"
23-
#include "platform/mbed_debug.h"
2423
#include "platform/mbed_stats.h"
2524
#include "us_ticker_api.h"
2625
#include "lp_ticker_api.h"
2726
#include <limits.h>
2827
#include <stdio.h>
2928
#include "platform/mbed_stats.h"
30-
29+
#include "platform/mbed_interface.h"
3130

3231
#if DEVICE_SLEEP
3332

@@ -105,14 +104,14 @@ static sleep_statistic_t *sleep_tracker_add(const char *const filename)
105104
}
106105
}
107106

108-
debug("No free indexes left to use in mbed sleep tracker.\r\n");
107+
mbed_error_printf("No free indexes left to use in mbed sleep tracker.\r\n");
109108

110109
return NULL;
111110
}
112111

113112
static void sleep_tracker_print_stats(void)
114113
{
115-
debug("Sleep locks held:\r\n");
114+
mbed_error_printf("Sleep locks held:\r\n");
116115
for (int i = 0; i < STATISTIC_COUNT; ++i) {
117116
if (sleep_stats[i].count == 0) {
118117
continue;
@@ -122,8 +121,8 @@ static void sleep_tracker_print_stats(void)
122121
return;
123122
}
124123

125-
debug("[id: %s, count: %u]\r\n", sleep_stats[i].identifier,
126-
sleep_stats[i].count);
124+
mbed_error_printf("[id: %s, count: %u]\r\n", sleep_stats[i].identifier,
125+
sleep_stats[i].count);
127126
}
128127
}
129128

@@ -138,7 +137,7 @@ void sleep_tracker_lock(const char *const filename, int line)
138137

139138
core_util_atomic_incr_u8(&stat->count, 1);
140139

141-
debug("LOCK: %s, ln: %i, lock count: %u\r\n", filename, line, deep_sleep_lock);
140+
mbed_error_printf("LOCK: %s, ln: %i, lock count: %u\r\n", filename, line, deep_sleep_lock);
142141
}
143142

144143
void sleep_tracker_unlock(const char *const filename, int line)
@@ -147,13 +146,13 @@ void sleep_tracker_unlock(const char *const filename, int line)
147146

148147
// Entry for this driver does not exist, something went wrong.
149148
if (stat == NULL) {
150-
debug("Unlocking sleep for driver that was not previously locked: %s, ln: %i\r\n", filename, line);
149+
mbed_error_printf("Unlocking sleep for driver that was not previously locked: %s, ln: %i\r\n", filename, line);
151150
return;
152151
}
153152

154153
core_util_atomic_decr_u8(&stat->count, 1);
155154

156-
debug("UNLOCK: %s, ln: %i, lock count: %u\r\n", filename, line, deep_sleep_lock);
155+
mbed_error_printf("UNLOCK: %s, ln: %i, lock count: %u\r\n", filename, line, deep_sleep_lock);
157156
}
158157

159158
#endif // MBED_SLEEP_TRACING_ENABLED

0 commit comments

Comments
 (0)