From 4de8d153038ed1e19ee8800eb530c3b108615b2b Mon Sep 17 00:00:00 2001 From: Piotr Esden-Tempski Date: Fri, 13 Feb 2015 01:34:49 -0800 Subject: [PATCH] [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. --- examples/stm32/f4/stm32f4-discovery/timer/timer.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/examples/stm32/f4/stm32f4-discovery/timer/timer.c b/examples/stm32/f4/stm32f4-discovery/timer/timer.c index f67262d..bf0e736 100644 --- a/examples/stm32/f4/stm32f4-discovery/timer/timer.c +++ b/examples/stm32/f4/stm32f4-discovery/timer/timer.c @@ -24,6 +24,8 @@ #include #include +#include + uint16_t frequency_sequence[18] = { 1000, 500, @@ -183,8 +185,16 @@ int main(void) gpio_setup(); tim_setup(); + /* Loop calling Wait For Interrupt. In older pre cortex ARM this is + * just equivalent to nop. On cortex it puts the cpu to sleep until + * one of the three occurs: + * + * a non-masked interrupt occurs and is taken + * an interrupt masked by PRIMASK becomes pending + * a Debug Entry request + */ while (1) - __asm("nop"); + __WFI(); /* Wait For Interrupt. */ return 0; }