Skip to content

Add USB send timeout #152

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 1 commit 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
11 changes: 10 additions & 1 deletion cores/arduino/USB/USBCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,9 @@ uint8_t USBDeviceClass::armRecv(uint32_t ep)
return usbd.epBank0ByteCount(ep);
}

// Timeout for sends
#define TX_TIMEOUT_MS 70

// Blocking Send of data to an endpoint
uint32_t USBDeviceClass::send(uint32_t ep, const void *data, uint32_t len)
{
Expand Down Expand Up @@ -672,9 +675,15 @@ uint32_t USBDeviceClass::send(uint32_t ep, const void *data, uint32_t len)
// RAM buffer is full, we can send data (IN)
usbd.epBank1SetReady(ep);

// convert the timeout from microseconds to a number of times through
// the wait loop; it takes (roughly) 16 clock cycles per iteration.
uint32_t timeout = microsecondsToClockCycles(TX_TIMEOUT_MS * 1000) / 16;

// Wait for transfer to complete
while (!usbd.epBank1IsTransferComplete(ep)) {
; // need fire exit.
if (timeout-- == 0) {
return -1;
}
}
written += length;
len -= length;
Expand Down