I using an STM32 (L0 5) HAL I need to disable IWDG or WWDG before entering in STOP mode. The below code is working fine until IWDG is resetting the MCU from STOP mode. For WWDG usage this is much faster and reset before HAL_PWR_EnterSTOPMode is called, despite HAL_WWDG_Refresh is called after each line. I tested also those scenarios also on Nucleo L05.
iwdgHandle.Instance = IWDG;
iwdgHandle.Init.Prescaler = IWDG_PRESCALER_64;
iwdgHandle.Init.Window = 4095;
iwdgHandle.Init.Reload = 4095;
if (HAL_IWDG_Init(&iwdgHandle) != HAL_OK) // almost 7secs until refresh has to be called
{
_Error_Handler(__FILE__, __LINE__);
}
HAL_PWR_EnableWakeUpPin(WakeSpi_Pin);
HAL_PWREx_EnableUltraLowPower(); // Enable Ultra low power mode
HAL_PWREx_EnableFastWakeUp(); // Enable the fast wake up from Ultra low power mode
HAL_SuspendTick();
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);