From 456c0d528f2e3dd9f17780a4581cdc3ea8f426df Mon Sep 17 00:00:00 2001 From: Sylvain Pelissier Date: Thu, 23 Aug 2018 17:27:04 +0200 Subject: [PATCH 1/2] USB: Check on the number of bytes to send to not send more than expected. --- cores/arduino/USB/USBCore.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cores/arduino/USB/USBCore.cpp b/cores/arduino/USB/USBCore.cpp index e7652016..3c162c80 100644 --- a/cores/arduino/USB/USBCore.cpp +++ b/cores/arduino/USB/USBCore.cpp @@ -229,6 +229,11 @@ int USBD_SendControl(uint8_t flags __attribute__ ((unused)), const void* d, uint if (_cmark < _cend) { + if (_cmark + len > _cend) + { + len = _cend - _cmark; + length = len; + } while (len > 0) { sent = UDD_Send(EP0, data + pos, len); From eb7eb86c8f08299d6422e1cc631e082e9e261aa9 Mon Sep 17 00:00:00 2001 From: Sylvain Pelissier Date: Tue, 4 Sep 2018 17:55:47 +0200 Subject: [PATCH 2/2] Correct SET_INTERFACE request --- cores/arduino/USB/USBCore.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cores/arduino/USB/USBCore.cpp b/cores/arduino/USB/USBCore.cpp index 3c162c80..b6333001 100644 --- a/cores/arduino/USB/USBCore.cpp +++ b/cores/arduino/USB/USBCore.cpp @@ -109,6 +109,7 @@ static const unsigned char test_packet_buffer[] = { volatile uint32_t _usbConfiguration = 0; volatile uint32_t _usbInitialized = 0; uint32_t _usbSetInterface = 0; +uint32_t _usbAlternateSetting = 0; uint32_t _cdcComposite = 0; //================================================================== @@ -800,8 +801,9 @@ static void USB_ISR(void) } else if (SET_INTERFACE == r) { - _usbSetInterface = setup.wValueL; - TRACE_CORE(puts(">>> EP0 Int: SET_INTERFACE\r\n");) + _usbSetInterface = setup.wIndex; + _usbAlternateSetting = setup.wValueL; + TRACE_CORE(printf(">>> EP0 Int: SET_INTERFACE interface=%d alternateSetting=%d\r\n",_usbSetInterface, _usbAlternateSetting);) } } else