Skip to content

Commit

Permalink
S3: don't wait for serial to initialize
Browse files Browse the repository at this point in the history
... allows to start effects a bit aerlier. Enabled by default on -S3. for your own builds, add `-DWLEDMM_NO_SERIAL_WAIT` to build_flags.
  • Loading branch information
softhack007 committed Jan 10, 2025
1 parent 8317c89 commit c144c77
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ build_flags = -g
-DARDUINO_ARCH_ESP32S3
-DCONFIG_IDF_TARGET_ESP32S3=1
-DCONFIG_LITTLEFS_FOR_IDF_3_2 -DLFS_THREADSAFE ;; WLEDMM
-DWLEDMM_NO_SERIAL_WAIT ;; WLEDMM don't wait for serial on -S3 (unless WLED_DEBUG is set)
-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
-DARDUINO_USB_MSC_ON_BOOT=0 -DARDUINO_DFU_ON_BOOT=0
Expand Down
11 changes: 10 additions & 1 deletion wled00/wled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,24 +452,32 @@ void WLED::setup()
delay(WLED_BOOTUPDELAY); // delay to let voltage stabilize, helps with boot issues on some setups
#endif
Serial.begin(115200);

#if !defined(WLEDMM_NO_SERIAL_WAIT) || defined(WLED_DEBUG)
if (!Serial) delay(1000); // WLEDMM make sure that Serial has initalized
#else
if (!Serial) delay(300); // just a tiny wait to avoid problems later when acessing serial
#endif

#ifdef ARDUINO_ARCH_ESP32
#if defined(WLED_DEBUG) && (defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || ARDUINO_USB_CDC_ON_BOOT)
if (!Serial) delay(2500); // WLEDMM allow CDC USB serial to initialise
if (!Serial) delay(2500); // WLEDMM allow CDC USB serial to initialise (WLED_DEBUG only)
#endif
#if ARDUINO_USB_CDC_ON_BOOT || ARDUINO_USB_MODE
#if ARDUINO_USB_CDC_ON_BOOT && (defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6))
// WLEDMM avoid "hung devices" when USB_CDC is enabled; see https://github.com/espressif/arduino-esp32/issues/9043
Serial.setTxTimeoutMs(0); // potential side-effect: incomplete debug output, with missing characters whenever TX buffer is full.
#endif
#if !defined(WLEDMM_NO_SERIAL_WAIT) || defined(WLED_DEBUG)
if (!Serial) delay(2500); // WLEDMM: always allow CDC USB serial to initialise
if (Serial) Serial.println("wait 1"); // waiting a bit longer ensures that a debug messages are shown in serial monitor
if (!Serial) delay(2500);
if (Serial) Serial.println("wait 2");
if (!Serial) delay(2500);

if (Serial) Serial.flush(); // WLEDMM
#endif

//Serial.setTimeout(350); // WLEDMM: don't change timeout, as it causes crashes later
// WLEDMM: redirect debug output to HWCDC
#if ARDUINO_USB_CDC_ON_BOOT && (defined(WLED_DEBUG) || defined(SR_DEBUG))
Expand Down Expand Up @@ -521,6 +529,7 @@ void WLED::setup()
USER_PRINT(F(", ")); USER_PRINT(ESP.getCpuFreqMHz()); USER_PRINTLN(F("MHz."));

// WLEDMM begin
delay(20); USER_FLUSH(); // drain serial output buffers
USER_PRINT(F("CPU "));
esp_reset_reason_t resetReason = getRestartReason();
USER_PRINT(restartCode2InfoLong(resetReason));
Expand Down

0 comments on commit c144c77

Please sign in to comment.