diff --git a/drivers/watchdog/wdt_iwdg_stm32.c b/drivers/watchdog/wdt_iwdg_stm32.c index 6b85fe13d7b..208f7753cc9 100644 --- a/drivers/watchdog/wdt_iwdg_stm32.c +++ b/drivers/watchdog/wdt_iwdg_stm32.c @@ -79,7 +79,7 @@ static void iwdg_stm32_convert_timeout(uint32_t timeout, static int iwdg_stm32_setup(const struct device *dev, uint8_t options) { - ARG_UNUSED(dev); + IWDG_TypeDef *iwdg = IWDG_STM32_STRUCT(dev); /* Deactivate running when debugger is attached. */ if (options & WDT_OPT_PAUSE_HALTED_BY_DBG) { @@ -101,7 +101,9 @@ static int iwdg_stm32_setup(const struct device *dev, uint8_t options) return -ENOTSUP; } - /* Enable the IWDG only when the timeout is installed */ + /* Enable the IWDG now (timeout has been installed previoulsy) */ + LL_IWDG_Enable(iwdg); /* No need to Reload counter */ + return 0; } @@ -136,22 +138,17 @@ static int iwdg_stm32_install_timeout(const struct device *dev, tickstart = k_uptime_get_32(); - LL_IWDG_Enable(iwdg); + /* Do not enable the wdg during install but during wdt_setup() */ LL_IWDG_EnableWriteAccess(iwdg); - LL_IWDG_SetPrescaler(iwdg, prescaler); - LL_IWDG_SetReloadCounter(iwdg, reload); /* Wait for the update operation completed */ - while (LL_IWDG_IsReady(iwdg) == 0) { + while (LL_IWDG_IsActiveFlag_PVU(iwdg) == 0) { if ((k_uptime_get_32() - tickstart) > IWDG_SR_UPDATE_TIMEOUT) { return -ENODEV; } } - /* Reload counter just before leaving */ - LL_IWDG_ReloadCounter(iwdg); - return 0; }