cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L433 IWDG wakes up from SHUTDOWN Mode

Jonathan Frech
Associate II

In my use-case i want to have a watch-dog active when the device is in use to prevent software stucks or accidental ending in endless loops. Therefore i have configured the IWDG like this:

void hw_IWDG_Init(void){
 
	IwdgHandle.Instance = IWDG;
	IwdgHandle.Init.Prescaler = IWDG_PRESCALER_256;
	IwdgHandle.Init.Reload = 0x0BB8;
	IwdgHandle.Init.Window = IWDG_WINDOW_DISABLE;
 
	if(HAL_IWDG_Init(&IwdgHandle) != HAL_OK)
	{
		/* Initialization Error */
		_Error_Handler(__FILE__, __LINE__);
	}
}

This should give me a IWDG Reset between 22.2 and 26s, depending on LSI accuracy according to datasheet (29.5 - 34kHz).

In normal operation, this works fine, but when the device is shut down, the watchdog should stop operating. According to datasheet, the watchdog is NOT ACTIVE in SHUTDOWN

Measuring with OTII, i get a average of 1uA current, which confirms that the device is actually entering SHUTDOWN. (Datasheet says 313nA at 3.6V, but there are other ic's on the board and measuring accuracy).

I enter Shutdown as following:

 hw_GPIO_InitShutdown();
 
	/* Disable used wakeup source: PWR_WAKEUP_PIN1 */
	  HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1);
	  HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN2);
	  HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN4);
 
	  HAL_PWR_DisableBkUpAccess();
 
	  /* Clear all related wakeup flags */
	  __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
 
	  /* Enable wakeup pin WKUP1 */
	  if(pol = WUPOL_HIGH){
		  HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1_HIGH);
	  }
	  else{
		  HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1_LOW);
	  }
 
	  /* Set RTC back-up register RTC_BKP31R to indicate
	       later on that system has entered shutdown mode  */
	  //WRITE_REG( RTC->BKP31R, 0x1 );
	  __HAL_RCC_PWR_CLK_ENABLE();
 
 
	  HAL_PWREx_DisableInternalWakeUpLine();
	  /* Enter the Shutdown mode */
	  HAL_PWREx_EnterSHUTDOWNMode();
	  //HAL_PWR_EnterSTANDBYMode();

I also modiefied HAL_PWREx_EnterSHUTDOWNMode as following:

  /* Set Shutdown mode */
  MODIFY_REG(PWR->CR1, PWR_CR1_LPMS, PWR_CR1_LPMS_SHUTDOWN);
 
  /* Set SLEEPDEEP bit of Cortex System Control Register */
  SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
 
/* This option is used to ensure that store operations are completed */
#if defined ( __CC_ARM)
  __force_stores();
#endif
 
  PWR->SR1 &= ~PWR_SR1_WUF;				//MODIFYED!!
  __SEV();								//MODIFYED!!
  __WFE();								//MODIFYED!!
  /* Request Wait For Interrupt */
  __WFI();

But yet, my device wakes up after 23 seconds.

Is there anyway i can further debug this?

What could be causing this malfunction?

10 REPLIES 10
Jack Peacock_2
Senior III

Look at the IWDG_STDBY flag in the option bytes. This halts IWDG in STANDBY and SHUTDOWN mode.

Jack Peacock

I forgot to mention that i use Atollic TrueStudio. As far as i know, this IDE does not support Option bytes at all, or am i wrong? Usually Option Bytes are programmed via ST-Link or CubeProgrammer when using .hex file for delivery

https://community.st.com/s/question/0D53W0000056NCFSA2/iwdg-is-not-turnoff-in-shutdown-mode-of-controllerstm32l4r5 and the link chain from there

I am not much into the low-power modes. I personally would double-check by reading back registers at every step taken towards the chosen low-power mode.

JW

Piranha
Chief II

Few days ago I also stumbled on this on a STM32L433 and found this topic:

https://community.st.com/s/question/0D50X0000BeaMHpSQM/stm32l4-iwdg-wake-up-device-in-shutdown-mode-

It seems that the OP also have found it and tried the "solution" provided by Imen. To me it seemed highly suspicious from the first look and it proved to be what it seems to be - absolutely unrelated to the problem and not fixing anything. But a bit of thinking and guessing and I found it. IWDG seems to be powered from the same power line the debug interface is powered and should be disabled before entering shutdown mode. Take a note that it must be disabled anyway, otherwise debug interface will consume current even in shutdown mode and those bits are not reset by system reset.

	SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
#ifdef NDEBUG
	DBGMCU->CR = 0; // Disable debug, trace and IWDG
#endif
	__DSB();
	__WFI();

ST's employees are not running into this issue because ST-LINK and their test code doesn't set these bits, but J-Link, probably other probes and more complex code can set these bits.

Problem reports go back to at least a year 2016. For me it doesn't seem like a hardware bug, but more like an inadequate documentation. @Imen DAHMEN​, @Tomas SIRUCEK​, someone should finally tackle this and update the reference manuals in all related STM32 series. And, as it will probably take a long time, at least inform us here for which series my findings are true.

Documentation doesn't mention shutdown mode at flags in option bytes.

Thank you for this answer! This was able to resolve my issue. As long as the ST-Link is connected, the WD does run in Shutdown (no matter if really debugging or just plugged in). After removing the ST-Link Cable, the Device works correctly!

> Thank you for this answer! This was able to resolve my issue. As long as the ST-Link is connected, the WD does run in Shutdown

> (no matter if really debugging or just plugged in). After removing the ST-Link Cable, the Device works correctly!

And what is the content of DBGMCU_CR?

JW

Is this solution suitable for all MCUs?

I tried it on STM32WB55CE with no success.

Very helpful post, thanks! I can confirm that the option byte IWDG_STDBY (set it in the cubeprogrammer) does affect also SHUTDOWN mode. The IWDG timer kept running in SHUTDOWN mode until I unchecked this option byte.