|
18 | 18 | #include "platform/mbed_wait_api.h"
|
19 | 19 | #include "platform/mbed_toolchain.h"
|
20 | 20 | #include "platform/mbed_interface.h"
|
| 21 | +#include "platform/mbed_retarget.h" |
21 | 22 | #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 |
28 | 23 |
|
29 | 24 | WEAK void mbed_die(void)
|
30 | 25 | {
|
@@ -61,30 +56,24 @@ void mbed_error_printf(const char *format, ...)
|
61 | 56 |
|
62 | 57 | void mbed_error_vfprintf(const char *format, va_list arg)
|
63 | 58 | {
|
64 |
| -#if DEVICE_SERIAL |
65 | 59 | #define ERROR_BUF_SIZE (128)
|
66 | 60 | core_util_critical_section_enter();
|
67 | 61 | char buffer[ERROR_BUF_SIZE];
|
68 | 62 | int size = vsnprintf(buffer, ERROR_BUF_SIZE, format, arg);
|
69 | 63 | 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 |
74 | 65 | char stdio_out_prev = '\0';
|
75 | 66 | for (int i = 0; i < size; i++) {
|
76 | 67 | 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); |
78 | 70 | }
|
79 |
| - serial_putc(&stdio_uart, buffer[i]); |
| 71 | + write(STDERR_FILENO, &buffer[i], 1); |
80 | 72 | stdio_out_prev = buffer[i];
|
81 | 73 | }
|
82 | 74 | #else
|
83 |
| - for (int i = 0; i < size; i++) { |
84 |
| - serial_putc(&stdio_uart, buffer[i]); |
85 |
| - } |
| 75 | + write(STDERR_FILENO, buffer, size); |
86 | 76 | #endif
|
87 | 77 | }
|
88 | 78 | core_util_critical_section_exit();
|
89 |
| -#endif |
90 | 79 | }
|
0 commit comments