Skip to content

Commit 6147f6f

Browse files
authored
Merge pull request #192 from adafruit/add-note-multi-cdc
update multiple cdc example
2 parents 489752a + 0165c9e commit 6147f6f

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

examples/CDC/cdc_multi/cdc_multi.ino

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,45 @@
1515
*
1616
* Requirement:
1717
* The max number of CDC ports (CFG_TUD_CDC) has to be changed to at least 2.
18-
* Config file is located in Adafruit_TinyUSB_Arduino/src/arduino/ports/platform/tusb_config_platform.h
19-
* where platform is one of: esp32, nrf, rp2040, samd
18+
* Config file is located in Adafruit_TinyUSB_Arduino/src/arduino/ports/{platform}/tusb_config_{platform}.h
19+
* where platform is one of: nrf, rp2040, samd
20+
*
21+
* NOTE: Currnetly multiple CDCs on ESP32-Sx is not yet supported.
22+
* An PR to update core/esp32/USBCDC and/or pre-built libusb are needed.
23+
* We would implement this later when we could.
2024
*/
2125

2226
#include <Adafruit_TinyUSB.h>
2327

2428
#define LED LED_BUILTIN
2529

26-
// Create extra USB Serial Ports. "Serial" is already created.
27-
Adafruit_USBD_CDC USBSer1;
30+
// Create 2nd instance of CDC Ports.
31+
#ifdef ARDUINO_ARCH_ESP32
32+
#error "Currnetly multiple CDCs on ESP32-Sx is not yet supported. An PR to update core/esp32/USBCDC and/or pre-built libusb are needed."
33+
// for ESP32, we need to specify instance number when declaring object
34+
Adafruit_USBD_CDC USBSer1(1);
35+
#else
36+
Adafruit_USBD_CDC USBSer1;
37+
#endif
2838

2939
void setup() {
3040
pinMode(LED, OUTPUT);
3141

32-
// start up all of the USB Vitual ports, and wait for them to enumerate.
3342
Serial.begin(115200);
43+
44+
// check to see if multiple CDCs are enabled
45+
if ( CFG_TUD_CDC < 2 ) {
46+
digitalWrite(LED, HIGH); // LED on for error indicator
47+
48+
while(1) {
49+
Serial.printf("CFG_TUD_CDC must be at least 2, current value is %u\n", CFG_TUD_CDC);
50+
Serial.println(" Config file is located in Adafruit_TinyUSB_Arduino/src/arduino/ports/{platform}/tusb_config_{platform}.h");
51+
Serial.println(" where platform is one of: nrf, rp2040, samd");
52+
delay(1000);
53+
}
54+
}
55+
56+
// initialize 2nd CDC interface
3457
USBSer1.begin(115200);
3558

3659
while (!Serial || !USBSer1) {

src/arduino/Adafruit_USBD_CDC.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@
2727

2828
#include "Adafruit_TinyUSB_API.h"
2929

30-
#if defined(__cplusplus) && !defined(ARDUINO_ARCH_ESP32)
30+
#if defined(__cplusplus)
31+
32+
#if defined(ARDUINO_ARCH_ESP32)
33+
34+
// For ESP32 use USBCDC as it is compatible
35+
#define Adafruit_USBD_CDC USBCDC
36+
37+
#else
3138

3239
#include "Adafruit_USBD_Interface.h"
3340
#include "Stream.h"
@@ -96,5 +103,7 @@ extern Adafruit_USBD_CDC Serial;
96103
extern Adafruit_USBD_CDC SerialTinyUSB;
97104
#endif
98105

106+
#endif // else of ESP32
99107
#endif // __cplusplus
108+
100109
#endif

0 commit comments

Comments
 (0)