WFI or WFE in place of idle loop

For research purposes, trace, and to learn, I would like to try replacing the idle loop with WFI or WFE instructions.

I usually have:

configUSE_IDLE_HOOK     0

I want to specify that I am not aiming for low consumption.

  • Which of the two between WFI and WFE should I use?
  • Is it required to initialize anything else in order to use these instructions to their best and without problems?

best regards

WFI vs WFE depends on your application. WFI is more common because it waits only for interrupts and not also for events. WFI is also compatible with low-power modes. If you are using events and need to wake up for events (WFE), you would already know that based on your application design.

With configUSE_PREEMPTION set to 1, you should be able to get away without masking interrupts (cpsid) for the WFI. Just execute the WFI anywhere in the idle loop (or even in the idle hook). With this (simple) setup, the configIDLE_SHOULD_YIELD feature won’t work correctly though. A simple workaround is not to have any other tasks at priority 0. Have fun experimenting!

1 Like