From b4dc14af85e9a69dba6a9d63a422cd1a7aba8760 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Thu, 11 Apr 2024 10:12:33 -0300 Subject: [PATCH 1/8] Create HWCDC_Events.ino --- .../examples/HWCDC_Events/HWCDC_Events.ino | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 libraries/ESP32/examples/HWCDC_Events/HWCDC_Events.ino diff --git a/libraries/ESP32/examples/HWCDC_Events/HWCDC_Events.ino b/libraries/ESP32/examples/HWCDC_Events/HWCDC_Events.ino new file mode 100644 index 00000000000..6b55cdcb038 --- /dev/null +++ b/libraries/ESP32/examples/HWCDC_Events/HWCDC_Events.ino @@ -0,0 +1,88 @@ +/* + * This Example demonstrates how to receive Hardware Serial Events + * This USB interface is available for the ESP32-S3, ESP32-C3, ESP32-C6 and ESP32-H2 + * + * It will log all events and USB status (plugged/unplugged) into UART0 + * Any data read from UART0 will be sent to the USB CDC + * Any data read from USB CDC will be sent to the UART0 + * + * A suggestion is to use Arduino Serial Monitor for the UART0 port + * and some other serial monitor application for the USB CDC port + * in order to see the exchanged data and the Hardware Serial Events + * + */ + +#ifndef ARDUINO_USB_MODE +#error This ESP32 SoC has no Native USB interface +#elif ARDUINO_USB_MODE == 0 +#warning This sketch should be used when USB is in Hardware CDC and JTAG mode +void setup(){} +void loop(){} +#else + +#if !ARDUINO_USB_CDC_ON_BOOT +HWCDC HWCDCSerial; +#endif + +// USB Event Callback Function that will log CDC events into UART0 +static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) { + if (event_base == ARDUINO_HW_CDC_EVENTS) { + switch (event_id) { + case ARDUINO_HW_CDC_CONNECTED_EVENT: + Serial0.println("CDC EVENT:: ARDUINO_HW_CDC_CONNECTED_EVENT"); + break; + case ARDUINO_HW_CDC_BUS_RESET_EVENT: + Serial0.println("CDC EVENT:: ARDUINO_HW_CDC_BUS_RESET_EVENT"); + break; + case ARDUINO_HW_CDC_RX_EVENT: + Serial0.println("\nCDC EVENT:: ARDUINO_HW_CDC_RX_EVENT"); + // sends all bytes read from USB Hardware Serial to UART0 + while (HWCDCSerial.available()) Serial0.write(HWCDCSerial.read()); + break; + case ARDUINO_HW_CDC_TX_EVENT: + Serial0.println("CDC EVENT:: ARDUINO_HW_CDC_TX_EVENT"); + break; + + default: + break; + } + } +} + +const char* _hwcdc_status[] = { + " USB Plugged but CDC is NOT connected\r\n", + " USB Plugged and CDC is connected\r\n", + " USB Unplugged and CDC NOT connected\r\n", + " USB Unplugged BUT CDC is connected :: PROBLEM\r\n", +}; + +const char* HWCDC_Status() { + int i = HWCDCSerial.isPlugged() ? 0 : 2; + if(HWCDCSerial.isConnected()) i += 1; + return _hwcdc_status[i]; +} + +void setup() { + USBSerial.onEvent(usbEventCallback); + USBSerial.begin(); + + Serial0.begin(115200); + Serial0.setDebugOutput(true); + Serial0.println("Starting..."); +} + +void loop() { + static uint32_t counter = 0; + + Serial0.print(counter); + Serial0.print(HWCDC_Status()); + + if (HWCDCSerial) { + HWCDCSerial.printf(" [%ld] connected\n\r", counter); + } + // sends all bytes read from UART0 to USB Hardware Serial + while (Serial0.available()) HWCDCSerial.write(Serial0.read()); + delay(1000); + counter++; +} +#endif From ca9aa14d65a074249186678a03ca86d5111a83c9 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Thu, 11 Apr 2024 10:14:39 -0300 Subject: [PATCH 2/8] Delete libraries/ESP32/examples/HWSerial_Events/.skip.esp32 --- libraries/ESP32/examples/HWSerial_Events/.skip.esp32 | 1 - 1 file changed, 1 deletion(-) delete mode 100644 libraries/ESP32/examples/HWSerial_Events/.skip.esp32 diff --git a/libraries/ESP32/examples/HWSerial_Events/.skip.esp32 b/libraries/ESP32/examples/HWSerial_Events/.skip.esp32 deleted file mode 100644 index 8b137891791..00000000000 --- a/libraries/ESP32/examples/HWSerial_Events/.skip.esp32 +++ /dev/null @@ -1 +0,0 @@ - From 56d5c11539c09524bd5c2f67f1531a8d6b7fb5eb Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Thu, 11 Apr 2024 10:14:55 -0300 Subject: [PATCH 3/8] Delete libraries/ESP32/examples/HWSerial_Events/.skip.esp32s2 --- libraries/ESP32/examples/HWSerial_Events/.skip.esp32s2 | 1 - 1 file changed, 1 deletion(-) delete mode 100644 libraries/ESP32/examples/HWSerial_Events/.skip.esp32s2 diff --git a/libraries/ESP32/examples/HWSerial_Events/.skip.esp32s2 b/libraries/ESP32/examples/HWSerial_Events/.skip.esp32s2 deleted file mode 100644 index 8b137891791..00000000000 --- a/libraries/ESP32/examples/HWSerial_Events/.skip.esp32s2 +++ /dev/null @@ -1 +0,0 @@ - From 559e3f2bd13d1faab0496461e57491486f22ae66 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Thu, 11 Apr 2024 10:15:09 -0300 Subject: [PATCH 4/8] Delete libraries/ESP32/examples/HWSerial_Events/HWSerial_Events.ino --- .../HWSerial_Events/HWSerial_Events.ino | 88 ------------------- 1 file changed, 88 deletions(-) delete mode 100644 libraries/ESP32/examples/HWSerial_Events/HWSerial_Events.ino diff --git a/libraries/ESP32/examples/HWSerial_Events/HWSerial_Events.ino b/libraries/ESP32/examples/HWSerial_Events/HWSerial_Events.ino deleted file mode 100644 index 9c6de0501fa..00000000000 --- a/libraries/ESP32/examples/HWSerial_Events/HWSerial_Events.ino +++ /dev/null @@ -1,88 +0,0 @@ -/* - * This Example demonstrates how to receive Hardware Serial Events - * This USB interface is available for the ESP32-S3, ESP32-C3, ESP32-C6 and ESP32-H2 - * - * It will log all events and USB status (plugged/unplugged) into UART0 - * Any data read from UART0 will be sent to the USB CDC - * Any data read from USB CDC will be sent to the UART0 - * - * A suggestion is to use Arduino Serial Monitor for the UART0 port - * and some other serial monitor application for the USB CDC port - * in order to see the exchanged data and the Hardware Serial Events - * - */ - -#ifndef ARDUINO_USB_MODE -#error This ESP32 SoC has no Native USB interface -#elif ARDUINO_USB_MODE == 0 -#warning This sketch should be used when USB is in Hardware CDC and JTAG mode -void setup(){} -void loop(){} -#else - -#if !ARDUINO_USB_CDC_ON_BOOT -HWCDC HWCDCSerial; -#endif - -// USB Event Callback Function that will log CDC events into UART0 -static void usbEventCallback(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) { - if (event_base == ARDUINO_HW_CDC_EVENTS) { - switch (event_id) { - case ARDUINO_HW_CDC_CONNECTED_EVENT: - Serial0.println("CDC EVENT:: ARDUINO_HW_CDC_CONNECTED_EVENT"); - break; - case ARDUINO_HW_CDC_BUS_RESET_EVENT: - Serial0.println("CDC EVENT:: ARDUINO_HW_CDC_BUS_RESET_EVENT"); - break; - case ARDUINO_HW_CDC_RX_EVENT: - Serial0.println("\nCDC EVENT:: ARDUINO_HW_CDC_RX_EVENT"); - // sends all bytes read from USB Hardware Serial to UART0 - while (HWCDCSerial.available()) Serial0.write(HWCDCSerial.read()); - break; - case ARDUINO_HW_CDC_TX_EVENT: - Serial0.println("CDC EVENT:: ARDUINO_HW_CDC_TX_EVENT"); - break; - - default: - break; - } - } -} - -const char* _hwcdc_status[] = { - " USB Plugged but CDC is NOT connected\r\n", - " USB Plugged and CDC is connected\r\n", - " USB Unplugged and CDC NOT connected\r\n", - " USB Unplugged BUT CDC is connected :: PROBLEM\r\n", -}; - -const char* HWCDC_Status() { - int i = HWCDCSerial.isPlugged() ? 0 : 2; - if(HWCDCSerial.isConnected()) i += 1; - return _hwcdc_status[i]; -} - -void setup() { - Serial0.begin(115200); - Serial0.setDebugOutput(true); - - HWCDCSerial.begin(); - HWCDCSerial.onEvent(usbEventCallback); - Serial0.println("Starting..."); -} - -void loop() { - static uint32_t counter = 0; - - Serial0.print(counter); - Serial0.print(HWCDC_Status()); - - if (HWCDCSerial) { - HWCDCSerial.printf(" [%ld] connected\n\r", counter); - } - // sends all bytes read from UART0 to USB Hardware Serial - while (Serial0.available()) HWCDCSerial.write(Serial0.read()); - delay(1000); - counter++; -} -#endif From 5f471f0f85dfba8302732211522d02e41726d499 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Thu, 11 Apr 2024 10:15:32 -0300 Subject: [PATCH 5/8] Create .skip.esp32 --- libraries/ESP32/examples/HWCDC_Events/.skip.esp32 | 1 + 1 file changed, 1 insertion(+) create mode 100644 libraries/ESP32/examples/HWCDC_Events/.skip.esp32 diff --git a/libraries/ESP32/examples/HWCDC_Events/.skip.esp32 b/libraries/ESP32/examples/HWCDC_Events/.skip.esp32 new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/libraries/ESP32/examples/HWCDC_Events/.skip.esp32 @@ -0,0 +1 @@ + From 60dd40e4939d566f3adeb596d4c58dbdd94cd5f1 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Thu, 11 Apr 2024 10:15:49 -0300 Subject: [PATCH 6/8] Create .skip.esp32s2 --- libraries/ESP32/examples/HWCDC_Events/.skip.esp32s2 | 1 + 1 file changed, 1 insertion(+) create mode 100644 libraries/ESP32/examples/HWCDC_Events/.skip.esp32s2 diff --git a/libraries/ESP32/examples/HWCDC_Events/.skip.esp32s2 b/libraries/ESP32/examples/HWCDC_Events/.skip.esp32s2 new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/libraries/ESP32/examples/HWCDC_Events/.skip.esp32s2 @@ -0,0 +1 @@ + From 656e68e7711aeb90870002eb6dad04912723eac6 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Thu, 11 Apr 2024 10:30:45 -0300 Subject: [PATCH 7/8] Fixes HWCDC_Events.ino --- libraries/ESP32/examples/HWCDC_Events/HWCDC_Events.ino | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/libraries/ESP32/examples/HWCDC_Events/HWCDC_Events.ino b/libraries/ESP32/examples/HWCDC_Events/HWCDC_Events.ino index 6b55cdcb038..4248278c8ff 100644 --- a/libraries/ESP32/examples/HWCDC_Events/HWCDC_Events.ino +++ b/libraries/ESP32/examples/HWCDC_Events/HWCDC_Events.ino @@ -15,9 +15,7 @@ #ifndef ARDUINO_USB_MODE #error This ESP32 SoC has no Native USB interface #elif ARDUINO_USB_MODE == 0 -#warning This sketch should be used when USB is in Hardware CDC and JTAG mode -void setup(){} -void loop(){} +#error This sketch should be used when USB is in Hardware CDC and JTAG mode #else #if !ARDUINO_USB_CDC_ON_BOOT @@ -63,8 +61,8 @@ const char* HWCDC_Status() { } void setup() { - USBSerial.onEvent(usbEventCallback); - USBSerial.begin(); + HWCDCSerial.onEvent(usbEventCallback); + HWCDCSerial.begin(); Serial0.begin(115200); Serial0.setDebugOutput(true); From 38cba319be5644dc4f2ecbff8d48b6e647e25bb3 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Thu, 11 Apr 2024 10:34:08 -0300 Subject: [PATCH 8/8] Fixes CI for S3 --- libraries/ESP32/examples/HWCDC_Events/HWCDC_Events.ino | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/ESP32/examples/HWCDC_Events/HWCDC_Events.ino b/libraries/ESP32/examples/HWCDC_Events/HWCDC_Events.ino index 4248278c8ff..3376a7fddc8 100644 --- a/libraries/ESP32/examples/HWCDC_Events/HWCDC_Events.ino +++ b/libraries/ESP32/examples/HWCDC_Events/HWCDC_Events.ino @@ -15,7 +15,9 @@ #ifndef ARDUINO_USB_MODE #error This ESP32 SoC has no Native USB interface #elif ARDUINO_USB_MODE == 0 -#error This sketch should be used when USB is in Hardware CDC and JTAG mode +#warning This sketch should be used when USB is in Hardware CDC and JTAG mode +void setup(){} +void loop(){} #else #if !ARDUINO_USB_CDC_ON_BOOT