diff --git a/cores/arduino/USB/SAMD21_USBDevice.h b/cores/arduino/USB/SAMD21_USBDevice.h index e7e4cdfa5..90822e14f 100644 --- a/cores/arduino/USB/SAMD21_USBDevice.h +++ b/cores/arduino/USB/SAMD21_USBDevice.h @@ -319,30 +319,34 @@ class DoubleBufferedEPOutHandler : public EPHandler { usbd.epBank0AckTransferComplete(ep); //usbd.epBank0AckTransferFailed(ep); // XXX - // Update counters and swap banks + // Update counters and swap banks for non-ZLP's if (incoming == 0) { last0 = usbd.epBank0ByteCount(ep); - incoming = 1; - usbd.epBank0SetAddress(ep, const_cast(data1)); - ready0 = true; - synchronized { - if (ready1) { - notify = true; - return; + if (last0 != 0) { + incoming = 1; + usbd.epBank0SetAddress(ep, const_cast(data1)); + synchronized { + ready0 = true; + if (ready1) { + notify = true; + return; + } + notify = false; } - notify = false; } } else { last1 = usbd.epBank0ByteCount(ep); - incoming = 0; - usbd.epBank0SetAddress(ep, const_cast(data0)); - synchronized { - ready1 = true; - if (ready0) { - notify = true; - return; + if (last1 != 0) { + incoming = 0; + usbd.epBank0SetAddress(ep, const_cast(data0)); + synchronized { + ready1 = true; + if (ready0) { + notify = true; + return; + } + notify = false; } - notify = false; } } release();