Skip to content

Commit 2e959f3

Browse files
committed
fix(rp2040): WFI doesn't wake up when interrupts disabled
according to the ARM ARM, we should wake even if PM=1, as long as the exception has higher priority than the currently executing handler: > If PRIMASK.PM is set to 1, an asynchronous exception that has a higher group priority than any active exception results in a WFI instruction exit. If the group priority of the exception is less than or equal to the execution group priority, the exception is ignored. see adafruit/circuitpython#5331
1 parent 3b08178 commit 2e959f3

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/rp2040.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -668,10 +668,16 @@ export class RP2040 {
668668
}
669669

670670
checkForInterrupts() {
671-
const currentPriority = Math.min(
672-
this.exceptionPriority(this.IPSR),
673-
this.PM ? 0 : LOWEST_PRIORITY
674-
);
671+
/* If we're waiting for an interrupt (i.e. WFI/WFE), the ARM says:
672+
> If PRIMASK.PM is set to 1, an asynchronous exception that has a higher group priority than any
673+
> active exception results in a WFI instruction exit. If the group priority of the exception is less than or
674+
> equal to the execution group priority, the exception is ignored.
675+
*/
676+
const currentPriority = this.waiting
677+
? this.PM
678+
? this.exceptionPriority(this.IPSR)
679+
: LOWEST_PRIORITY
680+
: Math.min(this.exceptionPriority(this.IPSR), this.PM ? 0 : LOWEST_PRIORITY);
675681
const interruptSet = this.pendingInterrupts & this.enabledInterrupts;
676682
const { svCallPriority, systickPriority } = this;
677683
for (let priority = 0; priority < currentPriority; priority++) {

0 commit comments

Comments
 (0)