Skip to content

Commit 8afe969

Browse files
committed
Make transmit timeout per endpoint
1 parent b627e00 commit 8afe969

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

cores/arduino/USB/USBCore.cpp

+15-6
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

@@ -602,6 +601,16 @@ uint8_t USBDeviceClass::armRecv(uint32_t ep)
602601
// Timeout for sends
603602
#define TX_TIMEOUT_MS 70
604603

604+
static char LastTransmitTimedOut[7] = {
605+
0,
606+
0,
607+
0,
608+
0,
609+
0,
610+
0,
611+
0
612+
};
613+
605614
// Blocking Send of data to an endpoint
606615
uint32_t USBDeviceClass::send(uint32_t ep, const void *data, uint32_t len)
607616
{
@@ -627,13 +636,13 @@ uint32_t USBDeviceClass::send(uint32_t ep, const void *data, uint32_t len)
627636
// previous transfer is still not complete
628637

629638
// convert the timeout from microseconds to a number of times through
630-
// the wait loop; it takes (roughly) 18 clock cycles per iteration.
631-
uint32_t timeout = microsecondsToClockCycles(TX_TIMEOUT_MS * 1000) / 18;
639+
// the wait loop; it takes (roughly) 23 clock cycles per iteration.
640+
uint32_t timeout = microsecondsToClockCycles(TX_TIMEOUT_MS * 1000) / 23;
632641

633642
// Wait for (previous) transfer to complete
634643
while (!usbd.epBank1IsTransferComplete(ep)) {
635-
if (lastTransmitTimedOut || timeout-- == 0) {
636-
lastTransmitTimedOut = 1;
644+
if (LastTransmitTimedOut[ep] || timeout-- == 0) {
645+
LastTransmitTimedOut[ep] = 1;
637646

638647
// set byte count to zero, so that ZLP is sent
639648
// instead of stale data
@@ -643,7 +652,7 @@ uint32_t USBDeviceClass::send(uint32_t ep, const void *data, uint32_t len)
643652
}
644653
}
645654

646-
lastTransmitTimedOut = 0;
655+
LastTransmitTimedOut[ep] = 0;
647656

648657
if (len >= EPX_SIZE) {
649658
length = EPX_SIZE - 1;

0 commit comments

Comments
 (0)