Skip to content

Commit 9400de3

Browse files
FRASTMcarlescufi
authored andcommitted
drivers: watchdog: stm32 iwdg starts with wdt_setup()
the watchdog is enabled by the wdt_setup() coming after the wdt_install_timeout. Due to PR #44972, the code did not follow that. This PR fixes the correct other in the sequence. Signed-off-by: Francois Ramu <[email protected]>
1 parent 86ee210 commit 9400de3

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

drivers/watchdog/wdt_iwdg_stm32.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static void iwdg_stm32_convert_timeout(uint32_t timeout,
7979

8080
static int iwdg_stm32_setup(const struct device *dev, uint8_t options)
8181
{
82-
ARG_UNUSED(dev);
82+
IWDG_TypeDef *iwdg = IWDG_STM32_STRUCT(dev);
8383

8484
/* Deactivate running when debugger is attached. */
8585
if (options & WDT_OPT_PAUSE_HALTED_BY_DBG) {
@@ -101,7 +101,9 @@ static int iwdg_stm32_setup(const struct device *dev, uint8_t options)
101101
return -ENOTSUP;
102102
}
103103

104-
/* Enable the IWDG only when the timeout is installed */
104+
/* Enable the IWDG now (timeout has been installed previoulsy) */
105+
LL_IWDG_Enable(iwdg); /* No need to Reload counter */
106+
105107
return 0;
106108
}
107109

@@ -136,22 +138,17 @@ static int iwdg_stm32_install_timeout(const struct device *dev,
136138

137139
tickstart = k_uptime_get_32();
138140

139-
LL_IWDG_Enable(iwdg);
141+
/* Do not enable the wdg during install but during wdt_setup() */
140142
LL_IWDG_EnableWriteAccess(iwdg);
141-
142143
LL_IWDG_SetPrescaler(iwdg, prescaler);
143-
LL_IWDG_SetReloadCounter(iwdg, reload);
144144

145145
/* Wait for the update operation completed */
146-
while (LL_IWDG_IsReady(iwdg) == 0) {
146+
while (LL_IWDG_IsActiveFlag_PVU(iwdg) == 0) {
147147
if ((k_uptime_get_32() - tickstart) > IWDG_SR_UPDATE_TIMEOUT) {
148148
return -ENODEV;
149149
}
150150
}
151151

152-
/* Reload counter just before leaving */
153-
LL_IWDG_ReloadCounter(iwdg);
154-
155152
return 0;
156153
}
157154

0 commit comments

Comments
 (0)