From 8ef9bb3d7bd026b57a8568030d8992644c9b8de8 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Fri, 27 May 2016 11:21:34 -0400 Subject: [PATCH 1/2] Make return value of USBDeviceClass::send the bytes sent --- cores/arduino/USB/USBCore.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cores/arduino/USB/USBCore.cpp b/cores/arduino/USB/USBCore.cpp index 09cfa6fee..8d83b9df6 100644 --- a/cores/arduino/USB/USBCore.cpp +++ b/cores/arduino/USB/USBCore.cpp @@ -605,6 +605,7 @@ uint8_t USBDeviceClass::armRecv(uint32_t ep) // Blocking Send of data to an endpoint uint32_t USBDeviceClass::send(uint32_t ep, const void *data, uint32_t len) { + uint32_t written = 0; uint32_t length = 0; if (!_usbConfiguration) @@ -675,10 +676,11 @@ uint32_t USBDeviceClass::send(uint32_t ep, const void *data, uint32_t len) while (!usbd.epBank1IsTransferComplete(ep)) { ; // need fire exit. } + written += length; len -= length; data = (char *)data + length; } - return len; + return written; } uint32_t USBDeviceClass::armSend(uint32_t ep, const void* data, uint32_t len) From 8d0c1674628df1c2c7592f4fc17467c694f5a1be Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Fri, 27 May 2016 11:22:49 -0400 Subject: [PATCH 2/2] Change return value of Serial_::write to be the # of bytes written Previous 0 was always returned. --- cores/arduino/USB/CDC.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/arduino/USB/CDC.cpp b/cores/arduino/USB/CDC.cpp index 5a111dce9..6bfc6e890 100644 --- a/cores/arduino/USB/CDC.cpp +++ b/cores/arduino/USB/CDC.cpp @@ -262,7 +262,7 @@ size_t Serial_::write(const uint8_t *buffer, size_t size) { uint32_t r = usb.send(CDC_ENDPOINT_IN, buffer, size); - if (r == 0) { + if (r > 0) { return r; } else { setWriteError();