From d7b5719dfdaee029d6a3f11e768ce681751c3062 Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 21 Dec 2022 22:07:15 +0100 Subject: [PATCH] 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 --- platformio.ini | 10 ++++++++++ wled00/wled.cpp | 5 ++++- wled00/wled.h | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 77b7c38c..dc99a4ee 100644 --- a/platformio.ini +++ b/platformio.ini @@ -214,6 +214,7 @@ build_flags = -g -D CONFIG_ASYNC_TCP_USE_WDT=0 #use LITTLEFS library by lorol in ESP32 core 1.x.x instead of built-in in 2.x.x -D LOROL_LITTLEFS + ; -DARDUINO_USB_CDC_ON_BOOT=0 ;; this flag is mandatory for "classic ESP32" when builing with arduino-esp32 >=2.0.3 default_partitions = tools/WLED_ESP32_4MB_1MB_FS.csv @@ -230,6 +231,9 @@ build_flags = -g -DCONFIG_IDF_TARGET_ESP32S2 -D CONFIG_ASYNC_TCP_USE_WDT=0 -DCO + -DARDUINO_USB_MODE=0 ;; this flag is mandatory for ESP32-S2 ! + ;; 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, ARDUINO_USB_MSC_ON_BOOT, ARDUINO_USB_DFU_ON_BOOT lib_deps = ${env.lib_deps} @@ -243,6 +247,9 @@ build_flags = -g -DCONFIG_IDF_TARGET_ESP32C3 -D CONFIG_ASYNC_TCP_USE_WDT=0 -DCO + -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 lib_deps = ${env.lib_deps} @@ -258,6 +265,8 @@ build_flags = -g -DCONFIG_IDF_TARGET_ESP32S3 -D CONFIG_ASYNC_TCP_USE_WDT=0 -DCO + ;; 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_MODE, ARDUINO_USB_CDC_ON_BOOT, ARDUINO_USB_MSC_ON_BOOT, ARDUINO_USB_DFU_ON_BOOT lib_deps = ${env.lib_deps} @@ -387,6 +396,7 @@ board = esp32-c3-devkitm-1 board_build.partitions = tools/WLED_ESP32_4MB_1MB_FS.csv build_flags = ${common.build_flags} ${esp32c3.build_flags} #-D WLED_RELEASE_NAME=ESP32-C3 -D WLED_WATCHDOG_TIMEOUT=0 + ; -DARDUINO_USB_CDC_ON_BOOT=1 ;; for virtual USB upload_speed = 460800 build_unflags = ${common.build_unflags} lib_deps = ${esp32c3.lib_deps} diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 87df1be0..e41176f4 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -268,7 +268,10 @@ void WLED::setup() #endif Serial.begin(115200); - Serial.setTimeout(50); + #if !ARDUINO_USB_CDC_ON_BOOT + Serial.setTimeout(50); // this causes troubles on new MCUs that have a "virtual" USB Serial (HWCDC) + #else + #endif #if defined(WLED_DEBUG) && defined(ARDUINO_ARCH_ESP32) && (defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || ARDUINO_USB_CDC_ON_BOOT) delay(2500); // allow CDC USB serial to initialise #endif diff --git a/wled00/wled.h b/wled00/wled.h index 27a4ef26..2ba99d22 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -71,6 +71,7 @@ #include } #else // ESP32 + #include // ensure we have the correct "Serial" on new MCUs (depends on ARDUINO_USB_MODE and ARDUINO_USB_CDC_ON_BOOT) #include #include #include "esp_wifi.h"