Luckily, I was able to use USB and UART0 at the same time. Of course, USB CDC on Boot is set to Enable. So I’ll share how I did it.
ESP-ROM:esp32c3-api1-20210207 Build:Feb 7 2021
Arduino core for the ESP32 v2.05
Arduino IDE 2.0.2
Note
In case of “CPU Frequency:160MHz”, it work correct, but in case of “CPU Frequency:40MHz”, it works at half the speed of what you set. This seems to be the cause.
/* Multiple Serial test for XIAO ESP32C3 */
HardwareSerial MySerial(0); //Create a new HardwareSerial class.
void setup() {
// initialize both serial ports:
Serial.begin(115200);
MySerial.begin(115200, SERIAL_8N1, RX, TX); // at CPU Freq is 40MHz, work half speed of defined.
}
void loop() {
// read from port 1, send to port 0:
if (MySerial.available()) {
String str = MySerial.readStringUntil('\r');
Serial.println(str);
}
// read from port 0, send to port 1:
if (Serial.available()) {
String str = Serial.readStringUntil('\r');
MySerial.println(str);
}
}
RX and TX is defined in arduino-esp32/variants/XIAO_ESP32C3/pins_arduino.h as below.
static const uint8_t TX = 21;
static const uint8_t RX = 20;
/* */
static const uint8_t D6 = 21;
static const uint8_t D7 = 20;