Seeed-Studio / ArduinoCore-samd

49 stars 27 forks source link

USB serial (CDC-ACM) to host is stingy with buffers, leads to blocking & bursting #59

Open egnor opened 2 years ago

egnor commented 2 years ago

Observed symptoms:

Discussion:

This code in USBDeviceClass::recv (called from _Serial::read) directly reads data from the USB buffer and only acknowledges the transfer once the code has been read by the app:

https://github.com/Seeed-Studio/ArduinoCore-samd/blob/991c4b032270cc7e53fdd70e31e75eeca2bdedc8/cores/arduino/USB/USBCore.cpp#L649

I believe this is why there is a zero-slack channel here, and why Serial.read() gives spurious -1 values as it reaches the end of one buffer and then returns it to the host for more data. Almost every other USB-serial implementation I've seen places some sort of ring buffer in between; USB transfers deposit data into the ring, and the application pulls out of it. That way there is a reasonable amount of "flex" and data can flow smoothly. Is that not something that can be done in this case?

Lesords commented 1 month ago

Hello,

I'm very sorry to have kept you waiting so long.

May I ask if you have solved this problem so far?

egnor commented 1 month ago

I haven't been using SAMD based parts lately, so I'm not sure if this is still an issue!

Lesords commented 1 month ago

I don't have the hardware for it at the moment, but when I do I'll check it out and let you know.