Skip to content

Send a ZLP if data size is multiple of EPX_SIZE for USB sends #63

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 4 commits into from
Closed
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
21 changes: 15 additions & 6 deletions cores/arduino/USB/USBCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,9 @@ uint8_t USBDeviceClass::armRecv(uint32_t ep)
uint32_t USBDeviceClass::send(uint32_t ep, const void *data, uint32_t len)
{
uint32_t length = 0;
// if len is a multiple of EPX_SIZE an ZLP needs to be sent
// to indicate end of transfer
bool sendZlp = (len % EPX_SIZE) == 0;

if (!_usbConfiguration)
return -1;
Expand Down Expand Up @@ -621,10 +624,10 @@ uint32_t USBDeviceClass::send(uint32_t ep, const void *data, uint32_t len)
#endif

// Flash area
while (len != 0)
while (len != 0 || sendZlp)
{
if (len >= 64) {
length = 64;
if (len > EPX_SIZE) {
length = EPX_SIZE;
} else {
length = len;
}
Expand All @@ -645,6 +648,12 @@ uint32_t USBDeviceClass::send(uint32_t ep, const void *data, uint32_t len)
while (!usbd.epBank1IsTransferComplete(ep)) {
; // need fire exit.
}

if (len == 0 && sendZlp) {
// empty transfer sent
sendZlp = false;
}

len -= length;
data += length;
}
Expand Down Expand Up @@ -679,12 +688,12 @@ uint32_t USBDeviceClass::sendControl(const void* _data, uint32_t len)
return length;
}

while (len > 0)
{
while (len > 0)
{
sent = armSend(EP0, data + pos, len);
pos += sent;
len -= sent;
}
}

return length;
}
Expand Down