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.