From 3e41bd8b359bbff95e7993b5b3615982b85a9cd0 Mon Sep 17 00:00:00 2001 From: Huang Qi Date: Tue, 7 Feb 2023 18:12:08 +0800 Subject: [PATCH] driver/serial: Convert CR to LF in driver Enable the behavior by default for console, but configurable by termios. Binary size: Before: text data bss dec hex filename 326460 409 8164 335033 51cb9 nuttx/nuttx After: text data bss dec hex filename 326478 409 8164 335051 51ccb nuttx/nuttx Signed-off-by: Huang Qi --- drivers/serial/serial.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c index 2fa17c6ede..cbb81e94cb 100644 --- a/drivers/serial/serial.c +++ b/drivers/serial/serial.c @@ -790,6 +790,11 @@ static ssize_t uart_read(FAR struct file *filep, * IUCLC - Not Posix * IXON/OXOFF - no xon/xoff flow control. */ +#else + if (dev->isconsole && ch == '\r') + { + ch = '\n'; + } #endif /* Store the received character */ @@ -1423,7 +1428,6 @@ static int uart_ioctl(FAR struct file *filep, int cmd, unsigned long arg) dev->tc_iflag = termiosp->c_iflag; dev->tc_oflag = termiosp->c_oflag; dev->tc_lflag = termiosp->c_lflag; - ret = 0; } break; @@ -1659,6 +1663,10 @@ int uart_register(FAR const char *path, FAR uart_dev_t *dev) /* Enable \n -> \r\n translation for the console */ dev->tc_oflag = OPOST | ONLCR; + + /* Convert CR to LF by default for console */ + + dev->tc_iflag |= ICRNL; } #endif