Test of the Nucleo boards standby mode. sleep() and deepsleep() use the STM32 SLEEP and STOP modes. This uses the 3rd low power mode STANDBY. Utilises the WakeUp code here: https://developer.mbed.org/users/Sissors/code/WakeUp/ Adds a ClearWakeUp so that Standby can be entered repeatedly.

Dependencies:   WakeUp mbed

main.cpp

Committer:
MichaelW
Date:
2016-05-07
Revision:
1:085a87258f10
Parent:
0:1ecaa40f74d0

File content as of revision 1:085a87258f10:

#include "mbed.h"
#include "WakeUp.h"

DigitalOut myled(LED1);

void ClearWakeUp(void);

int main()
{
    myled = 1;
    wait(0.2);
    myled = 0;
    wait(0.2);

    //The low-power oscillator can be quite inaccurate on some targets
    //this function calibrates it against the main clock
    WakeUp::calibrate();


    WakeUp::set_ms(5000);
    ClearWakeUp();

    printf("Entering Standby Mode\r\n");

    HAL_PWR_EnterSTANDBYMode();
    
    //This will never be executed
    printf("After sleep\r\n");

}
void ClearWakeUp(void)
{
    PWR->CR |= PWR_CR_DBP;      //Enable power domain
    RTC->WPR = 0xCA;            //Disable RTC write protection
    RTC->WPR = 0x53;

    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
    __HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);

    RTC->WPR = 0xFF;        //Enable RTC write protection
    PWR->CR &= ~PWR_CR_DBP; //Disable power domain
}