Swapping the order of the __WFI() and the __enable_irq() should work.
__WFI();__enable_irq();__ISB();__disable_irq();
Could you use WFE instead of WFI? WFE (Wake for Event) will cause the processor to wake on arrival of an interrupt (if they aren't masked) or an Event. Where an Event can be generated by executing SEV.If you put a SEV instruction into your interrupt handler you'd know that the event register was set, meaning the next WFE instruction would "fail". As long as you have the WFE in a loop (re-checking the sleep condition on waking) this shouldn't be a problem.
__WFI();__enable_irq();__ISB();__disable_irq();Should be sufficient.
__disable_irq();// do something ...__WFI(); __enable_irq();Sounds impossible, but it is the way to do, all other version causes race conditions and are not reliable.
Interesting. Is it guaranteed that pending interrupts are immediately executed as soon as interrupts are enabled, i.e., that after the code sequence__WFI();__enable_irq();__disable_irq();at least one interrupt handler was completed?Thanks & kind regards,Markus