UART high speed reading (6.25 Bits/sec)

Hello,
I struggling with serial communication on Jetson, I want my Jetson to read a stream of packages (exactly 114 bytes, each one with ~820 µs gap in between) from my STM board.

I’m using the serial library in c++ (which I changed a little to handle a bigger baud rate - 6’250’000, with termios2 ) (attached files).
serialib.h (4.9 KB)
serialib.cpp (24.5 KB)

Now I have a few problems (I’m sure that the STM side is working perfectly), but Jetson is doing tricks on me. I had a time when it’s somehow worked but now with no known reason, it keeps receiving less than half of the target amount (only around 45000 bytes/sec), if I comment out options.c_lflag |= (ICANON); (which successfully speed up communication previously) then I achieve ~70000.
Successfully I should receive 114000 bytes/sec.

If I try to change packages to some constant value then communication fails wholly (serial doesn’t even see available bytes).

I changed nothing in the library between the time when it’s worked pretty well (indeed received around target ~1000 packages, some had bad CRC but it’s not better now) and now. I also created a new project with only serial read but it’s making no difference - that makes me think there is something I don’t understand in hardware or karnel?

Here how to package looks like, the first byte is START_BYTE = 0xFF, the second is CRC_SUM, rest is 112 bytes of data:

Here’s the reading loop:


    serialib serial;
	
	if (serial.openDevice(STREAM_PORT, STREAM_BOUDRATE) == 1)
	{
		static ftor_DeltaTime stoper;
		while (true)
		{
			uint8_t buffer = 0;

			static int collected = 0;

			while (serial.available() > 0)
			{
				int nBytes = serial.readBytes(&buffer, 1, 0, 0);

				if (nBytes > 0)
				{
					collected += nBytes;
				}
			}
		}
	}

Even sending one byte per millisecond, it’s still giving only ~630 bytes per second.

Also (I’m not sure if that’s relevant, because it’s also happened when reading worked pretty good) when writing using serialib::writeBytes() there sometimes happened that program gets blocked for quite a lot time.
On the picture - the red line represents gpio signal that I see high just before using that function and set low after escaping it. The blue line represents written packages.

I did not look closely at the above, but I can tell you the base clock and divisor of the Jetson won’t be 100% up to spec at the higher UART speeds. You’re probably at the edge of where clocking is failing due to tolerance issues. The workaround is usually to use two stop bits. Do you have the option to work with two stop bits?

1 Like

hello vtg,

please also refer to Topic 1069632, for the steps to set 8M baud-rate settings,
thanks

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.