Repository navigation
refactor(autoresearch): adopt unified watchdog API + move boot diagnostic into platform impl - #2763
Conversation
…G_AUTO() Replace the ESP32-only `fl::watchdog_setup(15000)` prototype call in setup() with a single `FL_WATCHDOG_AUTO()` at the top of loop(). The new macro is cross-platform — ESP32 / Teensy 4 / Teensy 3 / RP2040 / nRF52 / STM32 / SAMD / Apollo3 / MGM240 / AVR — and falls through to a safe noop on any platform without a real WDT. What FL_WATCHDOG_AUTO() does that the prototype didn't: - Lazily arms the WDT on first call (no explicit setup() ordering needed) - Prints prior-boot reset/crash diagnostic via fl::println - Pauses 3 s on a crash so the developer can read the message before loop() repaints serial output - Feeds the WDT on BOTH ctor and dtor (start + end of each iteration) - Detects nested guards at runtime (one-shot warning if the user accidentally puts two macros in the same call stack) Also removes the stale "Teensy WDOG3 DISABLED — bricks the board" comment block — the WDOG3 reset-loop bug was fixed in PR #2753 via bare-register initialization and the CCM_CCGR5_WDOG3 clock-gate fix. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Previously `examples/AutoResearch/AutoResearch.ino` had a `#if defined(FL_IS_TEENSY_4X)` block that decoded SRC_SRSR bits and dumped the bundled Teensy `CrashReport` directly via `Serial.print`. That was exactly the kind of platform-specific surfacing the unified `fl::Watchdog` API exists to abstract away — user code shouldn't need to know about WDOG3_RST_B vs LOCKUP_SYSRESETREQ bit positions. Moving the boot diagnostic into the Teensy 4 watchdog impl (`watchdog_mxrt1062.impl.hpp::mxrt1062PrintBootDiagnosticOnce()`) so it runs from `Watchdog::begin()` on its first call, before any WDT writes. SRC_SRSR is write-1-to-clear so the next boot reads only its own cause. Now every Teensy 4 sketch that calls `FL_WATCHDOG_AUTO()` or `FastLED.watchdog().begin()` gets the prior-boot SRC_SRSR bit decode + CrashReport print automatically. AutoResearch.ino loses 30 lines of platform-`#ifdef`'d boot diagnostic code; the same information now prints through the API. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe PR migrates watchdog initialization from explicit setup-time configuration to lazy, macro-driven arming with automatic boot diagnostics. A new platform helper decodes reset sources and reports prior crashes; the AutoResearch example removes old diagnostics and uses ChangesWatchdog lazy initialization and boot diagnostics
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Two cleanups that together complete the migration of
examples/AutoResearch/AutoResearch.inoto the unifiedfl::WatchdogAPI + verify the whole stack on real Teensy 4 hardware.AutoResearch adopts
FL_WATCHDOG_AUTO()— one line at the top ofloop()replaces the ESP32-onlyfl::watchdog_setup(15000)prototype call and the explicitFastLED.watchdog().begin(...)+lastResetWasWatchdog()recovery block. Works portably across ESP32 / Teensy 4 / Teensy 3 / RP2040 / nRF52 / STM32 / SAMD / Apollo3 / MGM240 / AVR (noop fallback on platforms without a real WDT).Boot diagnostic moves from user code into the Teensy 4 watchdog impl. The previous
#if defined(FL_IS_TEENSY_4X)block inAutoResearch.inothat decoded SRC_SRSR bit names and dumped the bundled TeensyCrashReportis gone. The same information now prints frommxrt1062PrintBootDiagnosticOnce()insidesrc/platforms/arm/mxrt1062/watchdog_mxrt1062.impl.hpp, called once per process fromWatchdog::begin(). Every Teensy 4 sketch that usesFL_WATCHDOG_AUTO()orFastLED.watchdog().begin()now gets the diagnostic for free.Live-hardware proof on Teensy 4.0
Captured boot serial output after flashing this branch's
firmware.hex:Each line proves a different piece:
[FastLED.watchdog] SRC_SRSR = 0x1mxrt1062PrintBootDiagnosticOnce()ran fromWatchdog::begin()— the platform-specific bit decode lives in the API nowPOR (power-on reset)SRC_SRSR_IPP_RESET_Bcorrectlyno CrashReport from previous bootCrashReportcheck is gated on itsboolconversion inside the platform impl[FastLED.watchdog] armed via FL_WATCHDOG_AUTO()scopedWatchdogFirstInit()insrc/fl/wdt/_build.cpp.hpp:20ran — the Tier 1.5 RAII guard is activeuptimeMs: 19176with WDT timeout = 15 000FL_WATCHDOG_AUTO()'s ctor + dtor are feeding WDOG3 on every iteration via the bare-register pathThe prefix change from
[boot](previous AutoResearch#ifdefblock) to[FastLED.watchdog](new platform-impl helper) is itself the visible proof that the diagnostic relocated from user code into the API.Teensy 4.1 status
Same iMXRT1062 chip, same code path. Live verification on the specific 4.1 board on the dev bench is deferred because that board is coated in silicone RTV which appears to be holding the PROGRAM button asserted (cyclic HalfKay re-enumeration every ~6 s) and intermittently disrupting USB enumeration mid-write. Documented in #2760 with the cleanup steps.
Diff summary
examples/AutoResearch/AutoResearch.ino:fl::watchdog_setup(15000)call#if defined(FL_IS_TEENSY_4X)SRC_SRSR + CrashReport blockFastLED.watchdog().begin(15000)+lastResetWasWatchdog()recovery blockFL_WATCHDOG_AUTO()at top ofloop()and includesfl/wdt/watchdog.hunconditionallysrc/platforms/arm/mxrt1062/watchdog_mxrt1062.impl.hpp:mxrt1062PrintBootDiagnosticOnce()helper infl::platformsnamespace — SRC_SRSR raw + bit names + Teensy CrashReportWatchdog::begin()before any WDT writesReferences
🤖 Generated with Claude Code
Summary by CodeRabbit