I'm experiencing an odd issue with a Nucleo L432KC devboard from ST. When I start the IWDG using the following code:
IWDG_HandleTypeDef IwdgHandle;
IwdgHandle.Instance = IWDG;
IwdgHandle.Init.Prescaler = IWDG_PRESCALER_256;
IwdgHandle.Init.Reload = 30 * 125;
// 30 sec * 125 watchdog pulses per sec using the LSI frequency of ~32kHz and prescaler 256
and then try to "pet" the watchdog using the following:
HAL_IWDG_Refresh(&IwdgHandle); // resets the IWDG counter back to value of reload
The device immediately resets and the RCC_FLAG_IWDGRST
is set, indicating the reset was due to the watchdog timeout.
This issue using the same code worked perfectly on a Nucleo L152RE (the only difference is the dependencies now are for the L4xx series instead of L1xx)
Any ideas on why this reset is occuring?
Independent watchdog in the Stm32L4 series have window option. When enabled, it will reset the mcu if watchdog is reloaded too early - when watchdog counter value is above the window value.
IwdgHandle.Init.Window
should be set at 0xFFF (max value) if option is not required. If you have IwdgHandle
declared in bss - Window
field will be zero, resulting in a reset on watchdog refresh if counter is above zero.
typedef struct
{
uint32_t Prescaler; /*!< Select the prescaler of the IWDG.
This parameter can be a value of @ref IWDG_Prescaler */
uint32_t Reload; /*!< Specifies the IWDG down-counter reload value.
This parameter must be a number between Min_Data = 0 and Max_Data = 0x0FFF */
uint32_t Window; /*!< Specifies the window value to be compared to the down-counter.
This parameter must be a number between Min_Data = 0 and Max_Data = 0x0FFF */
} IWDG_InitTypeDef;
PS: Watchdog's timer is a downcounter. HAL_IWDG_Refresh
reloads counter with Reload
value, not resets to zero