Loosing data on serial port


I’m currently working on a project that uses a Beaglebone Green and I have some issues with reading from the serial port.

First some data about the OS:

  • Debian 9.3
  • installed bb-cape-overlays_4.14.20200403.0-0rcnee0~stretch+20200403_armhf.deb

The ttyO5 is connected to a FTDI FT312D which is connected to an Android Tablet.

I configured the port in RAW mode (cfmakeraw), baudrate is 921600, no flow control, 1 stop bit, 1 start bit, no parity.

The main thread reads from the port, puts it into a buffer and tries to find the frame start/end markers.

There are multiple threads that write to the port, but only one at a time (mutex).
Read and write can be “parallel” i.e. time sliced by the scheduler.

Now the problem: whenever I configure the port with VMIN > 0 or VTIME > 0 data is lost.
We can detect this because the length of the frame plus a CRC is transmitted and the number of bytes between the frame markers is smaller than it should be according to the length field.

I checked on the sender and it is sending the correct data.

We don’t loose data when I let the read call return also with 0 bytes (VMIN = 0, VTIME = 0).
I know that the missing flow control can lead to problems, but I don’t understand why it behaves this way.

What I find also strange is that I receive in the order of 1000 bytes (which would be around 10.8ms at this baudrate) per read with e.g. VMIN = 1 and saturating the link. I would expect to receive less. I guess this also depends on the load and when the thread can continue?

Any ideas?