Sleep mode is entered by default every time that the WFI or WFE instructions are invoked, as long as SCB_SCR_SLEEPDEEP remains off. Other low-power modes can be enabled by enabling the SLEEPDEEP flag. To enter one of the available deep-sleep modes, the SCB_SCR and the POW registers must be configured before calling WFI or WFE. Depending on the configuration, the system enters one of the two deep-sleep modes, stop or standby.
In the following example, a continuous 1 Hz timer is toggling the LED 10 times before switching to deep-sleep mode, using WFE. The main loop stays in sleep mode in between timer interrupts, using WFI:
void main(void) { int sleep = 0; pll_on(0); button_setup(); led_setup(); timer_init(CPU_FREQ, 1, 1000); while(1) ...