Skip to content

Commit d7b5719

Browse files
committed
add mandatory build flags for -S2 and -C3 (virtual USB)
I was wondering why sometimes the new MCUs still work better in Arduino IDE, so compared our build flags to what is used in Arduino IDE: -S2 always has -DARDUINO_USB_MODE=0 -C3 always has -DARDUINO_USB_MODE=1 -S3 supports all possible modes
1 parent 284a999 commit d7b5719

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

platformio.ini

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ build_flags = -g
214214
-D CONFIG_ASYNC_TCP_USE_WDT=0
215215
#use LITTLEFS library by lorol in ESP32 core 1.x.x instead of built-in in 2.x.x
216216
-D LOROL_LITTLEFS
217+
; -DARDUINO_USB_CDC_ON_BOOT=0 ;; this flag is mandatory for "classic ESP32" when builing with arduino-esp32 >=2.0.3
217218

218219
default_partitions = tools/WLED_ESP32_4MB_1MB_FS.csv
219220

@@ -230,6 +231,9 @@ build_flags = -g
230231
-DCONFIG_IDF_TARGET_ESP32S2
231232
-D CONFIG_ASYNC_TCP_USE_WDT=0
232233
-DCO
234+
-DARDUINO_USB_MODE=0 ;; this flag is mandatory for ESP32-S2 !
235+
;; 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:
236+
;; ARDUINO_USB_CDC_ON_BOOT, ARDUINO_USB_MSC_ON_BOOT, ARDUINO_USB_DFU_ON_BOOT
233237

234238
lib_deps =
235239
${env.lib_deps}
@@ -243,6 +247,9 @@ build_flags = -g
243247
-DCONFIG_IDF_TARGET_ESP32C3
244248
-D CONFIG_ASYNC_TCP_USE_WDT=0
245249
-DCO
250+
-DARDUINO_USB_MODE=1 ;; this flag is mandatory for ESP32-C3
251+
;; 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:
252+
;; ARDUINO_USB_CDC_ON_BOOT
246253

247254
lib_deps =
248255
${env.lib_deps}
@@ -258,6 +265,8 @@ build_flags = -g
258265
-DCONFIG_IDF_TARGET_ESP32S3
259266
-D CONFIG_ASYNC_TCP_USE_WDT=0
260267
-DCO
268+
;; 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:
269+
;; ARDUINO_USB_MODE, ARDUINO_USB_CDC_ON_BOOT, ARDUINO_USB_MSC_ON_BOOT, ARDUINO_USB_DFU_ON_BOOT
261270

262271
lib_deps =
263272
${env.lib_deps}
@@ -387,6 +396,7 @@ board = esp32-c3-devkitm-1
387396
board_build.partitions = tools/WLED_ESP32_4MB_1MB_FS.csv
388397
build_flags = ${common.build_flags} ${esp32c3.build_flags} #-D WLED_RELEASE_NAME=ESP32-C3
389398
-D WLED_WATCHDOG_TIMEOUT=0
399+
; -DARDUINO_USB_CDC_ON_BOOT=1 ;; for virtual USB
390400
upload_speed = 460800
391401
build_unflags = ${common.build_unflags}
392402
lib_deps = ${esp32c3.lib_deps}

wled00/wled.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,10 @@ void WLED::setup()
268268
#endif
269269

270270
Serial.begin(115200);
271-
Serial.setTimeout(50);
271+
#if !ARDUINO_USB_CDC_ON_BOOT
272+
Serial.setTimeout(50); // this causes troubles on new MCUs that have a "virtual" USB Serial (HWCDC)
273+
#else
274+
#endif
272275
#if defined(WLED_DEBUG) && defined(ARDUINO_ARCH_ESP32) && (defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || ARDUINO_USB_CDC_ON_BOOT)
273276
delay(2500); // allow CDC USB serial to initialise
274277
#endif

wled00/wled.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
#include <user_interface.h>
7272
}
7373
#else // ESP32
74+
#include <HardwareSerial.h> // ensure we have the correct "Serial" on new MCUs (depends on ARDUINO_USB_MODE and ARDUINO_USB_CDC_ON_BOOT)
7475
#include <WiFi.h>
7576
#include <ETH.h>
7677
#include "esp_wifi.h"

0 commit comments

Comments
 (0)