Missing bytes on serial link wec2013

Hello all,

following Latency receive on serial link wec2013 - Technical Support - Toradex Community, we are now facing another issue.

Our program is ready the serial link, little by little.
First, one byte to identify the communication.
Then, two more bytes that give us the length of the rest of the communication. So we expect to receive everything and respond with an ACK, else we respond with a NACK.

But by doing so, we are missing some bytes. Often the end, sometimes in between.
If we read without checking anything, we will receive all the expected bytes.

In this example, I send a message having 168 bytes in total, and my program can read them all.
If we split the read, for ID, then Length, then the rest, at one point it will not receive everything.

We think it may be due to some interrupt management, but are not sure…

Colibri Imx6
Boot version 1.8
OS: 1.6
Uart 2

Here is an example of the application running on device :

Here is the code I am using :
SerialPerfConsoleTest.cpp (5.8 KB)

On the other end, I send the message :
EE 00 A4 00 00 00 A4 00 00 0D 39 11 0A 54 58 54 2D 31 4C 2D 32 30 43 00 00 00 00 00 00 00 00 00 00 00 01 53 75 6D 6D 61 72 79 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 01 00 00 12 00 00 02 0A 00 03 00 03 00 02 00 64 00 00 08 00 00 0A 00 00 00 11 00 1F 09 01 00 04 0A 00 00 06 00 05 0A 10 00 13 01 1E 00 00 00 01 00 01 00 00 00 00 00 00 13 10 30 31 32 33 34 35 36 37 38 39 51 57 45 52 54 59 55 49 4F 50 10 00 13 01 1E 00 00 00 01 00 01 00 00 00 00 00 00 13 10 0D 81
Wait for the 06, wait one second, and send it again, all in a loop.

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Hello,

It sounds like you’re encountering a challenging issue with missing bytes during segmented serial communication on your Colibri iMX6 module. Let’s explore some potential solutions to help you resolve this problem:

  1. Buffer Management: Verify that your serial buffer is sufficiently large to accommodate the incoming data. If the buffer is too small, it might overflow, leading to data loss. Consider increasing the buffer size in your application settings if necessary.

  2. Interrupt Handling: Efficient interrupt handling is crucial in serial communication. Ensure that your interrupt service routine (ISR) is optimized to quickly process incoming data, minimizing the risk of missing bytes.

  3. Read Timing: When reading data in segments, ensure your application waits for the complete segment to be available before attempting to read it. Implement checks to confirm that the expected number of bytes is present in the buffer before proceeding with the read operation.

  4. Flow Control: Implementing hardware or software flow control can help manage the data flow between devices, preventing the sender from overwhelming the receiver and reducing the likelihood of data loss.

  5. Testing with Continuous Read: Since reading all data at once works without issues, try to replicate this logic in your segmented read approach. This might help identify any discrepancies in your current method.

  6. Debugging: Utilize debugging tools to monitor the serial data flow and identify any anomalies. This can provide insights into where the data loss is occurring.

By focusing on these areas, you should be able to pinpoint and resolve the issue with missing bytes during your segmented serial communication. If the problem persists, consider reviewing your code for any logical errors in data processing and handling.

I hope these suggestions prove helpful in addressing your issue.

Best regards,
Toradex AI Assistant

Please, also check if these links can help you solve your problem:

Linux iMX6 UART Driver Issues.

Hi @tkalkanci ,

The issue you describe is really strange.
Did you ever try to monitor the actual serial bytes transferred over the serial lines with some external capture device?
Since all bytes are received when doing a single read, i guess something is wrong with the way the bytes are processed when reading in chunks… are you sure you set the read timeouts correctly? Maybe not all bytes have been received yet and the read function returns with an incomplete number of bytes (due to timeout settings).
I see you still use Imag2 1.6: There was a BUG there that was fixed in the latest version about reported bytes when writing on serial port… don’t think it’s relevant in your case, but you could try to update anyway.
See:

Hi @tkalkanci ,

I just checked the source code you provided:
I see that you indeed change the Comm Timeouts.
The settings you use are MAXDWORD for ReadIntervalTimeout and 0 for both ReadTotalTimeoutConstant and ReadTotalTimeoutMultiplier
According the the MS documentation this settings means the ReadFile should return immediately with the amount of bytes already received, without waiting for the specified amount of bytes to be received.
See:

This could well explain your issue.

Hello Germano.tx,

Indeed we are monitoring with a serial external device, and checked all the bytes are well transmitted.

OK, we will check on the update.

Thank you !

Hello Germano.tx, sorry this is a mistake in the small demo application. We are normally using a 2 s time-out.

I will update and test again, checking also the update required.