Skip to content

refactor(autoresearch): adopt unified watchdog API + move boot diagnostic into platform impl - #2763

Merged
zackees merged 2 commits into
masterfrom
feat/autoresearch-use-unified-watchdog
Jun 5, 2026
Merged

zackees merged 2 commits into
masterfrom
feat/autoresearch-use-unified-watchdog

Conversation

@zackees

@zackees zackees commented Jun 5, 2026 •

Copy link
Copy Markdown
Member

Summary

Two cleanups that together complete the migration of examples/AutoResearch/AutoResearch.ino to the unified fl::Watchdog API + verify the whole stack on real Teensy 4 hardware.

  1. AutoResearch adopts FL_WATCHDOG_AUTO() — one line at the top of loop() replaces the ESP32-only fl::watchdog_setup(15000) prototype call and the explicit FastLED.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).

  2. Boot diagnostic moves from user code into the Teensy 4 watchdog impl. The previous #if defined(FL_IS_TEENSY_4X) block in AutoResearch.ino that decoded SRC_SRSR bit names and dumped the bundled Teensy CrashReport is gone. The same information now prints from mxrt1062PrintBootDiagnosticOnce() inside src/platforms/arm/mxrt1062/watchdog_mxrt1062.impl.hpp, called once per process from Watchdog::begin(). Every Teensy 4 sketch that uses FL_WATCHDOG_AUTO() or FastLED.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:

[SETUP COMPLETE] AutoResearch ready - awaiting JSON-RPC commands
[FastLED.watchdog] SRC_SRSR = 0x1
[FastLED.watchdog]   POR (power-on reset)
[FastLED.watchdog] no CrashReport from previous boot
_build.cpp.hpp(20): WARN: [FastLED.watchdog] armed via FL_WATCHDOG_AUTO()

[GPIO BASELINE TEST] Testing GPIO 1 ??? GPIO 2 connectivity
...
RESULT: {\"type\":\"status\",\"ready\":true,\"uptimeMs\":19176}

Each line proves a different piece:

Line Proves
[FastLED.watchdog] SRC_SRSR = 0x1 mxrt1062PrintBootDiagnosticOnce() ran from Watchdog::begin() — the platform-specific bit decode lives in the API now
POR (power-on reset) Bit-name lookup in the Teensy 4 watchdog impl translated SRC_SRSR_IPP_RESET_B correctly
no CrashReport from previous boot Bundled Teensy CrashReport check is gated on its bool conversion inside the platform impl
[FastLED.watchdog] armed via FL_WATCHDOG_AUTO() scopedWatchdogFirstInit() in src/fl/wdt/_build.cpp.hpp:20 ran — the Tier 1.5 RAII guard is active
uptimeMs: 19176 with WDT timeout = 15 000 Loop has run for >19 s with no WDT reset → FL_WATCHDOG_AUTO()'s ctor + dtor are feeding WDOG3 on every iteration via the bare-register path

The prefix change from [boot] (previous AutoResearch #ifdef block) 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:
    • Removes ESP32-only fl::watchdog_setup(15000) call
    • Removes 30-line #if defined(FL_IS_TEENSY_4X) SRC_SRSR + CrashReport block
    • Removes explicit FastLED.watchdog().begin(15000) + lastResetWasWatchdog() recovery block
    • Adds FL_WATCHDOG_AUTO() at top of loop() and includes fl/wdt/watchdog.h unconditionally
  • src/platforms/arm/mxrt1062/watchdog_mxrt1062.impl.hpp:
    • Adds mxrt1062PrintBootDiagnosticOnce() helper in fl::platforms namespace — SRC_SRSR raw + bit names + Teensy CrashReport
    • Calls it from Watchdog::begin() before any WDT writes
    • SRC_SRSR is write-1-to-clear so the next boot reads only its own cause

References

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Watchdog now initializes automatically via macro in each loop iteration, reducing manual setup code.
    • Boot diagnostics automatically display previous reset causes and crash logs on startup for easier troubleshooting.

zackees and others added 2 commits June 4, 2026 15:50
…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]>
@zackees
zackees merged commit ee3e7bd into master Jun 5, 2026
6 of 7 checks passed
@coderabbitai

coderabbitai Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d169160c-e31c-45fb-b047-e8680dd3e82c

📥 Commits

Reviewing files that changed from the base of the PR and between 08292b5 and 5955faf.

📒 Files selected for processing (2)
  • examples/AutoResearch/AutoResearch.ino
  • src/platforms/arm/mxrt1062/watchdog_mxrt1062.impl.hpp

📝 Walkthrough

Walkthrough

The 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 FL_WATCHDOG_AUTO() for per-loop watchdog feeding.

Changes

Watchdog lazy initialization and boot diagnostics

Layer / File(s) Summary
MXRT1062 boot diagnostic helper and Watchdog::begin integration
src/platforms/arm/mxrt1062/watchdog_mxrt1062.impl.hpp
Adds mxrt1062PrintBootDiagnosticOnce() to read and decode SRC_SRSR reset-source bits, clear the register, and print prior CrashReport to Serial once per boot; updates Watchdog::begin() to call this helper before arming the timer, ensuring reset diagnostics are emitted exactly once during initialization.
AutoResearch sketch lazy watchdog migration
examples/AutoResearch/AutoResearch.ino
Adds unified fl/wdt/watchdog.h header, removes explicit FastLED.watchdog().begin(15000) and prior-boot diagnostic reporting from setup(), inserts FL_WATCHDOG_AUTO() at the start of loop() for automatic per-iteration watchdog feeding via RAII, and updates documentation to indicate automatic boot diagnostic emission and three-second crash pause.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • FastLED/FastLED#2760: Unified watchdog flow using FL_WATCHDOG_AUTO and the Watchdog::begin path that emits SRC_SRSR/CrashReport diagnostic.
  • FastLED/FastLED#2731: Unified cross-platform watchdog design that these changes implement via lazy macro-driven initialization.
  • FastLED/FastLED#2744: Teensy 4 (iMXRT1062) boot-diagnostic and CrashReport support called for in Watchdog Phase 2.

Possibly related PRs

  • FastLED/FastLED#2753: Prior iMXRT1062 bare-register WDOG3 work that reworked SRC_SRSR reset-cause handling and AutoResearch watchdog testing.
  • FastLED/FastLED#2745: Overlaps with mxrt1062 watchdog implementation, including Watchdog::begin() setup path.
  • FastLED/FastLED#2756: New unified reset/crash classification API and ScopedWatchdog auto-feeding that rely on watchdog first-begin diagnostics.

Poem

🐰 The watchdog now sleeps at the start,
Yet wakes with each loop, playing its part,
Boot crashes broadcast their story once more,
Before the timer guards what came before!

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/autoresearch-use-unified-watchdog

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant