Skip to content

Detect mid-region power failures via NVM in-region flag - #59

Merged
byeongjee merged 1 commit into
mainfrom
byeongjee/mid-region-power-failure
Aug 10, 2026
Merged

Detect mid-region power failures via NVM in-region flag#59
byeongjee merged 1 commit into
mainfrom
byeongjee/mid-region-power-failure

Conversation

@byeongjee

Copy link
Copy Markdown
Owner

Summary

All three algorithms (MILP, RockClimb, SCHEMATIC) assume power never fails mid-region. This PR detects violations of that assumption (e.g. from wrong energy estimates), always on — including non-debug builds.

Firmware

  • New FRAM words __nvm_in_region / __nvm_violation in each runtime.
  • save_pc_sp_and_halt clears __nvm_in_region once the boundary checkpoint is committed; boot code (and the wait-mode continue path) sets it when execution (re)enters a region. Cost: two 1-word FRAM writes per region.
  • New check_region_violation boot macro: a reset arriving with the flag set records __nvm_violation = 1 and parks forever blinking LED1 (P1.0). The park is stable across further resets, so evidence survives until the next reflash.
  • bench_halt() / debug_exit() clear the flag at completion so post-run mspdebug attach resets cannot false-positive.

Python

  • New RegionViolationError; check_region_violation() / raise_if_region_violation() in device/flash.py.
  • ckpt bench reads the flag after every device run — including when the Saleae capture times out, which is exactly what a parked device causes — and writes the CSV row with status region_violation.
  • ckpt verify reports a violation as Status.ERROR with a "region energy violation" detail on both the normal readback and the capture-timeout path.

Testing

  • All 54 boot.S variants (3 algos x 3 halt modes x debug on/off x 3 CPU freqs) and runtime C files compile; all linker combinations resolve.
  • Disassembly confirms commit-point ordering: flag cleared after __nvm_pc/__nvm_sp are written, set again on region re-entry.
  • ruff format/ruff check clean; 139 unit-marked pytest tests pass.
  • Not yet exercised on hardware.

@byeongjee
byeongjee merged commit 5ed3dfc into main Aug 10, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant