This is an old revision of the document!


SLEEP Mode

In SLEEP mode only the cpu clock is disabled, everything else stays as previously configured.

Enter SLEEP mode

  • WFI (wait for interrupt) instuction enters SLEEP mode.


Exit SLEEP mode

  • Clear the EXTI (and, if not EXTI, the corresponding NVIC) pending bit.


The code snippet bellow shows how to enter (and exit) SLEEP mode.

#include "reg_stm32f4xx.h"
 
RCC->AHBENR[0] |= (0x1 <<  0u);       /* Enable GPIOA clock */
RCC->APBENR[1] |= (0x1 << 14u);       /* Enable SYSCFG clock */
 
/* Configure wake up pin (PA.0). */
GPIOA->MODER &= ~(0x3 << 0u);         /* Clear existing mode bits 10 and 11. */
 
GPIOA->PUPDR &= ~(0x3 << 0u);         /* Clear existing pull-up/-down bits 0 and 1. */
GPIOA->PUPDR |= (0x1 << 0u);          /* Set pin 0 to pull-up mode. */
 
/* Configure interrupt. */
SYSCFG->EXTICR[0] |= (0u << 0u);      /* Set EXTI0 to GPIOA. */
EXTI->RTSR |= (0x1 << 0u);            /* Trigger on rising edge. */
EXTI->IMR |= (0x1 << 0u);             /* Unmask interrupt line. */
NVIC->ISER[0] |= (0x1 << 6u);         /* Enable EXTI0 interrupt. */
 
/* Disable SLEEPDEEP (STOP or STANDBY mode). */
SCB->SCR &= ~(0x1 << 2u);
 
/* -------------------- Enter sleep mode -------------------- */
 
__asm volatile ("wfi");
 
 
/* -------------------- Enter sleep mode -------------------- */
 
/* Since all registers and the SRAM are untouched by the SLEEP mode,
 * the program continues after the WFI instruction.
 * No further steps required. 
 */


  • stm32/peripherals/pwr_sleep.1476362406.txt.gz
  • Last modified: 2016/10/13 12:40
  • by feur