IWDG Early Interrupt Not Working on STM32 NUCLEO-U385RG-Q #2763
-
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?
#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, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
LL_IWDG_SetEwiTime() overwrites the register when it is enabled and clears the EWI interrupt bit. |
Beta Was this translation helpful? Give feedback.
LL_IWDG_SetEwiTime() overwrites the register when it is enabled and clears the EWI interrupt bit.