diff --git a/src/main.cpp b/src/main.cpp index 2058167f..8ab62df7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -233,21 +233,6 @@ void setup() { esp_ota_mark_app_valid_cancel_rollback(); } } -#ifdef ENABLE_SERIAL_LOG - // Earliest possible Serial setup. The 250 ms stall before begin() lets the - // USB Serial/JTAG peripheral finish power-on and lets the host complete USB - // enumeration before we touch the CDC state — otherwise cold boot races - // and the host has to be physically replugged for logs to flow. Warm reboot - // worked without the delay because USB was already enumerated. - // - // setTxTimeoutMs(0) makes writes non-blocking — the HWCDC TX FIFO drops - // bytes harmlessly if the host isn't actively draining, instead of blocking - // for the default 250 ms per write and chaining into a firmware hang. - delay(250); - Serial.begin(115200); - logSerial.setTxTimeoutMs(0); -#endif - HalSystem::begin(); gpio.begin(); powerManager.begin(); @@ -264,6 +249,16 @@ void setup() { return; } +#ifdef ENABLE_SERIAL_LOG + if (gpio.isUsbConnected()) { + Serial.begin(115200); + const unsigned long start = millis(); + while (!Serial && (millis() - start) < 500) { + delay(10); + } + } +#endif + LOG_INF("MAIN", "Hardware detect: %s", gpio.deviceIsX3() ? "X3" : "X4"); LOG_DBG("MAIN", "Wakeup reason: %d, millis=%lu, rawPowerPin=%d", static_cast(wakeupReason), millis(), digitalRead(InputManager::POWER_BUTTON_PIN) == LOW);