From 8a0638831fdb69013e0fcd660d2a0897371c8224 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Fri, 6 Nov 2015 10:34:58 -0500 Subject: [PATCH 1/4] Use EPX_SIZE constant --- cores/arduino/USB/USBCore.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cores/arduino/USB/USBCore.cpp b/cores/arduino/USB/USBCore.cpp index 9642c2aad..2dedfae19 100644 --- a/cores/arduino/USB/USBCore.cpp +++ b/cores/arduino/USB/USBCore.cpp @@ -623,8 +623,8 @@ uint32_t USBDeviceClass::send(uint32_t ep, const void *data, uint32_t len) // Flash area while (len != 0) { - if (len >= 64) { - length = 64; + if (len > EPX_SIZE) { + length = EPX_SIZE; } else { length = len; } From 53ae1b96bfa3efdf41354b3cfffad93be43d0247 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Fri, 6 Nov 2015 10:36:11 -0500 Subject: [PATCH 2/4] Make whitespace consistent --- cores/arduino/USB/USBCore.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cores/arduino/USB/USBCore.cpp b/cores/arduino/USB/USBCore.cpp index 2dedfae19..bb904f84f 100644 --- a/cores/arduino/USB/USBCore.cpp +++ b/cores/arduino/USB/USBCore.cpp @@ -679,12 +679,12 @@ uint32_t USBDeviceClass::sendControl(const void* _data, uint32_t len) return length; } - while (len > 0) - { + while (len > 0) + { sent = armSend(EP0, data + pos, len); pos += sent; len -= sent; - } + } return length; } From 48e5dbb04ef8c1ca26e74da2094ba47ff29afd33 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Fri, 6 Nov 2015 10:41:21 -0500 Subject: [PATCH 3/4] Send empty transfer if send data length is a multiple of EPX_SIZE This indicates end of transfer --- cores/arduino/USB/USBCore.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cores/arduino/USB/USBCore.cpp b/cores/arduino/USB/USBCore.cpp index bb904f84f..6948fe1cf 100644 --- a/cores/arduino/USB/USBCore.cpp +++ b/cores/arduino/USB/USBCore.cpp @@ -581,6 +581,9 @@ uint8_t USBDeviceClass::armRecv(uint32_t ep) uint32_t USBDeviceClass::send(uint32_t ep, const void *data, uint32_t len) { uint32_t length = 0; + // if len is a multiple of EPX_SIZE an empty transfer needs to be sent + // to indicate end of transfer + bool sendEmpty = (len % EPX_SIZE) == 0; if (!_usbConfiguration) return -1; @@ -621,7 +624,7 @@ uint32_t USBDeviceClass::send(uint32_t ep, const void *data, uint32_t len) #endif // Flash area - while (len != 0) + while (len != 0 || sendEmpty) { if (len > EPX_SIZE) { length = EPX_SIZE; @@ -645,6 +648,12 @@ uint32_t USBDeviceClass::send(uint32_t ep, const void *data, uint32_t len) while (!usbd.epBank1IsTransferComplete(ep)) { ; // need fire exit. } + + if (len == 0 && sendEmpty) { + // empty transfer sent + sendEmpty = false; + } + len -= length; data += length; } From c0b2c7a400a477c974ad19c70f6d19fe211ce32f Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Fri, 13 Nov 2015 09:16:59 -0500 Subject: [PATCH 4/4] Rename sendEmpty to sendZlp --- cores/arduino/USB/USBCore.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cores/arduino/USB/USBCore.cpp b/cores/arduino/USB/USBCore.cpp index 6948fe1cf..0c7ef251c 100644 --- a/cores/arduino/USB/USBCore.cpp +++ b/cores/arduino/USB/USBCore.cpp @@ -581,9 +581,9 @@ uint8_t USBDeviceClass::armRecv(uint32_t ep) uint32_t USBDeviceClass::send(uint32_t ep, const void *data, uint32_t len) { uint32_t length = 0; - // if len is a multiple of EPX_SIZE an empty transfer needs to be sent + // if len is a multiple of EPX_SIZE an ZLP needs to be sent // to indicate end of transfer - bool sendEmpty = (len % EPX_SIZE) == 0; + bool sendZlp = (len % EPX_SIZE) == 0; if (!_usbConfiguration) return -1; @@ -624,7 +624,7 @@ uint32_t USBDeviceClass::send(uint32_t ep, const void *data, uint32_t len) #endif // Flash area - while (len != 0 || sendEmpty) + while (len != 0 || sendZlp) { if (len > EPX_SIZE) { length = EPX_SIZE; @@ -649,9 +649,9 @@ uint32_t USBDeviceClass::send(uint32_t ep, const void *data, uint32_t len) ; // need fire exit. } - if (len == 0 && sendEmpty) { + if (len == 0 && sendZlp) { // empty transfer sent - sendEmpty = false; + sendZlp = false; } len -= length;