on
2024-09-18
05:58 AM
- edited on
2024-09-24
12:30 AM
by
Laurids_PETERSE
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:
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)
1. Configure the PA5 to GPIO output in the pin configuration, this pin is used as an indicator that the EWI has occurred
2. Activate the IWDG by checking the "Activated" box. Then, configure the "IWDG Early Wakeup" parameter as follows:
3. For GPIO driver selector, select LL drivers
That is all for the STM32CubeMX configuration, you can now generate the code.
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.