Skip to main content
Explorer
July 3, 2025
Solved

IWDG Early Interrupt not generating on STM32 NUCLEO-U385RG-Q (Arduino IDE)

  • July 3, 2025
  • 2 replies
  • 894 views

Hi everyone,

I'm building a watchdog application on the STM32 NUCLEO-U385RG-Q using the Arduino IDE and the IWatchdog library. Since the library doesn’t support early interrupt callbacks, I modified it by adding some LL code (after

LL_IWDG_SetReloadCounter()) inside IWatchdogClass::set() as shown below. However, the early interrupt doesn’t trigger. Am I missing something, like NVIC config or enabling the interrupt line?
 LL_IWDG_SetEwiTime(IWDG, (uint32_t)EWITimeout);
 LL_IWDG_EnableIT_EWI(IWDG);

 Arduino Code

#include <IWatchdog.h>
extern "C"{
 #include <stm32u3xx_ll_iwdg.h>
 #include <stm32u3xx.h>
}

extern "C" void IWDG_IRQHandler (void){
 Serial.println("Wake up Interrupt");
}


void setup(){
 Serial.begin(115200);
 __enable_irq(); // Enables global interrupts
 HAL_NVIC_SetPriority(IWDG_IRQn, 0, 0);
 HAL_NVIC_EnableIRQ(IWDG_IRQn);
 IWatchdog.begin(10000000);
}

After further debugging, I found that EWI timeout is not being set if EWI interrupt is enabled and when EWI is disabled EWI timeout is updating but not both at the same time.

Any suggestions would be greatly appreciated.

Thanks,
Vijay

    This topic has been closed for replies.
    Best answer by TDK

    Here's what HAL does. Probably works. Note how it waits for registers to be updated.

    https://github.com/STMicroelectronics/stm32u3xx-hal-driver/blob/c24b3079e9c12264b0752240398a246f91b1356a/Src/stm32u3xx_hal_iwdg.c#L182

     

    If you can duplicate the issue using HAL or CubeMX generated code, post it here. Not interested in debugging Arduino libraries, not many people here using them.

     

    2 replies

    Super User
    July 3, 2025

    Arduino (STM32Duino) questions should go here: https://www.stm32duino.com/

    Or, perhaps, in the main Arduino forums: https://forum.arduino.cc/

    Super User
    July 3, 2025

    Why do you think it doesn't trigger? Your terminal may be buffering and waiting for \n before it prints characters. 

    Show your IWDG configuration.

    > After further debugging, I found that EWI timeout is not being set if EWI interrupt is enabled and when EWI is disabled EWI timeout is updating but not both at the same time.

    How is EWI timeout updating when EWI is disabled? What do you mean by this?

    Explorer
    July 3, 2025

    Hi TDK,

    While going through the STM32U385 reference manual, I found the correct sequence for configuring the Independent Watchdog (IWDG). According to the manual, after setting the IWDG reload register (IWDG_RLR), you should first set the early wake-up time and then enable the early wake-up interrupt by writing to the IWDG_EWCR register.

    So, I first called LL_IWDG_SetEwiTime() followed by LL_IWDG_EnableIT_EWI(). In this case, the EWI time value is correctly set, but the EWI enable bit remains 0.

    However, if I reverse the order — calling LL_IWDG_EnableIT_EWI() first and then LL_IWDG_SetEwiTime() — the enable bit is correctly set to 1, but the EWI time value becomes 0.

    It seems that the order in which these functions are called affects the result, and the settings don't get applied correctly.

    This is the IWDG configuration. Line 2 was executed by a previous function IWatchdogClass::begin(), while lines 10 and 11 were added by me in this library file.

     // Enable the IWDG by writing 0x0000 CCCC in the IWDG_KR register 
     LL_IWDG_Enable(IWDG);
     // Enable register access by writing 0x0000 5555 in the IWDG_KR register
     LL_IWDG_EnableWriteAccess(IWDG);
     // Write the IWDG prescaler by programming IWDG_PR from 0 to 7
     // LL_IWDG_PRESCALER_4 (0) is lowest divider
     LL_IWDG_SetPrescaler(IWDG, (uint32_t)prescaler);
     // Write the reload register (IWDG_RLR)
     LL_IWDG_SetReloadCounter(IWDG, reload);
     LL_IWDG_SetEwiTime(IWDG, (uint32_t)1000);
     LL_IWDG_EnableIT_EWI(IWDG);

     Thank you,

     Vijay.

    Super User
    July 3, 2025

    So all is well now? And the issue was because IWDG was being initialized in an incorrect order?

    If so please mark your post as the solution.