Skip to content

Commit a28c4f1

Browse files
committed
device/arm: clear pending interrupts before enabling them
Without this change, a pending interrupt would spuriously trigger immediately after enabling. This happens if an interrupt is triggered during flashing (e.g. by DMA), which survives the subsequent reset. This behaviour matches e.g. `machine.irqSet` in machine_rp2_rp2350.go. See 7f970a4, whose symptoms were likely caused by spurious interrupts.
1 parent 120d17c commit a28c4f1

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/device/arm/arm.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,13 @@ const (
148148

149149
// Enable the given interrupt number.
150150
func EnableIRQ(irq uint32) {
151-
NVIC.ISER[irq>>5].Set(1 << (irq & 0x1F))
151+
idx := irq / 32
152+
mask := uint32(0b1) << (irq % 32)
153+
154+
// Clear pending.
155+
NVIC.ICPR[idx].Set(mask)
156+
// Enable.
157+
NVIC.ISER[idx].Set(mask)
152158
}
153159

154160
// Disable the given interrupt number.

0 commit comments

Comments
 (0)