setup watchdog early on

King Kévin 2017-01-30 09:44:51 +01:00
parent a3d838e665
commit c54728241c
1 changed files with 18 additions and 0 deletions

View File

@ -145,12 +145,18 @@ void main(void)
rcc_clock_setup_in_hse_8mhz_out_72mhz(); // use 8 MHz high speed external clock to generate 72 MHz internal clock
// enable functionalities for easier debug
DBGMCU_CR |= DBGMCU_CR_IWDG_STOP; // stop independent watchdog counter when code is halted
DBGMCU_CR |= DBGMCU_CR_WWDG_STOP; // stop window watchdog counter when code is halted
DBGMCU_CR |= DBGMCU_CR_STANDBY; // allow debug also in standby mode (keep digital part and clock powered)
DBGMCU_CR |= DBGMCU_CR_STOP; // allow debug also in stop mode (keep clock powered)
DBGMCU_CR |= DBGMCU_CR_SLEEP; // allow debug also in sleep mode (keep clock powered)
#else if !(DEBUG)
// setup watchdog to reset in case we get stuck (i.e. when an error occurred)
iwdg_set_period_ms(WATCHDOG_PERIOD); // set independent watchdog period
iwdg_start(); // start independent watchdog
// setup board
@ -165,6 +171,18 @@ void main(void)
// minimal setup ready
printf("welcome to the STM32F1 CuVoodoo example code\n"); // print welcome message
#if !(DEBUG)
// show watchdog information
printf("watchdog set to (%.2fs)\n",WATCHDOG_PERIOD/1000.0);
printf("option bytes not set in flash: software wachtdog used (not started at reset)\n");
printf("software wachtdog used (not started at reset)\n");
} else {
printf("hardware wachtdog used (started at reset)\n");
// setup RTC
printf("setup internal RTC: ");
rtc_auto_awake(RCC_LSE, 32768-1); // ensure internal RTC is on, uses the 32.678 kHz LSE, and the prescale is set to our tick speed, else update backup registers accordingly (power off the micro-controller for the change to take effect)