cancel
Showing results for 
Search instead for 
Did you mean: 

Window option not working in code generated by STM32CubeIDE for IWDG

MScho.1
Associate III

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".

  1. LL_IWDG_SetWindow sets the window and also triggers a reload of the default value of 4095. The counter starts down-counting from 4095.
  2. A new reload value is set and awaited to be transferred.
  3. 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);
}

2 REPLIES 2
Imen GH
ST Employee

Hello @MScho.1​ 

I will check it and I will raise internally to take into consideration

Thank you for your contribution

Regards,

Khouloud ZEMMELI
ST Employee

​Hi @MScho.1​ ,

Issue fixed, the fix will be available for the next CubeMX release.

Best Regards,

Khouloud