fix(cpu): ARMv6-M exception priority model — stop GPIO IRQ self-preemption#53
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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