-
-
Notifications
You must be signed in to change notification settings - Fork 729
Description
Hi,
I'm logging to SERIAL and have a lot (~3000 per sec) of iterrupts.
When having the interrupts active, the SERIAL.print() often drops characters (return 0 bytes written). This was reproducable on MKRzero and on MKR1000.
Fix is a small change in file USBCore.cpp:
When checking for last send was finished, its first tested for IsReady, then it waitet for TransferComplete. My assuption is, that ISR is happening inbetween, so there is a bigger time difference between both lines.
Adding in the wait loop the condition for IsReady solved the issue.
Here the code:
uint32_t USBDeviceClass::send(uint32_t ep, const void *data, uint32_t len)
{
[...]
while (len != 0)
{
if (usbd.epBank1IsReady(ep)) {
// previous transfer is still not complete
[...]
// Wait for (previous) transfer to complete
// inspired by Paul Stoffregen's work on Teensy
// [Pae] old version : while (!usbd.epBank1IsTransferComplete(ep) && usbd.epBank1IsReady(ep)) {
while (!usbd.epBank1IsTransferComplete(ep) && usbd.epBank1IsReady(ep)) {
// [Pae] ^^^ ^^^^^^^^^^^^^^
if (LastTransmitTimedOut[ep] || timeout-- == 0) {
LastTransmitTimedOut[ep] = 1;
// set byte count to zero, so that ZLP is sent
// instead of stale data
usbd.epBank1SetByteCount(ep, 0);
return -1;
}
}
}
What are your thoughts?
Can this be fixed?
Thanks and best regards
Achim