From c54728241c50e503727cba351783c476554076a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Mon, 30 Jan 2017 09:44:51 +0100 Subject: [PATCH] setup watchdog early on --- main.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/main.c b/main.c index 9bda51e..1db140a 100644 --- a/main.c +++ b/main.c @@ -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 + #if DEBUG + // 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 #endif // 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); + if (FLASH_OBR&FLASH_OBR_OPTERR) { + printf("option bytes not set in flash: software wachtdog used (not started at reset)\n"); + } else if (FLASH_OBR&FLASH_OBR_WDG_SW) { + printf("software wachtdog used (not started at reset)\n"); + } else { + printf("hardware wachtdog used (started at reset)\n"); + } +#endif + // 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)