USB serial logs now flow on cold+warm boot without jiggle (#2034)

This commit is contained in:
jpirnay
2026-05-19 13:09:22 +02:00
parent 85d2a105b2
commit c539c11a74
+15 -10
View File
@@ -233,6 +233,21 @@ 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();
@@ -249,16 +264,6 @@ 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<int>(wakeupReason), millis(),
digitalRead(InputManager::POWER_BUTTON_PIN) == LOW);