scooter / Mbed 2 deprecated Nucleo_sleep

Dependencies:   mbed

main.cpp

Committer:
thorb3n
Date:
2015-12-08
Revision:
1:053449444c29
Parent:
0:8e1b0b607dc3

File content as of revision 1:053449444c29:

#include "mbed.h"

 #define IWDG_START 0x0000CCCC
 #define IWDG_WRITE_ACCESS 0x00005555
 #define IWDG_PR_PR_0 7
 #define IWDG_RELOAD 512*60
 #define IWDG_REFRESH 0xAAAA
 DigitalOut myled(LED1);
int main()
{
    /* (1) Activate IWDG (not needed if done in option bytes) */
    /* (2) Enable write access to IWDG registers */
    /* (3) Set prescaler by 8 */
    /* (4) Set reload value to have a rollover each 100ms */
    /* (5) Check if flags are reset */
    /* (6) Refresh counter */
    RCC_OscInitTypeDef RCC_OscInitStruct;
    RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
    RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_0;
    HAL_RCC_OscConfig(&RCC_OscInitStruct);
    
    IWDG->KR=IWDG_START;
    wait(5);
    IWDG->KR=IWDG_WRITE_ACCESS;
    IWDG->PR=IWDG_PR_PR_0;
    IWDG->RLR=IWDG_RELOAD;
    while(IWDG->SR) { 
        wait(0.1);   
    }
    //SwitchFromPLLtoHSI();
    //RCC->CFGR = (
    //0x00008000
    myled = 1;
    wait(3);
    myled = 0;
    wait(10);
   IWDG->KR=IWDG_REFRESH;/* (6) */
    //HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
    deepsleep();
    while(1) {
        
    }
}