Skip to content

Track if a USB ZLP is needed on flush #4138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions hardware/arduino/avr/cores/arduino/USBCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ static inline u8 FrameNumber()
//==================================================================
//==================================================================

bool _sendZlp[USB_ENDPOINTS];

u8 USBGetConfiguration(void)
{
return _usbConfiguration;
Expand All @@ -204,7 +206,7 @@ class LockEP
LockEP(u8 ep) : _sreg(SREG)
{
cli();
SetEP(ep & 7);
SetEP(ep & USB_ENDPOINTS_MASK);
}
~LockEP()
{
Expand Down Expand Up @@ -300,8 +302,15 @@ int USB_Send(u8 ep, const void* d, int len)
while (n--)
Send8(*data++);
}
if (!ReadWriteAllowed() || ((len == 0) && (ep & TRANSFER_RELEASE))) // Release full buffer
_sendZlp[ep & USB_ENDPOINTS_MASK] = !ReadWriteAllowed() && (len == 0) && !(ep & TRANSFER_RELEASE);

if (!ReadWriteAllowed()) // Release full buffer
ReleaseTX();

if ((len == 0) && (ep & TRANSFER_RELEASE)) {
while(!ReadWriteAllowed());
ReleaseTX();
}
}
}
TXLED1; // light the TX LED
Expand Down Expand Up @@ -625,8 +634,15 @@ ISR(USB_COM_vect)
void USB_Flush(u8 ep)
{
SetEP(ep);
if (FifoByteCount())

// wait for write access if a ZLP is needed
if (_sendZlp[ep])
while(!ReadWriteAllowed());

if (FifoByteCount() || _sendZlp[ep])
ReleaseTX();

_sendZlp[ep] = false;
}

static inline void USB_ClockDisable()
Expand Down
1 change: 1 addition & 0 deletions hardware/arduino/avr/cores/arduino/USBDesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#else
#define USB_ENDPOINTS 5 // AtMegaxxU2
#endif
#define USB_ENDPOINTS_MASK 7

#define ISERIAL_MAX_LEN 20

Expand Down