Window option not working in code generated by STM32CubeIDE for IWDG
- April 28, 2020
- 2 replies
- 1353 views
Hi,
I have found a bug in the instructions order in code generated by STM32CubeIDE v1.3.0 for the IWDG (STM32G474) with LL drivers. The code itself pads the watchdog outside the acceptance window as soon as the window is set to a value sufficiently far from the default.
An example code for auto-generated function is:
void MX_IWDG_Init(void)
{
LL_IWDG_Enable(IWDG);
LL_IWDG_EnableWriteAccess(IWDG);
LL_IWDG_SetPrescaler(IWDG, LL_IWDG_PRESCALER_4);
LL_IWDG_SetWindow(IWDG, 100);
LL_IWDG_SetReloadCounter(IWDG, 120);
while (LL_IWDG_IsReady(IWDG) != 1)
{
}
LL_IWDG_ReloadCounter(IWDG);
}Explanation:
Problematic here is what happens starting from the call to "LL_IWDG_SetWindow".
- LL_IWDG_SetWindow sets the window and also triggers a reload of the default value of 4095. The counter starts down-counting from 4095.
- A new reload value is set and awaited to be transferred.
- The call to "LL_IWDG_ReloadCounter" resets the counter to the new value, but actually does this outside the predefined window range --> the watchdog resets the system
In my case window values of 4095 down to 4089 do work by accident, since the reloading then falls within the window (will depend on system clock). Using any window value smaller than this results in system reset (independent of the programmed reload value)
The correct code that is working for me is (compare also to the recommended init sequence in RM0440 Rev4 attached):
void MX_IWDG_Init(void)
{
LL_IWDG_Enable(IWDG);
LL_IWDG_EnableWriteAccess(IWDG);
LL_IWDG_SetPrescaler(IWDG, LL_IWDG_PRESCALER_4);
LL_IWDG_SetReloadCounter(IWDG, 120);
while (LL_IWDG_IsReady(IWDG) != 1)
{
}
LL_IWDG_SetWindow(IWDG, 100);
}