Page 1 of 1

IWDG Early Interrupt Not Working on STM32 NUCLEO-U385RG-Q (Arduino IDE)

Posted: Thu Jul 03, 2025 8:38 am
by vijayrakesh
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_SetPrescaler()) 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?

Code: Select all

// Enable IWDG EWI in IWatchdog.cpp
  LL_IWDG_SetEwiTime(IWDG, (uint32_t)1500);
  LL_IWDG_EnableIT_EWI(IWDG);
// INO File

Code: Select all

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

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

#ifdef USER_BTN
const int buttonPin = USER_BTN;
#else
const int buttonPin = 2;
#endif

#ifdef LED_BUILTIN
const int ledPin = LED_BUILTIN;
#else
const int ledPin = 13;
#endif

static int default_buttonState = LOW;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT);
  Serial.begin(115200);
  Serial.println("Init");

  if (IWatchdog.isReset(true)) {
    // LED blinks to indicate reset
    for (uint8_t idx = 0; idx < 5; idx++) {
      digitalWrite(ledPin, HIGH);
      delay(100);
      digitalWrite(ledPin, LOW);
      delay(100);
    }
  }

  // Read default state of the pushbutton
  default_buttonState = digitalRead(buttonPin);
  
  // Enable EWI
   __enable_irq();   // Enables global interrupts
  HAL_NVIC_SetPriority(IWDG_IRQn, 0, 0);
  HAL_NVIC_EnableIRQ(IWDG_IRQn);
  IWatchdog.begin(10000000);
  Serial.print("EWI value: ");
  Serial.println(LL_IWDG_GetEwiTime(IWDG));
  
  if (!IWatchdog.isEnabled()) {
    // LED blinks indefinitely
    while (1) {
      digitalWrite(ledPin, HIGH);
      delay(500);
      digitalWrite(ledPin, LOW);
      delay(500);
    }
  }
}

void loop() {
  // Compare current button state of the pushbutton value:
  if (digitalRead(buttonPin) == default_buttonState) {
    digitalWrite(ledPin, LOW);
  } else {
    digitalWrite(ledPin, HIGH);
    // Reload the watchdog only when the button is pressed
    IWatchdog.reload();
  }
}


Any tips or examples would be greatly appreciated.

Thanks,
Vijay Rakesh