From 8cbd72bdaecda65a4495f7f58a2b31c5cfb714e8 Mon Sep 17 00:00:00 2001 From: Arthur Tazhitdinov Date: Wed, 21 Jan 2026 17:35:23 +0500 Subject: [PATCH] fix: hard reset via RTS pin after flashing firmware (#437) ## Summary * Disables going to sleep after uploading new firmware * Makes developer experience easier --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? _**< NO >**_ --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/main.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 3075757b..301d2180 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -276,13 +276,30 @@ void setupDisplayAndFonts() { Serial.printf("[%lu] [ ] Fonts setup\n", millis()); } +bool isUsbConnected() { + // U0RXD/GPIO20 reads HIGH when USB is connected + return digitalRead(UART0_RXD) == HIGH; +} + +bool isWakeupAfterFlashing() { + const auto wakeupCause = esp_sleep_get_wakeup_cause(); + const auto resetReason = esp_reset_reason(); + + return isUsbConnected() && (wakeupCause == ESP_SLEEP_WAKEUP_UNDEFINED) && (resetReason == ESP_RST_UNKNOWN); +} + void setup() { t1 = millis(); // Only start serial if USB connected pinMode(UART0_RXD, INPUT); - if (digitalRead(UART0_RXD) == HIGH) { + if (isUsbConnected()) { Serial.begin(115200); + // Wait up to 3 seconds for Serial to be ready to catch early logs + unsigned long start = millis(); + while (!Serial && (millis() - start) < 3000) { + delay(10); + } } inputManager.begin(); @@ -305,8 +322,10 @@ void setup() { SETTINGS.loadFromFile(); KOREADER_STORE.loadFromFile(); - // verify power button press duration after we've read settings. - verifyWakeupLongPress(); + if (!isWakeupAfterFlashing()) { + // For normal wakeups (not immediately after flashing), verify long press + verifyWakeupLongPress(); + } // First serial output only here to avoid timing inconsistencies for power button press duration verification Serial.printf("[%lu] [ ] Starting CrossPoint version " CROSSPOINT_VERSION "\n", millis());