Open egnor opened 2 years ago
Hello,
I'm very sorry to have kept you waiting so long.
May I ask if you have solved this problem so far?
I haven't been using SAMD based parts lately, so I'm not sure if this is still an issue!
I don't have the hardware for it at the moment, but when I do I'll check it out and let you know.
Observed symptoms:
Serial.read()
will return -1 frequently. For example if the host sends "Hello World!",Serial.read()
might return 'H', 'e', 'l', -1, 'l', 'o', ' ', 'W', -1, ...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?