[Patch] bsp/tms570/sci: fix bug in tms570_sci_read_received_chars()

Adrien Chardon Adrien at reflexaerospace.com
Thu Jan 25 14:15:20 UTC 2024


Hi all,

(First time posting on a Mailing List, I apologize if I'm breaking any rule)
(For the record: this work is done during my work hours at Reflex Aerospace)

I believe that I found a bug in the TMS570 BSP, more specifically the receiving
part of the SCI driver. Please find attached the git diff with more details.

```
Author: Adrien Chardon <adrien at reflexaerospace.com>
Date:   Wed Jan 24 18:01:52 2024 +0100

    bsp/tms570/sci: fix bug in tms570_sci_read_received_chars()

    `tms570_sci_interrupt_handler()` is called when an RX interrupt fires. It checks
    in the register `FLR`, the `RXRDY` bit (Receiver ready flag - indicate that the
    SCIRD contains new data). If it is set, it calls
    `tms570_sci_read_received_chars()`.

    `tms570_sci_read_received_chars()` checks the register `RD` against 0. If it is
    non zero, it returns 1 to indicate that one byte was read.

    In the old behavior, if it is zero, the function returns 0 to indicate that no
    data was read.

    The new behavior is to not silently drop 0x00 bytes. Ignoring 0x00 bytes is fine
    when working with printable text (which, I assume, is how this driver was
    tested), but as soon as the UART is used in non canonical (raw) mode, with
    potentially 0x00 bytes, these bytes will be silently dropped, causing issues in
    the data/protocol layer above.

diff --git bsps/arm/tms570/console/tms570-sci.c bsps/arm/tms570/console/tms570-sci.c
index a14b7dad5d..eb7c381d42 100644
--- bsps/arm/tms570/console/tms570-sci.c
+++ bsps/arm/tms570/console/tms570-sci.c
@@ -191,11 +191,8 @@ static int tms570_sci_read_received_chars(
   if ( N < 1 ) {
     return 0;
   }
-  if ( ctx->regs->RD != 0 ) {
-     buf[0] = ctx->regs->RD;
-    return 1;
-  }
-  return 0;
+  buf[0] = ctx->regs->RD;
+  return 1;
 }
```

Best regards

Adrien Chardon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20240125/13a29c1f/attachment.htm>


More information about the devel mailing list