Use BeagleBone PRU to collect data from Uart?


I have a sensor which dumps data packages at a continuous sampling rate via the uart. I tried to collect the data using a separate thread which collects the data and informs the main thread, when a complete package is available. But eventually it gets out of sync, probably because it gets descheduled for too long at some point.

My idea is now to use the PRU to collect the packages (of fixed length), calculate the checksum and push it to the main thread afterwards. Is this possible? Is there maybe a better solution (like a kernel module)? And has someone used the PRU with an UART before, so that I can take a look at some example code.
I have to admit that my experience either with assembler nor with Linux kernel modules is worth mentioning, but as the problem seems to be quite simple I thought it should be a good start.

Best regards,


How fast do you need to sample the UART? A kernel module would probably be quicker and it's easier to keep timing correct but it all comes down to your sample period really.

If you are using threads, you could use semaphores/mutex to synchronize

I would think you are doing something wrong, before digging into kernel or PRU for UART, I would make sure your sw behaves correctly.

at what rate does your sensor produce data?

Ok. I think I found the culprit.
I use libserial to handle the serial communication. It registers a signal
handler to wait for incoming data.
The periodic thread uses a blocking read for the waiting of the timer
event and apparently that can get aborted when the signal is issued. The
solution to this problem was to add the flag SA_RESTART
to the signal handler and recompile libserial. Then the read operation
will be restarted automatically in case it got interrupted. Manually
checking for the errno EINTR after a read failed and than restart did not
work stably.

A second thing then was that the device sometimes sends packages with
faulty checksums, which I didn't handle specifically.

Best regards,