Skip to content

Handle receiving a ZLP in USB_Available #6886

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 11 additions & 1 deletion hardware/arduino/avr/cores/arduino/USBCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ static inline u8 FifoFree()
return UEINTX & (1<<FIFOCON);
}

static inline u8 HasOUT()
{
return UEINTX & (1<<RXOUTI);
}

static inline void ReleaseRX()
{
UEINTX = 0x6B; // FIFOCON=0 NAKINI=1 RWAL=1 NAKOUTI=0 RXSTPI=1 RXOUTI=0 STALLEDI=1 TXINI=1
Expand Down Expand Up @@ -214,7 +219,12 @@ class LockEP
u8 USB_Available(u8 ep)
{
LockEP lock(ep);
return FifoByteCount();
u8 n = FifoByteCount();

if (!n && HasOUT())
ReleaseRX(); // handle ZLP

return n;
}

// Non Blocking receive
Expand Down