Disabling STM32 HAL IWDG or WWDG (watchdog) before STOP mode

Viewed 13053

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);
2 Answers

The Independent watchdog can not be stopped in any processor mode. You have to wake up regularly to reload the watchdog. What you can do is change the prescaler to maximum so the watchdog is counting slowly.

IWDG will only be stopped if you disconnect the controller from the power supply.

I have the (somehow) same problem, so it's what I have done:

I use HAL library, and it firstly initializes HAL_Init();, then calls SystemClock_Config();, and after that it starts initializing peripherals, including iwdg. (You can also do it without HAL).

So, when I want to go to stop mode, I restart the system using HAL_NVIC_SystemReset();, and when micro restarts, just after SystemClock_Config(); I check for previous system restart reason (check this). If it's software reset, I go to stop mode and don't let IWDG to be initialized.

Simple, easy.

psudo code:

1. instead of directly going to STOP mode -> make a software restart using HAL_NVIC_SystemReset();

//After restart and configuring system clocks (before initializing other peripherals)
2. if(previous restart reason == software restart) { 
        goto stop mode /* we don't init iwdg */
    } else {
        continue initializing peripherals.
    }
Related