From 2b886778957af3ab8d6445d1d2f21cbc4426e66d Mon Sep 17 00:00:00 2001
From: Juha Niskanen <juha.niskanen@haltian.com>
Date: Mon, 19 Oct 2020 18:43:55 +0300
Subject: [PATCH] system/cu: do not reset baud rate to zero when parity options
 are used

cfsetspeed() now stores baud rate to c_cflag member of
struct termios, so it must not be overridden later on.

Signed-off-by: Juha Niskanen <juha.niskanen@haltian.com>
---
 system/cu/cu.h      |  2 +-
 system/cu/cu_main.c | 16 ++++++++--------
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/system/cu/cu.h b/system/cu/cu.h
index 9ca6c78bb..f16aec189 100644
--- a/system/cu/cu.h
+++ b/system/cu/cu.h
@@ -70,7 +70,7 @@
 
 struct cu_globals_s
 {
-  int infd;            /* Incmoming data from serial port */
+  int infd;            /* Incoming data from serial port */
   int outfd;           /* Outgoing data to serial port */
   pthread_t listener;  /* Terminal listener thread */
 };
diff --git a/system/cu/cu_main.c b/system/cu/cu_main.c
index d914284b3..621088d3d 100644
--- a/system/cu/cu_main.c
+++ b/system/cu/cu_main.c
@@ -82,7 +82,7 @@ enum parity_mode
 
 static struct cu_globals_s g_cu;
 #ifdef CONFIG_SERIAL_TERMIOS
-int fd_std_tty;
+static int fd_std_tty;
 static struct termios g_tio_std;
 static struct termios g_tio_dev;
 #endif
@@ -144,13 +144,6 @@ static int set_termios(int fd, int rate, enum parity_mode parity,
 
   tio = g_tio_dev;
 
-  /* set baudrate */
-
-  if (rate != 0)
-    {
-      cfsetspeed(&tio, rate);
-    }
-
   switch (parity)
     {
       case PARITY_EVEN:
@@ -165,6 +158,13 @@ static int set_termios(int fd, int rate, enum parity_mode parity,
         break;
     }
 
+  /* set baudrate */
+
+  if (rate != 0)
+    {
+      cfsetspeed(&tio, rate);
+    }
+
   if (rtscts)
     {
       tio.c_cflag |= CRTS_IFLOW | CCTS_OFLOW;