From 649703e50041368f00e91e4aa59e697e13144f32 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 1 Oct 2018 11:17:25 +0200 Subject: [PATCH 1/2] Clear _usbLineInfo structure on SerialUSB.end() --- cores/arduino/USB/CDC.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/cores/arduino/USB/CDC.cpp b/cores/arduino/USB/CDC.cpp index 3c795f18e..c60388deb 100644 --- a/cores/arduino/USB/CDC.cpp +++ b/cores/arduino/USB/CDC.cpp @@ -150,6 +150,7 @@ void Serial_::begin(uint32_t /* baud_count */, uint8_t /* config */) void Serial_::end(void) { + memset((void*)&_usbLineInfo, 0, sizeof(_usbLineInfo)); } int Serial_::available(void) From 200f2a9f15388ec42ba65148c4a528b7377cc50b Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 1 Oct 2018 11:17:44 +0200 Subject: [PATCH 2/2] Inplement USBDevice.end() --- cores/arduino/USB/USBAPI.h | 1 + cores/arduino/USB/USBCore.cpp | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/cores/arduino/USB/USBAPI.h b/cores/arduino/USB/USBAPI.h index 690488b79..379f55ed3 100644 --- a/cores/arduino/USB/USBAPI.h +++ b/cores/arduino/USB/USBAPI.h @@ -58,6 +58,7 @@ class USBDeviceClass { // USB Device API void init(); + bool end(); bool attach(); bool detach(); void setAddress(uint32_t addr); diff --git a/cores/arduino/USB/USBCore.cpp b/cores/arduino/USB/USBCore.cpp index 311903989..ee7b90a44 100644 --- a/cores/arduino/USB/USBCore.cpp +++ b/cores/arduino/USB/USBCore.cpp @@ -387,6 +387,13 @@ bool USBDeviceClass::detach() return true; } +bool USBDeviceClass::end() { + if (!initialized) + return false; + usbd.disable(); + return true; +} + bool USBDeviceClass::configured() { return _usbConfiguration != 0;