Showing results for 
Search instead for 
Did you mean: 

STM32L4 : IWDG wake up device in shutdown mode ?


Hi !

I'm using the stm32l452RE mcu and I use the shutdown mode. I also use the watchdog (IWDG) to reset the system if an error occurs. This IWDG is set to 4s. When I go in shutdown mode, accordly to the docs, IWDG should be off because it is clocked with LSI which is off.

Despite this, the device resets exactly after 4s.

If I change IWDG to 10s, device reset after 10s. That's why I'm sure IWDG continues working even when my device goes in shutdown mode.

The only thing I'm not sure is if I really enter in shutdown. Here below is what I do to enter in shutdown mode :

/* Clear flag */

For the IWDG set up, here is what I do :

void MX_IWDG_Init(void)
	hiwdg.Instance = IWDG;
	hiwdg.Init.Prescaler = IWDG_PRESCALER_32;
	hiwdg.Init.Window = IWDG_WINDOW_DISABLE; 
	hiwdg.Init.Reload = (32000 * 4095) / (32 * 1000);
	if (HAL_IWDG_Init(&hiwdg) != HAL_OK)

Have you any idea ?

Thanks for your help !


This is not working for STM32WB55CE (at least with J-Link).

Hello @IHlot.1​ ,

Indeed, when you have a st-link (should be the same with a j-link) plugged, it is not working . There is no workaround for this. At least I did not find any

Note that as a ST support once told me that low power modes like standby and shutdown in debug mode are quite "simulated".

So, as long as you are plugged with your debugger, IWDG will reset the device.

Note that you have two things to monitor this :

  • _HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) : detect wake up by watchdog : as soon as you have a debugger, this is always true...
  • (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) : allow you to detect if there is a debugger. Note that it does not make the difference between "something is plugged on the debugger bus" and "something is attached" (step by step debugging).

None of these things is satisfying.

Chief II

For a complete list of standby/shutdown related problems and solutions, read this:

@SimonF​ , @IHlot.1​ , @SLesh.1​ 

> So, as long as you are plugged with your debugger, IWDG will reset the device.

Section 3b in my article describes a solution/workaround.

@Piranha​ , sadly it does not solve all configurations.

What if we want to be attached and trigger my breakpoint when IWDG wakeup event is triggered because the firmware stay stucked ?

Then, I need to keep IWDG event, I cannot disable them. And if I keep it, then it is triggered all the time.

No solution in this case, except by using some HMI interface as debug

Nice post, Thank you for contributing to the community !

@Piranha​ So, what is the solution/conclusion? I'm interested in IWDG for STM32wb55ce.

@SimonF, the section 3b has two sentences... The second one provides a solution.

@IHlot.1​, if you took the code from my article, did you define the NDEBUG for a non-debug build and tested that build?

@Piranha​  this does not provide the solution of the problem describe in the current post you write. With the solution in 3b, I can no longer test if my IWDG is working correctly because...well, it is disabled. Thus my only solution is to be detached from the debugger, wait / force the firmware to be stuck and change a led color when it happens to monitor.

The 3b (IWDG_STDBY option bit) only disables the IWDG in shutdown and standby modes, not completely. It will still function normally in other modes.