This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 09229d3ee41 drivers/serial/pty: Map CR to NL with ICRNL of the slave.
09229d3ee41 is described below

commit 09229d3ee41c79ee7eb570ff924c0e59be76ad73
Author: raiden00pl <[email protected]>
AuthorDate: Mon Nov 23 16:48:30 2026 +0100

    drivers/serial/pty: Map CR to NL with ICRNL of the slave.
    
    The master mapped CR to NL on write with its own OPOST | OCRNL.  Since
    TCSETS sets the flags of the slave on both ends, nothing can clear the
    flags of the master, so a raw mode set with cfmakeraw() still changed
    0x0d to 0x0a in the data written to the master and broke binary
    protocols.
    
    Do the mapping in the read of the slave with ICRNL, set by default.  The
    default behavior is the same, and a raw mode set through either end
    turns the mapping off.
    
    Tested on sim with a binary protocol over /dev/pty0 in raw mode.
    
    Assisted-by: Claude:claude-fable-5-2
    Signed-off-by: raiden00pl <[email protected]>
---
 drivers/serial/pty.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/serial/pty.c b/drivers/serial/pty.c
index b0f727d0c9d..1e699f678ca 100644
--- a/drivers/serial/pty.c
+++ b/drivers/serial/pty.c
@@ -1267,7 +1267,8 @@ int pty_register2(int minor, bool susv1)
   nxsem_init(&devpair->pp_slavesem, 0, 0);
   nxmutex_init(&devpair->pp_lock);
 
-  /* Map CR -> NL from terminal input (master)
+  /* Map CR -> NL from terminal input (master) with ICRNL of the slave, so
+   * that a raw mode set through either end turns it off.
    * For some usage like adb shell:
    *   adb shell write \r -> nsh read \n and echo input
    *   nsh write \n -> adb shell read \r\n
@@ -1279,8 +1280,8 @@ int pty_register2(int minor, bool susv1)
   devpair->pp_master.pd_devpair = devpair;
   devpair->pp_master.pd_master  = true;
   devpair->pp_slave.pd_devpair  = devpair;
-  uart_termios_init(&devpair->pp_master.pd_termios, 0, OPOST | OCRNL, 0);
-  uart_termios_init(&devpair->pp_slave.pd_termios, 0, OPOST | ONLCR,
+  uart_termios_init(&devpair->pp_master.pd_termios, 0, OPOST, 0);
+  uart_termios_init(&devpair->pp_slave.pd_termios, ICRNL, OPOST | ONLCR,
                     ECHO | ICANON | ISIG);
 #if defined(CONFIG_TTY_SIGINT) || defined(CONFIG_TTY_SIGTSTP)
   /* Initialize  of the task that will receive SIGINT signals. */

Reply via email to