Repository navigation
fix(watchdog/apollo3): drop non-existent RSTGEN::CLRSTAT + correct STAT bits (Closes #2787) - #2788
Conversation
…AT bits
`platforms/apollo3/watchdog_apollo3.impl.hpp` had two bugs against the
SparkFun Arduino_Apollo3 v2.2.1 CMSIS layout of `RSTGEN_Type`:
1. **Compile error** — `RSTGEN->CLRSTAT = 1u;` at line 96 referenced a
register member that does not exist. `RSTGEN_Type` contains
`CFG`/`SWPOI`/`SWPOR`/`TPIURST`/`INTEN`/`INTSTAT`/`INTCLR`/`INTSET`
(last group is the BODH interrupt only) and `STAT`. No clear register
exists for `STAT`; every `STAT` bit is documented as `(SBL)`, meaning
the Secondary Boot Loader latches it at boot and software cannot clear
it. This broke `bash compile apollo3_red` /
`bash compile apollo3_thing_explorable` and the matching GitHub
Actions workflows.
2. **Runtime bug (latent)** — the `STAT` bit-position table in the
comment and the `if/else` chain were off by one for the upper bits:
| Bit | Code said | Hardware actually says (`STAT_b`) |
|---|---|---|
| 6 | `POISTAT` POR-init | `WDRSTAT` watchdog |
| 7 | `WDRSTAT` watchdog | `BOUSTAT` unregulated brown-out |
`if (stat & (1u << 7)) cause = WATCHDOG` was reading the
unregulated-brownout bit, and `else if (stat & (1u << 6))
cause = POWER_ON` was reading the watchdog bit. Had this ever
compiled, `lastResetWasWatchdog()` would never report true after a
real watchdog reset and would falsely report it after an unregulated
brown-out. The CLRSTAT compile failure inadvertently protected
callers from shipping this.
Fix:
- Remove the impossible `RSTGEN->CLRSTAT = 1u;` write. Re-read
protection is already provided by the `cause_cached` flag in
`Apollo3WatchdogState`.
- Re-derive the bit positions from `RSTGEN_Type::STAT_b` in
`apollo3.h` and update both the comment table and the conditions.
- Map the additional Apollo3 brown-out variants (`BOUSTAT`/`BOCSTAT`/
`BOFSTAT`/`BOBSTAT`, bits 7/8/9/10) to `ResetCause::BROWNOUT`
alongside the general `BORSTAT` (bit 2), so every flavor of
brown-out reports consistently.
Local verification was blocked by a separate Windows-only fbuild
toolchain cache issue (arm-none-eabi-gcc 9.2.1 cache for the SparkFun
Apollo3 build missing `as.exe`); the failure fires inside the
Arduino_Apollo3 core before any FastLED translation unit is compiled,
and other arm-none-eabi-gcc boards in the same workspace compile
cleanly. PR CI on apollo3_red / apollo3_thing_explorable provides
authoritative verification of the fix.
Closes #2787
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe reset-cause detection in Apollo3's ChangesApollo3 Watchdog Reset-Cause Correction
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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
Fixes both Apollo3 workflows (`build_apollo3_red.yml` and `build_apollo3_thing_explorable.yml`) that were red on master with:
```
src/platforms/apollo3/watchdog_apollo3.impl.hpp:96:17: error:
'struct RSTGEN_Type' has no member named 'CLRSTAT'
```
Closes #2787. Continues the README badge sweep started in #2779 / #2780 (AVR) / #2785 (STM32 GIGA).
What's broken
Two bugs in `src/platforms/apollo3/watchdog_apollo3.impl.hpp` against the SparkFun Arduino_Apollo3 v2.2.1 CMSIS layout of `RSTGEN_Type` (defined in `apollo3.h`):
Compile error — line 96 wrote `RSTGEN->CLRSTAT = 1u;`, but `RSTGEN_Type` has no `CLRSTAT` member. The struct contains `CFG`, `SWPOI`, `SWPOR`, `TPIURST`, `INTEN`/`INTSTAT`/`INTCLR`/`INTSET` (BODH brown-out interrupt only), and `STAT` — and there is no clear register for `STAT`. Every `STAT_b` field is `(SBL)`-tagged: the Secondary Boot Loader latches it at boot and software cannot clear it.
Runtime bug (latent) — the bit-position table in the comment and the `if/else` chain had bits 6 and 7 wrong:
So `if (stat & (1u << 7)) cause = WATCHDOG` was actually reading the unregulated-brownout bit, and `else if (stat & (1u << 6)) cause = POWER_ON` was reading the watchdog bit. Had this ever compiled, `lastResetWasWatchdog()` would never have returned true after a real watchdog reset, and would have falsely reported watchdog after an unregulated brown-out. The CLRSTAT compile failure inadvertently protected callers from shipping broken behavior.
What this PR changes
`src/platforms/apollo3/watchdog_apollo3.impl.hpp`:
Test plan
Local verification with `bash compile` was blocked by a separate Windows-only fbuild toolchain cache issue (arm-none-eabi-gcc 9.2.1 cache for the SparkFun Apollo3 build missing `as.exe`). The failure fires inside the Arduino_Apollo3 core's `itoa.c` before any FastLED translation unit is compiled, and other arm-none-eabi-gcc boards in the same workspace (`stm32f103c8`, `nucleo_f429zi`, etc.) compile cleanly — i.e. unrelated to this change.
This PR's CI on apollo3_red / apollo3_thing_explorable is the authoritative verification. The compile error being fixed is unambiguous (`RSTGEN_Type` has no `CLRSTAT` member), and this PR removes the exact line that produced it; the bit-position corrections are verified by inspection against the CMSIS header.
`bash lint` clean.
Scope
🤖 Generated with Claude Code
Summary by CodeRabbit