cancel
Showing results for 
Search instead for 
Did you mean: 

IWDG early wakeup interrupt in Stop modes for STM32U5

Sarra.S
ST Employee

Introduction 

The IWDG (Independent Watchdog) offers the possibility to exit from stop modes in STM32U5. The wakeup from stop with interrupt is supported in Stop 0, Stop 1, Stop 2, and Stop 3 modes for STM32U535/545/59x/5Ax/5Fx/5Gx as described in the reference manual 0456 in table 618

Effect of LP modes on IWDGEffect of LP modes on IWDG

The IWDG offers the possibility to generate an Early Wakeup Interrupt EWI depending on the value of the down-counter. This can be used when specific safety operations or data logging must be performed before the watchdog reset is generated.

In all STM32U5 series except STM32U575/585 devices, the IWDG early interrupt is connected internally to EXTI line 25. In order to enable to EWI, it is needed to activate this EXTI line.

For STM32U575/585 devices, check the errata ES0499 2.18.1.

You can find the project related to this article in stm32-hotspot/CKB-STM32-IWDG-EWI (github.com)

STM32CubeMX configuration 

1. Configure the PA5 to GPIO output in the pin configuration, this pin is used as an indicator that the EWI has occurred 

GPIO_Output ConfigurationGPIO_Output Configuration

2. Activate the IWDG by checking the "Activated" box. Then, configure the "IWDG Early Wakeup" parameter as follows:

 

IWDG ConfigIWDG Config

 3. For GPIO driver selector, select LL drivers 

GPIO with LL driversGPIO with LL drivers

That is all for the STM32CubeMX configuration, you can now generate the code. 

Code configuration 

After code generation, we added the following code to enter stop2 mode and enable the EXTI line 25. 

 /* USER CODE BEGIN 2 */
  HAL_PWR_EnableWakeUpPin(EXTI_LINE_25); // Enable EXTI25 internally connected to IWDG EWI

  /* Enter the system to STOP 2 mode */

  HAL_SuspendTick();
  HAL_PWREx_EnterSTOP2Mode(PWR_STOPENTRY_WFI);
  HAL_ResumeTick();

  /* USER CODE END 2 */

Add the initialization of the EXTI structure along with the GPIO init in MX_GPIO_Init() 

static void MX_GPIO_Init(void)
{
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN MX_GPIO_Init_1 */
// Initialize the EXTI structure 
LL_EXTI_InitTypeDef EXTI_InitStruct = {0};
EXTI_InitStruct.Line_0_31 = LL_EXTI_LINE_25;
EXTI_InitStruct.LineCommand = ENABLE;
EXTI_InitStruct.Mode = LL_EXTI_MODE_IT;
EXTI_InitStruct.Trigger = LL_EXTI_TRIGGER_RISING_FALLING;
LL_EXTI_Init(&EXTI_InitStruct);

Finally, the PA5 pin is toggled inside the HAL_IWDG_EarlyWakeupCallback function to indicate that the EWI has occurred. 

References

Version history
Last update:
‎2024-09-24 12:30 AM
Updated by: