Fix watchdog init code

This commit is contained in:
Mario Hüttel 2020-07-06 21:37:36 +02:00
parent 67a32cdc20
commit 248707055e

View File

@ -70,15 +70,24 @@ int watchdog_setup(uint8_t prescaler)
/** - Unlock registers */ /** - Unlock registers */
IWDG->KR = STM32_WATCHDOG_REGISTER_ACCESS_KEY; IWDG->KR = STM32_WATCHDOG_REGISTER_ACCESS_KEY;
/** - Wait until prescaler can be written */
while (IWDG->SR & IWDG_SR_PVU);
/** - Write prescaler value */ /** - Write prescaler value */
IWDG->PR = prescaler_reg_val; IWDG->PR = prescaler_reg_val;
/* - Wait until reload value can be written */
while (IWDG->SR & IWDG_SR_RVU);
/** - Set reload value fixed to 0xFFF */ /** - Set reload value fixed to 0xFFF */
IWDG->RLR = 0xFFFU; IWDG->RLR = 0xFFFU;
/** - Write enable key */ /** - Write enable key */
IWDG->KR = STM32_WATCHDOG_ENABLE_KEY; IWDG->KR = STM32_WATCHDOG_ENABLE_KEY;
/** - Do a first reset of the counter. This also locks the config regs */
watchdog_ack(WATCHDOG_MAGIC_KEY);
return 0; return 0;
} }