cancel
Showing results for 
Search instead for 
Did you mean: 

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

vijayrakesh
Associate

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

1 ACCEPTED SOLUTION

Accepted Solutions

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.

 

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

7 REPLIES 7
Andrew Neil
Super User

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

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

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
TDK
Super User

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?

If you feel a post has answered your question, please click "Accept as Solution".

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.

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.

If you feel a post has answered your question, please click "Accept as Solution".

No issue is not resolved yet. Whichever order I follow the EWI configuration is not correctly applied and I am not receiving EW interrupt callback but IWDG reset after timeout.

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.

 

If you feel a post has answered your question, please click "Accept as Solution".

@TDK wrote:

Not interested in debugging Arduino libraries, not many people here using them.


Indeed.

@vijayrakesh That's why you'd be better asking in the STM32Duino and/or Arduino forum(s)

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.