Skip to content

fix(cpu): ARMv6-M exception priority model — stop GPIO IRQ self-preemption#53

Merged
begeistert merged 1 commit into
masterfrom
fix/armv6m-exception-priority
Jul 12, 2026
Merged

fix(cpu): ARMv6-M exception priority model — stop GPIO IRQ self-preemption#53
begeistert merged 1 commit into
masterfrom
fix/armv6m-exception-priority

Conversation

@begeistert

Copy link
Copy Markdown
Collaborator

Corrects the ARMv6-M exception priority/preemption model in the Cortex-M0+ core (CortexM0Plus, SystemOps, PpbPeripheral) so a GPIO IRQ no longer self-preempts. Adds MicroPythonGpioIrqTests.

Verified: unit 516/0, new GPIO IRQ integration test 2/0. Ships as 1.0.1-beta.11.

🤖 Generated with Claude Code

…ption

CheckForInterrupts took any pending+enabled exception with no notion of
execution priority. A level-held IRQ like IO_IRQ_BANK0 (re-asserted by
IoBank0 until the handler acks INTR) therefore re-preempted its own
handler after every instruction; the stack unwound into RAM and the core
died in a HardFault lockup loop the moment a MicroPython Pin.irq handler
saw its first edge.

Implement the ARMv6-M (B1.5.4) model:

- NVIC IPR levels live in four per-level bitmask buckets, rebuilt on IPR
  writes (2-bit priorities in bits 7:6 of each byte); reset puts every
  IRQ at level 0.
- Execution priority derives from IPSR (NMI=-2, HardFault=-1, SVCall/
  PendSV/SysTick from SHPR2/3, IRQs from their bucket); PRIMASK boosts
  it to 0. SHPR2/3 writes are masked to their implemented bits.
- A pending exception preempts only when strictly more urgent; ties
  resolve to the lowest exception number, matching NVIC arbitration.
- MSR PRIMASK re-arms the interrupt check so unmasking takes effect
  immediately.

Regression-tested with MicroPython v1.21: Pin.irq callbacks now count
externally forced edges and a 50-edge burst leaves the REPL responsive.

Claude-Session: https://claude.ai/code/session_01LzMZxpFZefZTzGPCfg2AHq
@begeistert begeistert requested a review from lmSeryi as a code owner July 12, 2026 07:58
@begeistert begeistert merged commit 6dbc7f6 into master Jul 12, 2026
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