Skip to main content
MScho.1
Associate III
April 28, 2020
Question

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

  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);
}

This topic has been closed for replies.

2 replies

Imen GH
ST Employee
April 28, 2020

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
May 18, 2020

​Hi @MScho.1​ ,

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

Best Regards,

Khouloud