Serial driver occasionally sends incorrect character.

I have a C program running on my beaglebone-black board that sends single character commands to a device that returns single ‘\r’ terminated strings. Occasionally, a different character goes over the wire than what was sent by the program. For example, the program may send a ‘T’ and occasionally a ‘X’ goes over the wire. The incorrect character sent isn’t a random character, it’s always a valid command that was sent several commands before.

As an experiment, I wrote a simple program that sends characters ‘0’-‘9’ over and over. Occasionally I see a character that is out of order. For example, ‘8’ is sent instead of ‘5’. If I change the program to send ‘a’-‘z’ and re-run it, I may occasionally see ‘0’-‘9’ go over the wire instead of ‘a’-‘z’ at first, but eventually all of the incorrect characters sent over the wire are in the range of ‘a’-‘z’.

All of these clues point to an issue with the serial driver. I’m using UART4 and running 4.4.70-bone-rt-r17.

Any suggestions what to try next?

Not sure of your path to the USB port.

Best way is to build your own based upon termios.h.
Watch your buffers and arrays.

How are you decoding the information? Are you sure the decoder is working correctly?

The serial port path is “/dev/ttyS4”. The C code is base on termios.h (i.e. using open(), write(), read(), etc). I’m not decoding anything. In the experiment described above, I have a loopback jumper wire connecting TX to RX. I open() the port, write() a character, then read() character, and occasionally don’t get back what I sent.

This commit describes what I’m seeing, but I patched 8250_omap.c driver and it doesn’t fix my problem.

What speed are you using?

My suggestion would be move up to the latest kernel. Might even try an RT kernel. Pretty sure ours are on 5.?? kernels.

My baud rate is 9600bps. I’m running 4.4.70-bone-rt-r17, which is a RT kernel.

It turns out the commit above DOES fix my problem. I initially only replaced the modules on the board and rebooted. For some reason that didn’t work. I ended up replacing everything (kernel, modules, firmware, dtbs) and it works now.

Thank for your help!