Hi everyone,
I’m trying to enable both USB Mass Storage (MSC) and USB CDC (Serial) simultaneously on an ESP32 using the Arduino framework in PlatformIO.
Currently, I have the following configuration in my platformio.ini:
build_flags =
-D ARDUINO_USB_MODE=1
-D ARDUINO_USB_CDC_ON_BOOT=0
With this setup, CDC and JTAG over USB work fine.
However, when I try to initialize the MSC interface like this:
msc.vendorID(“xxxxxx”);
msc.productID(“xxxxxx”);
msc.productRevision(“xxxxxx”);
msc.onRead(OnReadFunction);
msc.onWrite(OnWriteFunction);
msc.onStartStop(OnStartStopFunction);
msc.mediaPresent(true);
if (!msc.begin(SD.numSectors(), SD.sectorSize())) {
LOG_E(“MSC initialization failed!”);
}
USBSerial.onEvent(USBEventCallbackFunction);
USBSerial.begin(115200);
vTaskDelay(pdMS_TO_TICKS(100));
if (!USB.begin()) {
LOG_E(“USB initialization failed!”);
}
it seems that calling USB.begin() overrides the CDC interface — MSC works, but the serial port disappears.
If I remove USB.begin(), the CDC interface works again, but MSC stops working.
So my question is:
Is it possible to enable both USB MSC and CDC simultaneously on ESP32 in the Arduino environment?
And if so, should I use ARDUINO_USB_MODE=0 and ARDUINO_USB_CDC_ON_BOOT=0 to have full control of both interfaces manually?
Any guidance or working example would be greatly appreciated!
Thanks in advance.