Skip to content
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