Skip to content

Commit f667443

Browse files
committed
Send ZLP (zero length packet) on flush, if last write filled buffer
Also, wait for write access before sending ZLP
1 parent aaec9e2 commit f667443

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

hardware/arduino/avr/cores/arduino/USBCore.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ static inline u8 FrameNumber()
191191
//==================================================================
192192
//==================================================================
193193

194+
bool _sendZlp[USB_ENDPOINTS];
195+
194196
u8 USBGetConfiguration(void)
195197
{
196198
return _usbConfiguration;
@@ -300,6 +302,7 @@ int USB_Send(u8 ep, const void* d, int len)
300302
while (n--)
301303
Send8(*data++);
302304
}
305+
_sendZlp[ep & USB_ENDPOINTS_MASK] = !ReadWriteAllowed() && (len == 0);
303306
if (!ReadWriteAllowed() || ((len == 0) && (ep & TRANSFER_RELEASE))) // Release full buffer
304307
ReleaseTX();
305308
}
@@ -625,8 +628,15 @@ ISR(USB_COM_vect)
625628
void USB_Flush(u8 ep)
626629
{
627630
SetEP(ep);
628-
if (FifoByteCount())
631+
632+
// wait for write access if a ZLP is needed
633+
if (_sendZlp[ep])
634+
while(!ReadWriteAllowed());
635+
636+
if (FifoByteCount() || _sendZlp[ep])
629637
ReleaseTX();
638+
639+
_sendZlp[ep] = false;
630640
}
631641

632642
static inline void USB_ClockDisable()

0 commit comments

Comments
 (0)