Skip to content

Commit 78f4b4b

Browse files
committed
Make mbed_error not serial-specific
Use write() on current output device instead - this works on the assumption that write() is safe to call from critical section. UARTSerial has previously been upgraded to support this, and this also improves the behaviour when buffered serial is in use - the current buffered output will be fully flushed before outputting the error message.
1 parent 1094c08 commit 78f4b4b

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

platform/mbed_board.c

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,8 @@
1818
#include "platform/mbed_wait_api.h"
1919
#include "platform/mbed_toolchain.h"
2020
#include "platform/mbed_interface.h"
21+
#include "platform/mbed_retarget.h"
2122
#include "platform/mbed_critical.h"
22-
#include "hal/serial_api.h"
23-
24-
#if DEVICE_SERIAL
25-
extern int stdio_uart_inited;
26-
extern serial_t stdio_uart;
27-
#endif
2823

2924
WEAK void mbed_die(void)
3025
{
@@ -61,30 +56,24 @@ void mbed_error_printf(const char *format, ...)
6156

6257
void mbed_error_vfprintf(const char *format, va_list arg)
6358
{
64-
#if DEVICE_SERIAL
6559
#define ERROR_BUF_SIZE (128)
6660
core_util_critical_section_enter();
6761
char buffer[ERROR_BUF_SIZE];
6862
int size = vsnprintf(buffer, ERROR_BUF_SIZE, format, arg);
6963
if (size > 0) {
70-
if (!stdio_uart_inited) {
71-
serial_init(&stdio_uart, STDIO_UART_TX, STDIO_UART_RX);
72-
}
73-
#if MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES
64+
#if MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES || MBED_CONF_PLATFORM_STDIO_CONVERT_TTY_NEWLINES
7465
char stdio_out_prev = '\0';
7566
for (int i = 0; i < size; i++) {
7667
if (buffer[i] == '\n' && stdio_out_prev != '\r') {
77-
serial_putc(&stdio_uart, '\r');
68+
const char cr = '\r';
69+
write(STDERR_FILENO, &cr, 1);
7870
}
79-
serial_putc(&stdio_uart, buffer[i]);
71+
write(STDERR_FILENO, &buffer[i], 1);
8072
stdio_out_prev = buffer[i];
8173
}
8274
#else
83-
for (int i = 0; i < size; i++) {
84-
serial_putc(&stdio_uart, buffer[i]);
85-
}
75+
write(STDERR_FILENO, buffer, size);
8676
#endif
8777
}
8878
core_util_critical_section_exit();
89-
#endif
9079
}

rtos/TARGET_CORTEX/TARGET_CORTEX_M/mbed_rtx_fault_handler.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "device.h"
1919
#include "platform/mbed_error.h"
2020
#include "platform/mbed_interface.h"
21-
#include "hal/serial_api.h"
2221

2322
#ifndef MBED_FAULT_HANDLER_DISABLED
2423
#include "mbed_rtx_fault_handler.h"

0 commit comments

Comments
 (0)