is this normal even though i set the USB CDC on Boot setting to disabled?:
View attachment 587373
Yes don't worry about that, it depends on the board. Original code was done on a dev board with 2 usb ports and the code below works fine. On some boards it works differently (your boards file probably doesn't define this - ARDUINO_USB_MODE
), as long as when you compiled you make sure you disabled cdc it stops you sending serial data which would interfere with payload injection bytes. CDC enabled is only useful for debugging, which breaks injection code from working so make sure it's disabled when flashing the esp32-s3.
You can alter the logic in this code section, depending on what your board code uses, but it's not needed as it's only for UI stuff which doesn't effect injection at all.
Code:
#ifdef ARDUINO_USB_MODE
bool usb_cdc_enabled = ARDUINO_USB_MODE;
#else
bool usb_cdc_enabled = false;
#endif
#ifdef USBCON
usb_cdc_enabled = true;
#endif
#if !CONFIG_IDF_TARGET_ESP32S2
doc["usb"]["cdc_enabled"] = usb_cdc_enabled;
doc["usb"]["serial_connected"] = Serial ? true : false;
doc["usb"]["vid"] = USB_VID ? USB_VID : 0x303a;
doc["usb"]["pid"] = USB_PID ? USB_PID : 0x1001;
#endif
Here's what's wrong with the code and how to fix it:
USBCON Defined whenever the board/variant has any native USB support compiled in. It does not mean CDC is enabled.
Your code does this:
Sets usb_cdc_enabled = ARDUINO_USB_MODE → correctly gets 0 or 1
Then #ifdef USBCON → overwrites it with true regardless of the actual mode So on any board where the variant defines USBCON (most ESP32-S3 boards do), you always report CDC enabled even when the board is in OTG mode (ARDUINO_USB_MODE=0).
Why it varies by board
Different board definitions (in boards.txt / variants/) set these macros differently:
Some define USBCON in the variant headers
Some don't
The "USB Mode" menu in Arduino IDE (or your PlatformIO build_flags) controls ARDUINO_USB_MODE
So boards from one manufacturer may define USBCON while others don't, causing the inconsistent behavior you're seeing.
The fix
Use ARDUINO_USB_MODE as the authoritative source when it exists, and only fall back to USBCON when it doesn't:
Code:
bool usb_cdc_enabled = false;
#ifdef ARDUINO_USB_MODE
usb_cdc_enabled = (ARDUINO_USB_MODE == 1);
#elif defined(USBCON)
usb_cdc_enabled = true;
#endif
If you also want to account for the "CDC on Boot" setting specifically, you can add:
Code:
#ifdef ARDUINO_USB_CDC_ON_BOOT
usb_cdc_enabled = usb_cdc_enabled && ARDUINO_USB_CDC_ON_BOOT;
#endif
Bottom line: USBCON means "USB is present," not "CDC is enabled." Don't let it override ARDUINO_USB_MODE.
So to summerize, this is what your fixed code section should look like:
Code:
doc["mac"]["ap"] = macStr2;
doc["mac"]["base"] = baseMacStr;
bool usb_cdc_enabled = false;
#ifdef ARDUINO_USB_MODE
usb_cdc_enabled = (ARDUINO_USB_MODE == 1);
#elif defined(USBCON)
usb_cdc_enabled = true;
#endif
#ifdef ARDUINO_USB_CDC_ON_BOOT
usb_cdc_enabled = usb_cdc_enabled && ARDUINO_USB_CDC_ON_BOOT;
#endif
#if !CONFIG_IDF_TARGET_ESP32S2
doc["usb"]["cdc_enabled"] = usb_cdc_enabled;
doc["usb"]["serial_connected"] = Serial ? true : false;
doc["usb"]["vid"] = USB_VID ? USB_VID : 0x303a;
doc["usb"]["pid"] = USB_PID ? USB_PID : 0x1001;
#endif
Settings should look like this:
If you are still having issues after this, you probably have an issue with the usb cable/wires you are using either being soldered wrongly or not thick enough. So try a differen't usb cable and make sure to that gnd wire is connected between your chip and usb gnd on the switch.