0
#include <RTClock.h>
#include <libmaple/pwr.h>
#include <libmaple/scb.h>
RTClock rtclock(RTCSEL_LSE);

#define SCB_SCR_SLEEPDEEP 4 
#define SCB_SCR_SLEEPONEXIT 2  
#define SCB_SCR_SEVONPEND 16

void sleepMode(bool standby, uint8_t seconds) { 
  rtclock.createAlarm(&int_fun, rtclock.getTime()+seconds);  // wakeup int
  PWR_BASE->CR &= PWR_CR_LPDS | PWR_CR_PDDS | PWR_CR_CWUF;
  PWR_BASE->CR |= PWR_CR_CWUF;
  PWR_BASE->CR |= PWR_CSR_EWUP;
  SCB_BASE->SCR |= SCB_SCR_SLEEPDEEP;
  if(standby) {
    PWR_BASE->CR |= PWR_CR_PDDS;
    PWR_BASE->CR &= ~PWR_CR_LPDS;
  } else {
    adc_disable(ADC1);
    adc_disable(ADC2);
    PWR_BASE->CR &= ~PWR_CR_PDDS;
    PWR_BASE->CR |= PWR_CR_LPDS;
  }
  asm("    wfi");
  SCB_BASE->SCR &= ~SCB_SCR_SLEEPDEEP;
}

This is the code I use to put the stm into sleep for 5 seconds. The problem is that stm could not wake up after sleep properly and consumes around 13 mA not 40mA like running on 72 MHz.

I use Arduino IDE

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.