Skip to content

Commit 69c3362

Browse files
committed
Added newline conversion for stdout
stdout converts the following character sequences: \n -> \r\n \r\n -> \r\n \r -> \r \n\r -> \n\r For original behaviour, a serial object can be instantiated explicitly
1 parent 42561b9 commit 69c3362

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

hal/common/retarget.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ FileHandle::~FileHandle() {
8888
#if DEVICE_SERIAL
8989
extern int stdio_uart_inited;
9090
extern serial_t stdio_uart;
91+
static char stdio_prev;
9192
#endif
9293

9394
static void init_serial() {
@@ -227,7 +228,11 @@ extern "C" int PREFIX(_write)(FILEHANDLE fh, const unsigned char *buffer, unsign
227228
#if DEVICE_SERIAL
228229
if (!stdio_uart_inited) init_serial();
229230
for (unsigned int i = 0; i < length; i++) {
231+
if (buffer[i] == '\n' && stdio_prev != '\r') {
232+
serial_putc(&stdio_uart, '\r');
233+
}
230234
serial_putc(&stdio_uart, buffer[i]);
235+
stdio_prev = buffer[i];
231236
}
232237
#endif
233238
n = length;

0 commit comments

Comments
 (0)