Skip to content

Commit be738f7

Browse files
committed
Make transmit timeout per endpoint
1 parent 316eccf commit be738f7

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

cores/arduino/USB/USBCore.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ static volatile uint8_t rxLEDPulse; /**< Milliseconds remaining for data Rx LED
3838
#endif
3939
static char isRemoteWakeUpEnabled = 0;
4040
static char isEndpointHalt = 0;
41-
static char lastTransmitTimedOut = 0;
4241

4342
extern void (*gpf_isr)(void);
4443

@@ -606,6 +605,16 @@ uint8_t USBDeviceClass::armRecv(uint32_t ep)
606605
// Timeout for sends
607606
#define TX_TIMEOUT_MS 70
608607

608+
static char LastTransmitTimedOut[7] = {
609+
0,
610+
0,
611+
0,
612+
0,
613+
0,
614+
0,
615+
0
616+
};
617+
609618
// Blocking Send of data to an endpoint
610619
uint32_t USBDeviceClass::send(uint32_t ep, const void *data, uint32_t len)
611620
{
@@ -662,13 +671,13 @@ uint32_t USBDeviceClass::send(uint32_t ep, const void *data, uint32_t len)
662671
// previous transfer is still not complete
663672

664673
// convert the timeout from microseconds to a number of times through
665-
// the wait loop; it takes (roughly) 18 clock cycles per iteration.
666-
uint32_t timeout = microsecondsToClockCycles(TX_TIMEOUT_MS * 1000) / 18;
674+
// the wait loop; it takes (roughly) 23 clock cycles per iteration.
675+
uint32_t timeout = microsecondsToClockCycles(TX_TIMEOUT_MS * 1000) / 23;
667676

668677
// Wait for (previous) transfer to complete
669678
while (!usbd.epBank1IsTransferComplete(ep)) {
670-
if (lastTransmitTimedOut || timeout-- == 0) {
671-
lastTransmitTimedOut = 1;
679+
if (LastTransmitTimedOut[ep] || timeout-- == 0) {
680+
LastTransmitTimedOut[ep] = 1;
672681

673682
// set byte count to zero, so that ZLP is sent
674683
// instead of stale data
@@ -678,7 +687,7 @@ uint32_t USBDeviceClass::send(uint32_t ep, const void *data, uint32_t len)
678687
}
679688
}
680689

681-
lastTransmitTimedOut = 0;
690+
LastTransmitTimedOut[ep] = 0;
682691

683692
if (len >= 64) {
684693
length = 64;

0 commit comments

Comments
 (0)