Skip to content

Commit 4de8d15

Browse files
committed
[stm32f4-discovery] Using WFI instead of nop in the main loop.
WFI (Wait for Interrupt) tells the processor to suspend untill the next interrupt is called. Better than burning away the cycles with nop.
1 parent ec7c0f3 commit 4de8d15

File tree

1 file changed

+11
-1
lines changed
  • examples/stm32/f4/stm32f4-discovery/timer

1 file changed

+11
-1
lines changed

examples/stm32/f4/stm32f4-discovery/timer/timer.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include <libopencm3/cm3/nvic.h>
2525
#include <libopencm3/stm32/exti.h>
2626

27+
#include <libopencmsis/core_cm3.h>
28+
2729
uint16_t frequency_sequence[18] = {
2830
1000,
2931
500,
@@ -183,8 +185,16 @@ int main(void)
183185
gpio_setup();
184186
tim_setup();
185187

188+
/* Loop calling Wait For Interrupt. In older pre cortex ARM this is
189+
* just equivalent to nop. On cortex it puts the cpu to sleep until
190+
* one of the three occurs:
191+
*
192+
* a non-masked interrupt occurs and is taken
193+
* an interrupt masked by PRIMASK becomes pending
194+
* a Debug Entry request
195+
*/
186196
while (1)
187-
__asm("nop");
197+
__WFI(); /* Wait For Interrupt. */
188198

189199
return 0;
190200
}

0 commit comments

Comments
 (0)