From d298f72727abe36433fcbf77b7de6e03da95f156 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 20 Sep 2025 11:29:54 +0000 Subject: [PATCH 01/11] Initial plan From bb10ec3b75a502dd30365e7964d527d5c20171df Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 20 Sep 2025 11:36:51 +0000 Subject: [PATCH 02/11] Fix ARDUINO_USB_MODE issue: change from 1 to 0 to allow normal boot Co-authored-by: netmindz <442066+netmindz@users.noreply.github.com> --- platformio.ini | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/platformio.ini b/platformio.ini index 96c06b9e..b5f51b1e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -455,7 +455,7 @@ build_flags = -g -D CONFIG_ASYNC_TCP_USE_WDT=0 -D CONFIG_ASYNC_TCP_TASK_STACK_SIZE=9472 ;; WLEDMM increase stack by 1.25Kb, as audioreactive needs bigger SETTINGS_STACK_BUF_SIZE -DCO - -DARDUINO_USB_MODE=1 ;; this flag is mandatory for ESP32-C3 + -DARDUINO_USB_MODE=0 ;; changed from 1 to 0 to allow normal boot without USB debugger ;; please make sure that the following flags are properly set (to 0 or 1) by your board.json, or included in your custom platformio_override.ini entry: ;; ARDUINO_USB_CDC_ON_BOOT @@ -702,7 +702,7 @@ build_unflags = ${common.build_unflags} build_flags = ${common.build_flags} ${esp32s3.build_flags} -D CONFIG_LITTLEFS_FOR_IDF_3_2 -D WLED_WATCHDOG_TIMEOUT=0 ;-D ARDUINO_USB_CDC_ON_BOOT=0 ;; -D ARDUINO_USB_MODE=1 ;; for boards with serial-to-USB chip - -D ARDUINO_USB_CDC_ON_BOOT=1 -D ARDUINO_USB_MODE=1 ;; for boards with USB-OTG connector only (USBCDC or "TinyUSB") + -D ARDUINO_USB_CDC_ON_BOOT=1 -D ARDUINO_USB_MODE=0 ;; changed from 1 to 0 to allow normal boot without USB debugger ; -D WLED_RELEASE_NAME=ESP32-S3_PSRAM -D WLED_USE_PSRAM -DBOARD_HAS_PSRAM ; tells WLED that PSRAM shall be used -D WLED_USE_PSRAM_JSON -DALL_JSON_TO_PSRAM ; WLEDMM --> force all JSON stuff into PSRAM; gives more free heap @@ -1907,7 +1907,7 @@ build_flags = ${common.build_flags} ${esp32s3.build_flags} -Wno-misleading-inden ${common_mm.HUB75_build_flags} ${common_mm.animartrix_build_flags} -D WLED_RELEASE_NAME=esp32S3_4MB_S - -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 ;; for Serial-to-USB chip + -DARDUINO_USB_MODE=0 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 ;; changed from 1 to 0 to allow normal boot without USB debugger ;;-DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=1 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=1 ;; for Hardware-CDC USB mode -D WLED_DISABLE_ADALIGHT ;; disables serial protocols - recommended for Hardware-CDC USB (Serial RX will receive junk commands when RX pin is unconnected, unless its pulled down by resistor) -D WLED_WATCHDOG_TIMEOUT=0 -D CONFIG_ASYNC_TCP_USE_WDT=0 @@ -1938,7 +1938,7 @@ build_flags = ${common.build_flags} ${esp32s3.build_flags} -Wno-misleading-inden ; -DBOARD_HAS_PSRAM -D WLED_USE_PSRAM_JSON -D WLED_USE_PSRAM ;; un-comment in case your board supports PSRAM ;; -D WLED_USE_PSRAM_JSON -DALL_JSON_TO_PSRAM ; WLEDMM --> force all JSON stuff into PSRAM; gives more free heap -D WLED_RELEASE_NAME=esp32S3_8MB_M - -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 ;; for Serial-to-USB chip + -DARDUINO_USB_MODE=0 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 ;; changed from 1 to 0 to allow normal boot without USB debugger ;;-DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=1 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=1 ;; for Hardware-CDC USB mode ;;-D WLED_DISABLE_ADALIGHT ;; disables serial protocols - recommended for Hardware-CDC USB (Serial RX will receive junk commands when RX pin is unconnected, unless its pulled down by resistor) -D WLED_WATCHDOG_TIMEOUT=0 -D CONFIG_ASYNC_TCP_USE_WDT=0 @@ -1989,7 +1989,7 @@ build_flags = ${common.build_flags} ${esp32s3.build_flags} -Wno-misleading-inden -DBOARD_HAS_PSRAM ;; -D WLED_USE_PSRAM ;; your board supports PSRAM -D WLED_USE_PSRAM_JSON -DALL_JSON_TO_PSRAM ; WLEDMM --> force all JSON stuff into PSRAM; gives more free heap -D WLED_RELEASE_NAME=esp32S3_8MB_PSRAM_M - -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 ;; for Serial-to-USB chip + -DARDUINO_USB_MODE=0 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 ;; changed from 1 to 0 to allow normal boot without USB debugger ;;-DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=1 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=1 ;; for Hardware-CDC USB mode ;;-D WLED_DISABLE_ADALIGHT ;; disables serial protocols - recommended for Hardware-CDC USB (Serial RX will receive junk commands when RX pin is unconnected, unless its pulled down by resistor) -D WLED_WATCHDOG_TIMEOUT=0 -D CONFIG_ASYNC_TCP_USE_WDT=0 @@ -2027,7 +2027,7 @@ build_unflags = ${env:esp32S3_8MB_M.build_unflags} ;; use the same as "normal" build_flags = ${common.build_flags} ${esp32s3.build_flags} -Wno-misleading-indentation -Wno-format-truncation ${common_mm.build_flags_S} -D WLED_RELEASE_NAME=esp32S3_8MB_S - -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 ;; for Serial-to-USB chip + -DARDUINO_USB_MODE=0 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 ;; changed from 1 to 0 to allow normal boot without USB debugger ;;-DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=1 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=1 ;; for Hardware-CDC USB mode ;;-D WLED_DISABLE_ADALIGHT ;; disables serial protocols - recommended for Hardware-CDC USB (Serial RX will receive junk commands when RX pin is unconnected, unless its pulled down by resistor) ${Speed_Flags.build_flags_V4} ;; optimize for speed instead of size @@ -2090,7 +2090,7 @@ build_flags = ${common.build_flags} ${esp32s3.build_flags} -Wno-misleading-inden -D MAX_SEGMENT_DATA=40960 ;; default 32767 -DBOARD_HAS_PSRAM ;; -D WLED_USE_PSRAM ;; your board supports PSRAM -D WLED_USE_PSRAM_JSON -DALL_JSON_TO_PSRAM ; WLEDMM --> force all JSON stuff into PSRAM; gives more free heap - -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 ;; for Serial-to-USB chip + -DARDUINO_USB_MODE=0 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 ;; changed from 1 to 0 to allow normal boot without USB debugger ;; -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=1 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=1 ;; for Hardware-CDC USB mode -D WLED_WATCHDOG_TIMEOUT=0 -D CONFIG_ASYNC_TCP_USE_WDT=0 ;; -DUSERMOD_BATTERY_MEASUREMENT_PIN=2 ;; battery voltage pin @@ -2134,7 +2134,7 @@ build_flags = ${common.build_flags} ${esp32s3.build_flags} -Wno-misleading-inden -D WLEDMM_FASTPATH -DBOARD_HAS_PSRAM ;; -D WLED_USE_PSRAM ;; your board supports PSRAM -D WLED_USE_PSRAM_JSON -DALL_JSON_TO_PSRAM ; WLEDMM --> force all JSON stuff into PSRAM; gives more free heap - -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 ;; for Serial-to-USB chip + -DARDUINO_USB_MODE=0 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 ;; changed from 1 to 0 to allow normal boot without USB debugger ;;-DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=1 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=1 ;; for Hardware-CDC USB mode -D WLED_WATCHDOG_TIMEOUT=0 -D CONFIG_ASYNC_TCP_USE_WDT=0 ;; -D LEDPIN=38 ;; buildin LED @@ -2160,7 +2160,7 @@ build_flags = ${common.build_flags} ${esp32s3.build_flags} -Wno-misleading-inden -D WLED_USE_PSRAM_JSON -DALL_JSON_TO_PSRAM ; WLEDMM --> force all JSON stuff into PSRAM; gives more free heap -DCONFIG_MBEDTLS_DYNAMIC_BUFFER=1 ;; optional - allows some buffers to use PSRAM -DLOLIN_WIFI_FIX -DWLEDMM_WIFI_POWERON_HACK ;; seems to work much better with this - -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=1 ;; for Serial-to-USB chip + -DARDUINO_USB_MODE=0 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=1 ;; changed from 1 to 0 to allow normal boot without USB debugger ;;-DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=1 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=1 ;; for Hardware-CDC USB mode -D WLED_DISABLE_ADALIGHT ;; disables serial protocols - recommended for Hardware-CDC USB (Serial RX will receive junk commands when RX pin is unconnected, unless its pulled down by resistor) ${Speed_Flags.build_flags_V4} ;; optimize for speed instead of size @@ -2205,7 +2205,7 @@ build_flags = ${common.build_flags} ${esp32s3.build_flags} -Wno-misleading-inden -D WLED_USE_PSRAM_JSON -DALL_JSON_TO_PSRAM ; WLEDMM --> force all JSON stuff into PSRAM; gives more free heap -DCONFIG_MBEDTLS_DYNAMIC_BUFFER=1 ;; optional - allows some buffers to use PSRAM -DLOLIN_WIFI_FIX -DWLEDMM_WIFI_POWERON_HACK ;; seems to work much better with this - -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=1 ;; for Serial-to-USB chip + -DARDUINO_USB_MODE=0 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=1 ;; changed from 1 to 0 to allow normal boot without USB debugger ;;-DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=1 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=1 ;; for Hardware-CDC USB mode -D WLED_DISABLE_ADALIGHT ;; disables serial protocols - recommended for Hardware-CDC USB (Serial RX will receive junk commands when RX pin is unconnected, unless its pulled down by resistor) ;; ${common_mm.animartrix_build_flags} ;; not enough flash From e094d60552c98583249ccf374b55c842158aaa1f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 20 Sep 2025 12:06:19 +0000 Subject: [PATCH 03/11] Implement conditional ARDUINO_USB_MODE: dev=1, release=0 Co-authored-by: netmindz <442066+netmindz@users.noreply.github.com> --- pio-scripts/conditional_usb_mode.py | 73 +++++++++++++++++++++++++++++ platformio.ini | 21 +++++---- 2 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 pio-scripts/conditional_usb_mode.py diff --git a/pio-scripts/conditional_usb_mode.py b/pio-scripts/conditional_usb_mode.py new file mode 100644 index 00000000..170eb923 --- /dev/null +++ b/pio-scripts/conditional_usb_mode.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python3 +""" +Conditional USB Mode Script for WLED-MM + +This script automatically sets ARDUINO_USB_MODE based on the build context: +- For development builds: ARDUINO_USB_MODE=1 (allows USB debugging) +- For release builds (CI): ARDUINO_USB_MODE=0 (allows normal boot without USB debugger) + +The script detects release builds by checking for the WLED_RELEASE environment variable +which is set to True in the GitHub Actions CI workflow. +""" + +Import('env') +import os + +def conditional_usb_mode(env): + """ + Conditionally set ARDUINO_USB_MODE based on build context. + + For ESP32-C3, ESP32-S2, and ESP32-S3 variants: + - Development builds: ARDUINO_USB_MODE=1 (default, good for debugging) + - Release builds: ARDUINO_USB_MODE=0 (prevents hanging without USB debugger) + """ + + # Check if this is a release build (CI sets WLED_RELEASE=True) + is_release_build = os.environ.get('WLED_RELEASE', '').lower() in ('true', '1', 'yes') + + if is_release_build: + print("WLED Release build detected - setting ARDUINO_USB_MODE=0 for production") + + # Find and modify ARDUINO_USB_MODE in build flags + build_flags = env.get('BUILD_FLAGS', []) + cpp_defines = env.get('CPPDEFINES', []) + + # Look through CPPDEFINES and modify ARDUINO_USB_MODE if found + modified = False + new_defines = [] + + for define in cpp_defines: + if isinstance(define, (list, tuple)) and len(define) == 2: + if define[0] == 'ARDUINO_USB_MODE' and define[1] == '1': + # Change ARDUINO_USB_MODE from 1 to 0 for release builds + new_defines.append(('ARDUINO_USB_MODE', '0')) + modified = True + print(f" Changed ARDUINO_USB_MODE from 1 to 0") + else: + new_defines.append(define) + else: + new_defines.append(define) + + if modified: + env.Replace(CPPDEFINES=new_defines) + + # Also check raw build flags for -DARDUINO_USB_MODE=1 + new_build_flags = [] + for flag in build_flags: + if isinstance(flag, str) and 'ARDUINO_USB_MODE=1' in flag: + # Replace ARDUINO_USB_MODE=1 with ARDUINO_USB_MODE=0 + new_flag = flag.replace('ARDUINO_USB_MODE=1', 'ARDUINO_USB_MODE=0') + new_build_flags.append(new_flag) + modified = True + print(f" Modified build flag: {flag} -> {new_flag}") + else: + new_build_flags.append(flag) + + if modified: + env.Replace(BUILD_FLAGS=new_build_flags) + + else: + print("Development build detected - keeping ARDUINO_USB_MODE=1 for debugging") + +# Apply the conditional USB mode logic +conditional_usb_mode(env) \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index b5f51b1e..ecdb65ce 100644 --- a/platformio.ini +++ b/platformio.ini @@ -220,6 +220,7 @@ ldscript_16m14m = eagle.flash.16m14m.ld extra_scripts = pre:pio-scripts/set_version.py pre:pio-scripts/build-html.py + pre:pio-scripts/conditional_usb_mode.py post:pio-scripts/output_bins.py post:pio-scripts/strip-floats.py pre:pio-scripts/user_config_copy.py @@ -455,7 +456,7 @@ build_flags = -g -D CONFIG_ASYNC_TCP_USE_WDT=0 -D CONFIG_ASYNC_TCP_TASK_STACK_SIZE=9472 ;; WLEDMM increase stack by 1.25Kb, as audioreactive needs bigger SETTINGS_STACK_BUF_SIZE -DCO - -DARDUINO_USB_MODE=0 ;; changed from 1 to 0 to allow normal boot without USB debugger + -DARDUINO_USB_MODE=1 ;; this flag is mandatory for ESP32-C3 ;; please make sure that the following flags are properly set (to 0 or 1) by your board.json, or included in your custom platformio_override.ini entry: ;; ARDUINO_USB_CDC_ON_BOOT @@ -702,7 +703,7 @@ build_unflags = ${common.build_unflags} build_flags = ${common.build_flags} ${esp32s3.build_flags} -D CONFIG_LITTLEFS_FOR_IDF_3_2 -D WLED_WATCHDOG_TIMEOUT=0 ;-D ARDUINO_USB_CDC_ON_BOOT=0 ;; -D ARDUINO_USB_MODE=1 ;; for boards with serial-to-USB chip - -D ARDUINO_USB_CDC_ON_BOOT=1 -D ARDUINO_USB_MODE=0 ;; changed from 1 to 0 to allow normal boot without USB debugger + -D ARDUINO_USB_CDC_ON_BOOT=1 -D ARDUINO_USB_MODE=1 ;; for boards with USB-OTG connector only (USBCDC or "TinyUSB") ; -D WLED_RELEASE_NAME=ESP32-S3_PSRAM -D WLED_USE_PSRAM -DBOARD_HAS_PSRAM ; tells WLED that PSRAM shall be used -D WLED_USE_PSRAM_JSON -DALL_JSON_TO_PSRAM ; WLEDMM --> force all JSON stuff into PSRAM; gives more free heap @@ -1907,7 +1908,7 @@ build_flags = ${common.build_flags} ${esp32s3.build_flags} -Wno-misleading-inden ${common_mm.HUB75_build_flags} ${common_mm.animartrix_build_flags} -D WLED_RELEASE_NAME=esp32S3_4MB_S - -DARDUINO_USB_MODE=0 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 ;; changed from 1 to 0 to allow normal boot without USB debugger + -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 ;; for Serial-to-USB chip ;;-DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=1 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=1 ;; for Hardware-CDC USB mode -D WLED_DISABLE_ADALIGHT ;; disables serial protocols - recommended for Hardware-CDC USB (Serial RX will receive junk commands when RX pin is unconnected, unless its pulled down by resistor) -D WLED_WATCHDOG_TIMEOUT=0 -D CONFIG_ASYNC_TCP_USE_WDT=0 @@ -1938,7 +1939,7 @@ build_flags = ${common.build_flags} ${esp32s3.build_flags} -Wno-misleading-inden ; -DBOARD_HAS_PSRAM -D WLED_USE_PSRAM_JSON -D WLED_USE_PSRAM ;; un-comment in case your board supports PSRAM ;; -D WLED_USE_PSRAM_JSON -DALL_JSON_TO_PSRAM ; WLEDMM --> force all JSON stuff into PSRAM; gives more free heap -D WLED_RELEASE_NAME=esp32S3_8MB_M - -DARDUINO_USB_MODE=0 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 ;; changed from 1 to 0 to allow normal boot without USB debugger + -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 ;; for Serial-to-USB chip ;;-DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=1 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=1 ;; for Hardware-CDC USB mode ;;-D WLED_DISABLE_ADALIGHT ;; disables serial protocols - recommended for Hardware-CDC USB (Serial RX will receive junk commands when RX pin is unconnected, unless its pulled down by resistor) -D WLED_WATCHDOG_TIMEOUT=0 -D CONFIG_ASYNC_TCP_USE_WDT=0 @@ -1989,7 +1990,7 @@ build_flags = ${common.build_flags} ${esp32s3.build_flags} -Wno-misleading-inden -DBOARD_HAS_PSRAM ;; -D WLED_USE_PSRAM ;; your board supports PSRAM -D WLED_USE_PSRAM_JSON -DALL_JSON_TO_PSRAM ; WLEDMM --> force all JSON stuff into PSRAM; gives more free heap -D WLED_RELEASE_NAME=esp32S3_8MB_PSRAM_M - -DARDUINO_USB_MODE=0 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 ;; changed from 1 to 0 to allow normal boot without USB debugger + -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 ;; for Serial-to-USB chip ;;-DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=1 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=1 ;; for Hardware-CDC USB mode ;;-D WLED_DISABLE_ADALIGHT ;; disables serial protocols - recommended for Hardware-CDC USB (Serial RX will receive junk commands when RX pin is unconnected, unless its pulled down by resistor) -D WLED_WATCHDOG_TIMEOUT=0 -D CONFIG_ASYNC_TCP_USE_WDT=0 @@ -2027,7 +2028,7 @@ build_unflags = ${env:esp32S3_8MB_M.build_unflags} ;; use the same as "normal" build_flags = ${common.build_flags} ${esp32s3.build_flags} -Wno-misleading-indentation -Wno-format-truncation ${common_mm.build_flags_S} -D WLED_RELEASE_NAME=esp32S3_8MB_S - -DARDUINO_USB_MODE=0 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 ;; changed from 1 to 0 to allow normal boot without USB debugger + -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 ;; for Serial-to-USB chip ;;-DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=1 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=1 ;; for Hardware-CDC USB mode ;;-D WLED_DISABLE_ADALIGHT ;; disables serial protocols - recommended for Hardware-CDC USB (Serial RX will receive junk commands when RX pin is unconnected, unless its pulled down by resistor) ${Speed_Flags.build_flags_V4} ;; optimize for speed instead of size @@ -2090,7 +2091,7 @@ build_flags = ${common.build_flags} ${esp32s3.build_flags} -Wno-misleading-inden -D MAX_SEGMENT_DATA=40960 ;; default 32767 -DBOARD_HAS_PSRAM ;; -D WLED_USE_PSRAM ;; your board supports PSRAM -D WLED_USE_PSRAM_JSON -DALL_JSON_TO_PSRAM ; WLEDMM --> force all JSON stuff into PSRAM; gives more free heap - -DARDUINO_USB_MODE=0 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 ;; changed from 1 to 0 to allow normal boot without USB debugger + -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 ;; for Serial-to-USB chip ;; -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=1 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=1 ;; for Hardware-CDC USB mode -D WLED_WATCHDOG_TIMEOUT=0 -D CONFIG_ASYNC_TCP_USE_WDT=0 ;; -DUSERMOD_BATTERY_MEASUREMENT_PIN=2 ;; battery voltage pin @@ -2134,7 +2135,7 @@ build_flags = ${common.build_flags} ${esp32s3.build_flags} -Wno-misleading-inden -D WLEDMM_FASTPATH -DBOARD_HAS_PSRAM ;; -D WLED_USE_PSRAM ;; your board supports PSRAM -D WLED_USE_PSRAM_JSON -DALL_JSON_TO_PSRAM ; WLEDMM --> force all JSON stuff into PSRAM; gives more free heap - -DARDUINO_USB_MODE=0 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 ;; changed from 1 to 0 to allow normal boot without USB debugger + -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=0 ;; for Serial-to-USB chip ;;-DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=1 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=1 ;; for Hardware-CDC USB mode -D WLED_WATCHDOG_TIMEOUT=0 -D CONFIG_ASYNC_TCP_USE_WDT=0 ;; -D LEDPIN=38 ;; buildin LED @@ -2160,7 +2161,7 @@ build_flags = ${common.build_flags} ${esp32s3.build_flags} -Wno-misleading-inden -D WLED_USE_PSRAM_JSON -DALL_JSON_TO_PSRAM ; WLEDMM --> force all JSON stuff into PSRAM; gives more free heap -DCONFIG_MBEDTLS_DYNAMIC_BUFFER=1 ;; optional - allows some buffers to use PSRAM -DLOLIN_WIFI_FIX -DWLEDMM_WIFI_POWERON_HACK ;; seems to work much better with this - -DARDUINO_USB_MODE=0 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=1 ;; changed from 1 to 0 to allow normal boot without USB debugger + -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=1 ;; for Serial-to-USB chip ;;-DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=1 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=1 ;; for Hardware-CDC USB mode -D WLED_DISABLE_ADALIGHT ;; disables serial protocols - recommended for Hardware-CDC USB (Serial RX will receive junk commands when RX pin is unconnected, unless its pulled down by resistor) ${Speed_Flags.build_flags_V4} ;; optimize for speed instead of size @@ -2205,7 +2206,7 @@ build_flags = ${common.build_flags} ${esp32s3.build_flags} -Wno-misleading-inden -D WLED_USE_PSRAM_JSON -DALL_JSON_TO_PSRAM ; WLEDMM --> force all JSON stuff into PSRAM; gives more free heap -DCONFIG_MBEDTLS_DYNAMIC_BUFFER=1 ;; optional - allows some buffers to use PSRAM -DLOLIN_WIFI_FIX -DWLEDMM_WIFI_POWERON_HACK ;; seems to work much better with this - -DARDUINO_USB_MODE=0 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=1 ;; changed from 1 to 0 to allow normal boot without USB debugger + -DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=0 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=1 ;; for Serial-to-USB chip ;;-DARDUINO_USB_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=1 -DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_USB_DFU_ON_BOOT=1 ;; for Hardware-CDC USB mode -D WLED_DISABLE_ADALIGHT ;; disables serial protocols - recommended for Hardware-CDC USB (Serial RX will receive junk commands when RX pin is unconnected, unless its pulled down by resistor) ;; ${common_mm.animartrix_build_flags} ;; not enough flash From 2932644381163a72363dd32b93b494f822a0acb8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 15 Nov 2025 21:25:33 +0000 Subject: [PATCH 04/11] Add CDC_ON_BOOT=1 check: only modify USB_MODE for USB-OTG boards Co-authored-by: softhack007 <91616163+softhack007@users.noreply.github.com> --- pio-scripts/conditional_usb_mode.py | 41 +++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/pio-scripts/conditional_usb_mode.py b/pio-scripts/conditional_usb_mode.py index 170eb923..5cb70b7f 100644 --- a/pio-scripts/conditional_usb_mode.py +++ b/pio-scripts/conditional_usb_mode.py @@ -8,25 +8,62 @@ This script automatically sets ARDUINO_USB_MODE based on the build context: The script detects release builds by checking for the WLED_RELEASE environment variable which is set to True in the GitHub Actions CI workflow. + +CRITICAL: This change only applies to boards with USB-OTG (ARDUINO_USB_CDC_ON_BOOT=1). +For boards with classical UART-to-USB chips (ARDUINO_USB_CDC_ON_BOOT=0), +ARDUINO_USB_MODE=1 is harmless and left unchanged. """ Import('env') import os +def has_cdc_on_boot_enabled(env): + """ + Check if ARDUINO_USB_CDC_ON_BOOT is set to 1 in the build configuration. + + Returns True if CDC_ON_BOOT=1, False otherwise. + This is used to identify boards with USB-OTG (native USB) vs UART-to-USB chips. + """ + cpp_defines = env.get('CPPDEFINES', []) + build_flags = env.get('BUILD_FLAGS', []) + + # Check in CPPDEFINES + for define in cpp_defines: + if isinstance(define, (list, tuple)) and len(define) == 2: + if define[0] == 'ARDUINO_USB_CDC_ON_BOOT' and define[1] == '1': + return True + + # Check in raw build flags + for flag in build_flags: + if isinstance(flag, str) and 'ARDUINO_USB_CDC_ON_BOOT=1' in flag: + return True + + return False + def conditional_usb_mode(env): """ Conditionally set ARDUINO_USB_MODE based on build context. - For ESP32-C3, ESP32-S2, and ESP32-S3 variants: + For ESP32-C3, ESP32-S2, and ESP32-S3 variants with USB-OTG (CDC_ON_BOOT=1): - Development builds: ARDUINO_USB_MODE=1 (default, good for debugging) - Release builds: ARDUINO_USB_MODE=0 (prevents hanging without USB debugger) + + For boards with classical UART-to-USB chip (CDC_ON_BOOT=0): + - ARDUINO_USB_MODE=1 is harmless and left unchanged """ # Check if this is a release build (CI sets WLED_RELEASE=True) is_release_build = os.environ.get('WLED_RELEASE', '').lower() in ('true', '1', 'yes') if is_release_build: - print("WLED Release build detected - setting ARDUINO_USB_MODE=0 for production") + # Check if this board uses USB-OTG (CDC_ON_BOOT=1) + if not has_cdc_on_boot_enabled(env): + print("WLED Release build detected - board has UART-to-USB chip (CDC_ON_BOOT=0)") + print(" Keeping ARDUINO_USB_MODE=1 (harmless for UART-to-USB boards)") + return + + print("WLED Release build detected - board has USB-OTG (CDC_ON_BOOT=1)") + print(" Setting ARDUINO_USB_MODE=0 for production") # Find and modify ARDUINO_USB_MODE in build flags build_flags = env.get('BUILD_FLAGS', []) From 0c92e573e1c56b1b8abce9f5be4d004d40cf0df7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 15 Nov 2025 21:48:43 +0000 Subject: [PATCH 05/11] Improve messaging: conditional warnings and production alerts Co-authored-by: softhack007 <91616163+softhack007@users.noreply.github.com> --- pio-scripts/conditional_usb_mode.py | 36 ++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/pio-scripts/conditional_usb_mode.py b/pio-scripts/conditional_usb_mode.py index 5cb70b7f..ca88ffda 100644 --- a/pio-scripts/conditional_usb_mode.py +++ b/pio-scripts/conditional_usb_mode.py @@ -40,6 +40,28 @@ def has_cdc_on_boot_enabled(env): return False +def has_usb_mode_enabled(env): + """ + Check if ARDUINO_USB_MODE is set to 1 in the build configuration. + + Returns True if USB_MODE=1, False otherwise. + """ + cpp_defines = env.get('CPPDEFINES', []) + build_flags = env.get('BUILD_FLAGS', []) + + # Check in CPPDEFINES + for define in cpp_defines: + if isinstance(define, (list, tuple)) and len(define) == 2: + if define[0] == 'ARDUINO_USB_MODE' and define[1] == '1': + return True + + # Check in raw build flags + for flag in build_flags: + if isinstance(flag, str) and 'ARDUINO_USB_MODE=1' in flag: + return True + + return False + def conditional_usb_mode(env): """ Conditionally set ARDUINO_USB_MODE based on build context. @@ -104,7 +126,19 @@ def conditional_usb_mode(env): env.Replace(BUILD_FLAGS=new_build_flags) else: - print("Development build detected - keeping ARDUINO_USB_MODE=1 for debugging") + # Development build + has_usb_mode = has_usb_mode_enabled(env) + has_cdc_boot = has_cdc_on_boot_enabled(env) + + if has_usb_mode and has_cdc_boot: + print("Development build detected - keeping ARDUINO_USB_MODE=1 for debugging") + # Warning in orange/yellow using ANSI color codes + print("\033[93m WARNING: This build is NOT suitable for production devices!\033[0m") + print("\033[93m Production builds require WLED_RELEASE=True environment variable.\033[0m") + elif has_usb_mode: + # USB_MODE=1 present but not CDC_ON_BOOT=1 (UART-to-USB board) + print("Development build detected - board has UART-to-USB chip") + # If neither flag is present, don't print anything # Apply the conditional USB mode logic conditional_usb_mode(env) \ No newline at end of file From 43b0da03aa3f2aa236669eec3a210991f645103d Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Sat, 15 Nov 2025 23:15:44 +0100 Subject: [PATCH 06/11] Update debug messages for USB mode detection --- pio-scripts/conditional_usb_mode.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pio-scripts/conditional_usb_mode.py b/pio-scripts/conditional_usb_mode.py index ca88ffda..a851648f 100644 --- a/pio-scripts/conditional_usb_mode.py +++ b/pio-scripts/conditional_usb_mode.py @@ -131,14 +131,17 @@ def conditional_usb_mode(env): has_cdc_boot = has_cdc_on_boot_enabled(env) if has_usb_mode and has_cdc_boot: - print("Development build detected - keeping ARDUINO_USB_MODE=1 for debugging") + print("Development build detected - keeping ARDUINO_USB_MODE=1 for USB-OTG debugging") # Warning in orange/yellow using ANSI color codes print("\033[93m WARNING: This build is NOT suitable for production devices!\033[0m") print("\033[93m Production builds require WLED_RELEASE=True environment variable.\033[0m") + elif has_cdc_boot: + # CDC_ON_BOOT=1 present but not USB_MODE=1 + print("Development build detected - USB-OTG enabled, but ARDUINO_USB_MODE=1 missing for debugging.") elif has_usb_mode: # USB_MODE=1 present but not CDC_ON_BOOT=1 (UART-to-USB board) print("Development build detected - board has UART-to-USB chip") # If neither flag is present, don't print anything # Apply the conditional USB mode logic -conditional_usb_mode(env) \ No newline at end of file +conditional_usb_mode(env) From 3bc68c574e2ddeed3cf0d008e80fe75d623b8bdc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 15 Nov 2025 23:24:01 +0000 Subject: [PATCH 07/11] Fix conflicting ARDUINO_USB_MODE definitions using BUILD_UNFLAGS Co-authored-by: softhack007 <91616163+softhack007@users.noreply.github.com> --- pio-scripts/conditional_usb_mode.py | 44 +++++------------------------ 1 file changed, 7 insertions(+), 37 deletions(-) diff --git a/pio-scripts/conditional_usb_mode.py b/pio-scripts/conditional_usb_mode.py index a851648f..08e73664 100644 --- a/pio-scripts/conditional_usb_mode.py +++ b/pio-scripts/conditional_usb_mode.py @@ -87,43 +87,13 @@ def conditional_usb_mode(env): print("WLED Release build detected - board has USB-OTG (CDC_ON_BOOT=1)") print(" Setting ARDUINO_USB_MODE=0 for production") - # Find and modify ARDUINO_USB_MODE in build flags - build_flags = env.get('BUILD_FLAGS', []) - cpp_defines = env.get('CPPDEFINES', []) - - # Look through CPPDEFINES and modify ARDUINO_USB_MODE if found - modified = False - new_defines = [] - - for define in cpp_defines: - if isinstance(define, (list, tuple)) and len(define) == 2: - if define[0] == 'ARDUINO_USB_MODE' and define[1] == '1': - # Change ARDUINO_USB_MODE from 1 to 0 for release builds - new_defines.append(('ARDUINO_USB_MODE', '0')) - modified = True - print(f" Changed ARDUINO_USB_MODE from 1 to 0") - else: - new_defines.append(define) - else: - new_defines.append(define) - - if modified: - env.Replace(CPPDEFINES=new_defines) - - # Also check raw build flags for -DARDUINO_USB_MODE=1 - new_build_flags = [] - for flag in build_flags: - if isinstance(flag, str) and 'ARDUINO_USB_MODE=1' in flag: - # Replace ARDUINO_USB_MODE=1 with ARDUINO_USB_MODE=0 - new_flag = flag.replace('ARDUINO_USB_MODE=1', 'ARDUINO_USB_MODE=0') - new_build_flags.append(new_flag) - modified = True - print(f" Modified build flag: {flag} -> {new_flag}") - else: - new_build_flags.append(flag) - - if modified: - env.Replace(BUILD_FLAGS=new_build_flags) + # Check if ARDUINO_USB_MODE=1 is present + if has_usb_mode_enabled(env): + # Remove the old definition and add the new one + # This approach properly handles flag inheritance in PlatformIO + env.Append(BUILD_UNFLAGS=["-DARDUINO_USB_MODE=1"]) + env.Append(CPPDEFINES=[("ARDUINO_USB_MODE", "0")]) + print(f" Changed ARDUINO_USB_MODE from 1 to 0") else: # Development build From 2869de215cfd298c6becb75846f4b71614d3f6c5 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Sun, 16 Nov 2025 00:35:23 +0100 Subject: [PATCH 08/11] USB mode script: updated print statements for clarity --- pio-scripts/conditional_usb_mode.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pio-scripts/conditional_usb_mode.py b/pio-scripts/conditional_usb_mode.py index 08e73664..0fd1e638 100644 --- a/pio-scripts/conditional_usb_mode.py +++ b/pio-scripts/conditional_usb_mode.py @@ -13,6 +13,7 @@ CRITICAL: This change only applies to boards with USB-OTG (ARDUINO_USB_CDC_ON_BO For boards with classical UART-to-USB chips (ARDUINO_USB_CDC_ON_BOOT=0), ARDUINO_USB_MODE=1 is harmless and left unchanged. """ +## This script was created with the help of an AI, reviewed and tested by @softhack007 Import('env') import os @@ -80,11 +81,11 @@ def conditional_usb_mode(env): if is_release_build: # Check if this board uses USB-OTG (CDC_ON_BOOT=1) if not has_cdc_on_boot_enabled(env): - print("WLED Release build detected - board has UART-to-USB chip (CDC_ON_BOOT=0)") + print("WLED Release build detected - board uses UART-to-USB chip (CDC_ON_BOOT=0)") print(" Keeping ARDUINO_USB_MODE=1 (harmless for UART-to-USB boards)") return - print("WLED Release build detected - board has USB-OTG (CDC_ON_BOOT=1)") + print("WLED Release build detected - board uses USB-OTG (CDC_ON_BOOT=1)") print(" Setting ARDUINO_USB_MODE=0 for production") # Check if ARDUINO_USB_MODE=1 is present @@ -107,10 +108,10 @@ def conditional_usb_mode(env): print("\033[93m Production builds require WLED_RELEASE=True environment variable.\033[0m") elif has_cdc_boot: # CDC_ON_BOOT=1 present but not USB_MODE=1 - print("Development build detected - USB-OTG enabled, but ARDUINO_USB_MODE=1 missing for debugging.") + print("Development build detected - USB-OTG enabled, but ARDUINO_USB_MODE=1 missing for debugging") elif has_usb_mode: # USB_MODE=1 present but not CDC_ON_BOOT=1 (UART-to-USB board) - print("Development build detected - board has UART-to-USB chip") + print("Development build detected - board uses UART-to-USB chip") # If neither flag is present, don't print anything # Apply the conditional USB mode logic From c785cb5f6c756008ec30279e046136c78e4344be Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 15 Nov 2025 23:51:04 +0000 Subject: [PATCH 09/11] Fix Serial breakage: remove ARDUINO_USB_MODE instead of setting to 0 Co-authored-by: softhack007 <91616163+softhack007@users.noreply.github.com> --- pio-scripts/conditional_usb_mode.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/pio-scripts/conditional_usb_mode.py b/pio-scripts/conditional_usb_mode.py index 0fd1e638..2d34126e 100644 --- a/pio-scripts/conditional_usb_mode.py +++ b/pio-scripts/conditional_usb_mode.py @@ -2,9 +2,9 @@ """ Conditional USB Mode Script for WLED-MM -This script automatically sets ARDUINO_USB_MODE based on the build context: +This script automatically manages ARDUINO_USB_MODE based on the build context: - For development builds: ARDUINO_USB_MODE=1 (allows USB debugging) -- For release builds (CI): ARDUINO_USB_MODE=0 (allows normal boot without USB debugger) +- For release builds (CI): ARDUINO_USB_MODE is removed (prevents hanging, allows normal boot) The script detects release builds by checking for the WLED_RELEASE environment variable which is set to True in the GitHub Actions CI workflow. @@ -12,6 +12,10 @@ which is set to True in the GitHub Actions CI workflow. CRITICAL: This change only applies to boards with USB-OTG (ARDUINO_USB_CDC_ON_BOOT=1). For boards with classical UART-to-USB chips (ARDUINO_USB_CDC_ON_BOOT=0), ARDUINO_USB_MODE=1 is harmless and left unchanged. + +IMPORTANT: We remove ARDUINO_USB_MODE entirely for release builds rather than setting +it to 0, because ARDUINO_USB_MODE=0 breaks Serial functionality when CDC_ON_BOOT=1. +When ARDUINO_USB_MODE is undefined, the framework uses appropriate defaults. """ ## This script was created with the help of an AI, reviewed and tested by @softhack007 @@ -65,14 +69,17 @@ def has_usb_mode_enabled(env): def conditional_usb_mode(env): """ - Conditionally set ARDUINO_USB_MODE based on build context. + Conditionally manage ARDUINO_USB_MODE based on build context. For ESP32-C3, ESP32-S2, and ESP32-S3 variants with USB-OTG (CDC_ON_BOOT=1): - Development builds: ARDUINO_USB_MODE=1 (default, good for debugging) - - Release builds: ARDUINO_USB_MODE=0 (prevents hanging without USB debugger) + - Release builds: ARDUINO_USB_MODE removed (prevents hanging, preserves Serial functionality) For boards with classical UART-to-USB chip (CDC_ON_BOOT=0): - ARDUINO_USB_MODE=1 is harmless and left unchanged + + Note: We remove the flag entirely rather than setting to 0, because + ARDUINO_USB_MODE=0 breaks Serial functionality with CDC_ON_BOOT=1. """ # Check if this is a release build (CI sets WLED_RELEASE=True) @@ -86,15 +93,14 @@ def conditional_usb_mode(env): return print("WLED Release build detected - board uses USB-OTG (CDC_ON_BOOT=1)") - print(" Setting ARDUINO_USB_MODE=0 for production") + print(" Removing ARDUINO_USB_MODE definition for production") # Check if ARDUINO_USB_MODE=1 is present if has_usb_mode_enabled(env): - # Remove the old definition and add the new one - # This approach properly handles flag inheritance in PlatformIO + # Remove ARDUINO_USB_MODE entirely - don't set it to 0 as that breaks Serial + # When undefined, the framework uses appropriate defaults based on CDC_ON_BOOT env.Append(BUILD_UNFLAGS=["-DARDUINO_USB_MODE=1"]) - env.Append(CPPDEFINES=[("ARDUINO_USB_MODE", "0")]) - print(f" Changed ARDUINO_USB_MODE from 1 to 0") + print(f" Removed ARDUINO_USB_MODE definition (was 1)") else: # Development build From 6ccbfe61ab60fb55983670d9c45a2d11ff7ea75f Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Sun, 16 Nov 2025 01:08:27 +0100 Subject: [PATCH 10/11] additional debug help --- pio-scripts/output_bins.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pio-scripts/output_bins.py b/pio-scripts/output_bins.py index 3a55ced8..6b5ed337 100644 --- a/pio-scripts/output_bins.py +++ b/pio-scripts/output_bins.py @@ -49,7 +49,7 @@ def wledmm_print_build_info(env): found = False for item in all_flags: - if 'WLED_RELEASE_NAME' in item[0] or 'WLED_VERSION' in item[0] or 'ARDUINO_USB_CDC_ON_BOOT' in item[0]: + if 'WLED_RELEASE_NAME' in item[0] or 'WLED_VERSION' in item[0] or 'ARDUINO_USB_CDC_ON_BOOT' in item[0] or 'ARDUINO_USB_MODE' in item[0]: if first: print("\nUsermods and Features:") print_my_item(item) first = False From 9860dc5ca01171d31ebe25df04e73f43754c30ed Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Sun, 16 Nov 2025 01:19:08 +0100 Subject: [PATCH 11/11] Disable CDC USB on boot for older framework compatibility Changed ARDUINO_USB_CDC_ON_BOOT flag to disable CDC USB due to issues with the older framework. --- platformio.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index ecdb65ce..90dcf48f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -2502,11 +2502,12 @@ upload_speed = 460800 build_unflags = ${env:esp32c3dev_4MB_M.build_unflags} -DWLEDMM_FASTPATH ;; needs more testing on -C3 -D WLED_ENABLE_HUB75MATRIX ;; not enough pins + -DARDUINO_USB_CDC_ON_BOOT=1 ;; hangs on boot build_flags = ${common.build_flags} ${esp32c3.build_flags} -D WLED_WATCHDOG_TIMEOUT=0 -D CONFIG_ASYNC_TCP_USE_WDT=0 ${common_mm.build_flags_S} -Wno-misleading-indentation -Wno-format-truncation -D WLED_RELEASE_NAME=seeed_esp32c3_4MB_S - -DARDUINO_USB_CDC_ON_BOOT=1 ;; enable CDC USB -> needed for debugging over serial USB + -DARDUINO_USB_CDC_ON_BOOT=0 ;; disable CDC USB, as the older framework has problems with it -D WLED_DISABLE_ADALIGHT ;; to disable serial protocols when using CDC USB (Serial RX pin will receive junk commands, unless its pulled down by resistor) -D WLED_DISABLE_INFRARED ;; save flash space ;-D WLED_DISABLE_ALEXA ;; save flash space