4

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);
Colateral
  • 1,736
  • 2
  • 18
  • 22
  • In the meanwhile I found the following: : ''the IWDG is started by writing to its Key register or by hardware option. Once started it cannot be stopped except by a Reset.'' – Colateral Nov 16 '18 at 15:52
  • 1
    also from ST: One of the differences between WWDG and IWDG is that IWDG has independent clock. The WWDG is clocked from APB bus whose frequency is derived from the core clock (SYSCLK). Due to the fact that the core clock is stopped in STOP mode the WWDG clock is stopped as well. This means it is automatically stopped in STOP low-power mode and you don't have to refresh it. With IWDG you would have to wake-up regularly and refresh it. Microcontrollers from STM32L4 family allow to stop also IWDG in STOP mode (by setting corresponding option byte). – Colateral Nov 16 '18 at 15:54

4 Answers4

6

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.

A.R.C.
  • 910
  • 11
  • 22
  • Same behaviour seems to be also with WWDG. Does this can be disabled before going to STOP? – Colateral Nov 16 '18 at 14:15
  • @Colateral No, with watchdogs generally once you set them going that's it. It's to prevent code from accidentally turning it off again in a fault state. – Colin Nov 16 '18 at 14:39
  • I have to correct myself! In shutdown mode, all clocks except LSE are off. So, if your WDG is running for example on LSI, reloading is not necessary. See chapter Power control for an overview of sleep modes and clock behavior. – A.R.C. Dec 17 '18 at 07:13
  • Note: For debugging purposes, the Independent Watchdog (IWDG) can be stopped when the core is halted (see DBG_IWDG_STOP (in the Debug MCU freeze register) in the reference manual). – rel May 09 '19 at 02:36
  • For WWDG, you can disable using __HAL_RCC_WWDG_CLK_DISABLE(); – user3509549 Aug 29 '20 at 21:54
  • Note that disabling it using __HAL_RCC_WWDG_CLK_DISABLE should be considered a brittle workaround and is not portable : I have used that approach on an stm32F4 but on a stm32G4 the same trick is not preventing a wwdg induced reset. – gg99 Sep 28 '21 at 13:50
1

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.
    }
Mohammad Kholghi
  • 533
  • 2
  • 7
  • 21
1

There's a flash option byte that you can clear that will prevent the IWDG or the WWDG timers from counting while in stop mode.

  • Where is it bruv? – Mohammad Kholghi Jul 14 '23 at 08:43
  • @MohammadKholghi The USER option bytes contain the bits for controlling if the IWDT is frozen or running in stop or standby mode. Clear bit 17 to freeze the IWDT in stop mode. Clear bit 18 to freeze the IWDT in standby mode. You can use `HAL_FLASHEx_OBProgram` in stm32l4xx_hal_flash_ex.c to configure the option bytes. – Ted Aug 22 '23 at 12:52
0

As previously mentioned, there is a solution involving option bytes. I utilized the STM32Cube Programmer application and disabled the IWDG_STOP option within the user options. This action freezes the watchdog timer when entering the stop mode.

Wadeva
  • 1
  • 1