Skip to content

Commit 3316756

Browse files
cmagliefacchinm
authored andcommitted
USBDevice: do not use automatic multi-packet USB transactions
If the host sends an unfinished OUT transaction (=> a transaction that ends with a data packet filled to the maximum allowed size but not followed by another shorter packet or a ZLP) the Transaction Completed interrupt is not fired and the incoming data remains suspendend until the host sends more data. This commit fix the problem by disabilng multi-packet transactions.
1 parent c7894e8 commit 3316756

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

cores/arduino/USB/SAMD21_USBDevice.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -235,20 +235,18 @@ class EPHandler {
235235

236236
class DoubleBufferedEPOutHandler : public EPHandler {
237237
public:
238-
DoubleBufferedEPOutHandler(USBDevice_SAMD21G18x &usbDev, uint32_t endPoint, uint32_t bufferSize) :
238+
enum { size = 64 };
239+
240+
DoubleBufferedEPOutHandler(USBDevice_SAMD21G18x &usbDev, uint32_t endPoint) :
239241
usbd(usbDev),
240-
ep(endPoint), size(bufferSize),
242+
ep(endPoint),
241243
current(0), incoming(0),
242244
first0(0), last0(0), ready0(false),
243245
first1(0), last1(0), ready1(false),
244246
notify(false)
245247
{
246-
data0 = reinterpret_cast<uint8_t *>(malloc(size));
247-
data1 = reinterpret_cast<uint8_t *>(malloc(size));
248-
249248
usbd.epBank0SetSize(ep, 64);
250249
usbd.epBank0SetType(ep, 3); // BULK OUT
251-
252250
usbd.epBank0SetAddress(ep, const_cast<uint8_t *>(data0));
253251

254252
release();
@@ -378,7 +376,6 @@ class DoubleBufferedEPOutHandler : public EPHandler {
378376
void release() {
379377
// Release OUT EP
380378
usbd.epBank0EnableTransferComplete(ep);
381-
usbd.epBank0SetMultiPacketSize(ep, size);
382379
usbd.epBank0SetByteCount(ep, 0);
383380
usbd.epBank0ResetReady(ep);
384381
}
@@ -387,15 +384,14 @@ class DoubleBufferedEPOutHandler : public EPHandler {
387384
USBDevice_SAMD21G18x &usbd;
388385

389386
const uint32_t ep;
390-
const uint32_t size;
391387
uint32_t current, incoming;
392388

393-
volatile uint8_t *data0;
389+
__attribute__((__aligned__(4))) volatile uint8_t data0[size];
394390
uint32_t first0;
395391
volatile uint32_t last0;
396392
volatile bool ready0;
397393

398-
volatile uint8_t *data1;
394+
__attribute__((__aligned__(4))) volatile uint8_t data1[size];
399395
uint32_t first1;
400396
volatile uint32_t last1;
401397
volatile bool ready1;

cores/arduino/USB/USBCore.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ void USBDeviceClass::initEP(uint32_t ep, uint32_t config)
408408
if (epHandlers[ep] != NULL) {
409409
delete (DoubleBufferedEPOutHandler*)epHandlers[ep];
410410
}
411-
epHandlers[ep] = new DoubleBufferedEPOutHandler(usbd, ep, 256);
411+
epHandlers[ep] = new DoubleBufferedEPOutHandler(usbd, ep);
412412
}
413413
else if (config == (USB_ENDPOINT_TYPE_BULK | USB_ENDPOINT_IN(0)))
414414
{

0 commit comments

Comments
 (0)