From f1cdd5fb8d20904a91e87be8e654a2ba69bfbf66 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Fri, 13 Nov 2015 14:45:03 -0500 Subject: [PATCH 1/2] Split out endpoint size into variable --- hardware/arduino/sam/cores/arduino/USB/USBCore.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp b/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp index 56c4577b896..67461af18c2 100644 --- a/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp +++ b/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp @@ -195,6 +195,7 @@ uint32_t USBD_Send(uint32_t ep, const void* d, uint32_t len) { uint32_t n; int r = len; + uint32_t epSize = (ep==0) ? EP0_SIZE : EPX_SIZE; const uint8_t* data = (const uint8_t*)d; if (!_usbConfiguration) @@ -205,8 +206,7 @@ uint32_t USBD_Send(uint32_t ep, const void* d, uint32_t len) while (len) { - if(ep==0) n = EP0_SIZE; - else n = EPX_SIZE; + n = epSize; if (n > len) n = len; len -= n; From d0f5d0f83ec0311c6fd31adf86296751f8c6f937 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Fri, 13 Nov 2015 15:09:22 -0500 Subject: [PATCH 2/2] Send ZLP is data size is non-zero and a multiple of the endpoint size --- hardware/arduino/sam/cores/arduino/USB/USBCore.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp b/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp index 67461af18c2..fbd83cf18f2 100644 --- a/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp +++ b/hardware/arduino/sam/cores/arduino/USB/USBCore.cpp @@ -214,6 +214,10 @@ uint32_t USBD_Send(uint32_t ep, const void* d, uint32_t len) UDD_Send(ep & 0xF, data, n); data += n; } + + if ((r != 0) && (r % epSize) == 0) + UDD_Send(ep & 0xF, NULL, 0); + //TXLED1; // light the TX LED //TxLEDPulse = TX_RX_LED_PULSE_MS; return r;