@@ -452,24 +452,32 @@ void WLED::setup()
452452 delay (WLED_BOOTUPDELAY); // delay to let voltage stabilize, helps with boot issues on some setups
453453 #endif
454454 Serial.begin (115200 );
455+
456+ #if !defined(WLEDMM_NO_SERIAL_WAIT) || defined(WLED_DEBUG)
455457 if (!Serial) delay (1000 ); // WLEDMM make sure that Serial has initalized
458+ #else
459+ if (!Serial) delay (300 ); // just a tiny wait to avoid problems later when acessing serial
460+ #endif
456461
457462 #ifdef ARDUINO_ARCH_ESP32
458463 #if defined(WLED_DEBUG) && (defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32C3) || ARDUINO_USB_CDC_ON_BOOT)
459- if (!Serial) delay (2500 ); // WLEDMM allow CDC USB serial to initialise
464+ if (!Serial) delay (2500 ); // WLEDMM allow CDC USB serial to initialise (WLED_DEBUG only)
460465 #endif
461466 #if ARDUINO_USB_CDC_ON_BOOT || ARDUINO_USB_MODE
462467 #if ARDUINO_USB_CDC_ON_BOOT && (defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32C6))
463468 // WLEDMM avoid "hung devices" when USB_CDC is enabled; see https://github.com/espressif/arduino-esp32/issues/9043
464469 Serial.setTxTimeoutMs (0 ); // potential side-effect: incomplete debug output, with missing characters whenever TX buffer is full.
465470 #endif
471+ #if !defined(WLEDMM_NO_SERIAL_WAIT) || defined(WLED_DEBUG)
466472 if (!Serial) delay (2500 ); // WLEDMM: always allow CDC USB serial to initialise
467473 if (Serial) Serial.println (" wait 1" ); // waiting a bit longer ensures that a debug messages are shown in serial monitor
468474 if (!Serial) delay (2500 );
469475 if (Serial) Serial.println (" wait 2" );
470476 if (!Serial) delay (2500 );
471477
472478 if (Serial) Serial.flush (); // WLEDMM
479+ #endif
480+
473481 // Serial.setTimeout(350); // WLEDMM: don't change timeout, as it causes crashes later
474482 // WLEDMM: redirect debug output to HWCDC
475483 #if ARDUINO_USB_CDC_ON_BOOT && (defined(WLED_DEBUG) || defined(SR_DEBUG))
@@ -521,6 +529,7 @@ void WLED::setup()
521529 USER_PRINT (F (" , " )); USER_PRINT (ESP.getCpuFreqMHz ()); USER_PRINTLN (F (" MHz." ));
522530
523531 // WLEDMM begin
532+ delay (20 ); USER_FLUSH (); // drain serial output buffers
524533 USER_PRINT (F (" CPU " ));
525534 esp_reset_reason_t resetReason = getRestartReason ();
526535 USER_PRINT (restartCode2InfoLong (resetReason));
0 commit comments