Skip to main content
SimonF
Senior
November 20, 2019
Solved

STM32L4 : IWDG wake up device in shutdown mode ?

  • November 20, 2019
  • 7 replies
  • 7364 views

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 !

This topic has been closed for replies.
Best answer by Piranha

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

7 replies

waclawek.jan
Super User
November 21, 2019

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
SimonFAuthor
Senior
November 21, 2019

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.

ST Technical Moderator
March 13, 2020

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

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
SLesh.1
Associate II
July 12, 2020

@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
PiranhaBest answer
Principal III
July 12, 2020

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

SLesh.1
Associate II
July 13, 2020

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...

SLesh.1
Associate II
July 13, 2020

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.

SimonF
SimonFAuthor
Senior
March 7, 2022

I confirm the solution from @Piranha​ .

Just add this line before going in shutdown mode :

DBGMCU->CR = 0

IHlot.1
Associate II
July 12, 2022

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

SimonF
SimonFAuthor
Senior
July 13, 2022

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.

Piranha
Principal III
July 13, 2022

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

https://community.st.com/s/question/0D53W00001bnh8dSAA/how-to-enter-standby-or-shutdown-mode-on-stm32

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

SimonF
SimonFAuthor
Senior
July 13, 2022

Nice post, Thank you for contributing to the community !