cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L4 : IWDG wake up device in shutdown mode ?

SimonF
Senior

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 :

HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1_LOW); 
HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1);
/* Clear flag */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUF1);
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUFI);
HAL_PWREx_EnterSHUTDOWNMode();

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)
	{
		Error_Handler();
	}
}

Have you any idea ?

Thanks for your help !

1 ACCEPTED SOLUTION

Accepted Solutions
Piranha
Chief II

Imen's solution is nonsense and doesn't solve anything. The real solution is there:

https://community.st.com/s/question/0D53W00000947bASAQ/stm32l433-iwdg-wakes-up-from-shutdown-mode

View solution in original post

20 REPLIES 20

This may be a undocumented "feature", unacknowledged by ST so far.

https://community.st.com/s/question/0D50X00009XkYZQSA3/trying-to-put-stm32l471rg-into-shutdown-mode

JW

@Imen DAHMEN​  , @Viktor POHORELY​ 

SimonF
Senior

Thank you for your time.

Well, I saw this thread but it's been close without definitive reply (as far as I know).

But I guess the only people able to reply are ST Employee and hope they will come to that post.

I believe I'm not the only one who deals with this problem.

@Imen DAHMEN​  answered the post by linking their PWR projects but obviously I look this project and even done same lines in the same order.

It doesn't change anything.

And as far as I know, in any case, the IWDG should be able to wake up if device is in shutdown mode.

Imen.D
ST Employee

Hi,

The LSI and IDWG is NOT functional in shutdown mode on STM32L4.

We have simply tested example given in the Cube firmware package by adding the following code :

/* Insert 990 ms delay */
 HAL_Delay(990);
 /* Refresh IWDG: reload counter */
 if(HAL_IWDG_Refresh(&IwdgHandle) != HAL_OK)
 {
 /* Refresh Error */
 Error_Handler();
 }
 BSP_LED_Off(LED2);
 __HAL_RCC_PWR_CLK_ENABLE();
 HAL_PWREx_EnterSHUTDOWNMode();
//    HAL_PWR_EnterSTANDBYMode();
while(1);

Standby is waking up but not Shutdown.

Also, i have tested the code in the discussion mentioned by Jan (see code below) and confirm that if IWDG occured is because the event was not cleared at Cortex level.

/* Refresh IWDG: reload counter */
 if(HAL_IWDG_Refresh(&IwdgHandle) != HAL_OK)
{
 /* Refresh Error */
Error_Handler();
 }
 BSP_LED_Off(LED2);
 __HAL_RCC_PWR_CLK_ENABLE();
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk | SCB_SCR_SLEEPONEXIT_Msk;
 // Setup Low Power Mode State and Shutdown
 PWR->CR1 |= 0x4004; // Set LPR and LPMS_SHUTDOWN bits
 // Clear WUFx bits
 PWR->SR1 &= ~PWR_SR1_WUF;
 __SEV();
 __WFE();
 __WFE();
 

The consumption of the LSI is around 150nA much greater than shutdown mode itself, so we would noticed it which is not the case (even with IDWG enabled, shutdown consumption is inline with datasheet expectation)

Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
SLesh.1
Associate III

@Imen DAHMEN​ thank you for your answer. But it is not clear - how to use shutdown mode with IWDG in a proper way? I have the same problem:

I set RTC for wake up (every 5 seconds f.e.), set IWDG (every 1 second f.e.), - when system goes to shutdown mode - it rebooted by IWDG every 1 second. If IWDG turned off - it works well - it runs every 5 seconds.

if(HAL_IWDG_Refresh(&hiwdg) != HAL_OK)
   {
	   /* Refresh Error */
	   Error_Handler();
   }
 
timeout = 5000; // ms, see below
 
wakeUpCounterMs = timeout * 2; // Wakeup Time Base = 16 /(~32.000KHz) = ~0.5 ms Wakeup Time = 0.5 ms  * WakeUpCounter
 
HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, wakeUpCounterMs, RTC_WAKEUPCLOCK_RTCCLK_DIV16);
 
__HAL_RCC_PWR_CLK_ENABLE();
HAL_PWREx_EnterSHUTDOWNMode();
 
while(1);

Piranha
Chief II

Imen's solution is nonsense and doesn't solve anything. The real solution is there:

https://community.st.com/s/question/0D53W00000947bASAQ/stm32l433-iwdg-wakes-up-from-shutdown-mode

Thank you, I will try it.

But I have other problem... that is a magic with power save modes (may be main reason some were in my hands... (= ) But I retuned back to standby mode without IWDG. And it doesn't work... (shutdown mode too, but it with standby mode I can see flag that system was sleep without backup register - __HAL_PWR_GET_FLAG(PWR_FLAG_SB) ). I send MCU in standby mode but it runs immediately. But RTC wake up was set. Before experiments with shutdown mode it worked.

I have made a simple project:

int main(void)
{
  /* USER CODE BEGIN 1 */
 
  /* USER CODE END 1 */
 
  /* MCU Configuration--------------------------------------------------------*/
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  /* USER CODE BEGIN Init */
 
  /* USER CODE END Init */
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* USER CODE BEGIN SysInit */
 
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART2_UART_Init();
  MX_LPUART1_UART_Init();
  MX_RTC_Init();
  /* USER CODE BEGIN 2 */
 
  __HAL_RCC_PWR_CLK_ENABLE();
 
  if(__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET) {
  	/* Clear Standby flag */
  	__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
  	__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
  	__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WUFI);
  	HAL_UART_Transmit(&hlpuart1, "wakeup\r\n", 8, 100);
  }
  else {
  	HAL_UART_Transmit(&hlpuart1, "run\r\n", 5, 100);
  }
 
  HAL_Delay(2000);
 
 
  HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
  HAL_PWREx_DisableInternalWakeUpLine();
 
 // 5 sec delay
  HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 5, RTC_WAKEUPCLOCK_CK_SPRE_16BITS);
 
  HAL_PWREx_EnableInternalWakeUpLine();
 
  HAL_PWR_EnterSTANDBYMode();
 
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

The same result... System is rebooting every 2 seconds, not 7.

It looks like that I have set some non-volatile setting...

I have fount a my mistake... or stm32 feature. If something is set up wrong with power safe mode, I have to turn off the power for power reset - new settings will not applied without power off. Reset from ST-Link is not enough.

Sorry for the late reply.

Thank you for your reply @Piranha​ . I had open a ticket with ST employees and they told me the same as in this thread. Keep saying that I'm not in the right mod or telling me I don't understand the datasheet. I do not understand why they cannot just tell us "we know there is an issue" or "it is not specified in the datasheet but..." Instead of just saying the same thing to everybody while it is obviously false. It made me lost a lot of time.

Thank you because I got the same behaviour. For me it is linked with ST-LINK (not J-LINK) and when using it, iwdg is working even in shutdown. On some device this behaviour goes back to normal when ST-LINK is unwired and for some other even withoutt ST-LINK the issue is still there.

I still do not have the time to fix this issue or try because it is not a priority right now but I let know the community if I can confirm it is working for me too.

SimonF
Senior

I confirm the solution from @Piranha​ .

Just add this line before going in shutdown mode :

DBGMCU->CR = 0