Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 1:053449444c29
- Parent:
- 0:8e1b0b607dc3
--- a/main.cpp Tue Dec 01 15:45:13 2015 +0000 +++ b/main.cpp Tue Dec 08 14:27:53 2015 +0000 @@ -1,39 +1,43 @@ #include "mbed.h" - -InterruptIn event(USER_BUTTON); -DigitalOut myled(LED1); - -int go_to_sleep = 0; - -void pressed() -{ - printf("Button pressed\n"); - go_to_sleep = !go_to_sleep; -} - + + #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); - HAL_PWR_EnableWakeUpPin(USER_BUTTON); - int i = 0; - - //event.fall(&pressed); - - while (1) { - event.fall(&pressed); - if (go_to_sleep) { - //myled = 1; - printf("%d: Entering sleep (press user button to resume)\n", i); - //sleep(); - //deepsleep(); - HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI); - - //wait(0.1); - } else { - printf("%d: Running\n", i); - myled = !myled; - wait(1.0); - } - i++; + 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) { + + } +} \ No newline at end of file