Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8609

Advanced users • SD card writes cause dropped USB packets

$
0
0
I'm having an issue with an RPi 4. I have a custom microcontroller that sends data packets over USB, around 7k each, one per second. On the Pi side I have a C app that uses libusb to get the packet from a bulk endpoint, parse it a bit, and write a few kilobytes to the SD card.

I'm using the basic fwrite() and printf() for writes to the file.

Occasionally, it misses a packet. The packet doesn't get buffered, it's just gone and I get the next one. The microcontroller definitely sends it, I've gone as far as checking with an oscilloscope that the USB packets are being sent.

On Windows it works flawlessly, but obviously the Windows machines are more powerful and write to an SSD. Still, it's bit surprising that writing a few kilobytes per second is enough to cause USB dropped packets.

I have tied:

- Parse but only write half the data. Fixes the issue.
- Async libusb, doesn't help.
- Split app into one that just reads USB at max priority, and one that just writes data from a pipe at low priority. Doesn't help.

OS is a pretty vanilla install of RPi OS:

PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
uname -r gives 6.1.21-v8+

I could try getting a faster SD card, but if it fails when writing more than a few kilobytes per second...

How can I fix this?

Statistics: Posted by aestetix — Tue Feb 06, 2024 2:53 pm



Viewing all articles
Browse latest Browse all 8609

Trending Articles