2020-06-10 05:54 AM
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?
2020-06-10 06:06 AM
Look at the IWDG_STDBY flag in the option bytes. This halts IWDG in STANDBY and SHUTDOWN mode.
Jack Peacock
2020-06-10 06:10 AM
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
2020-06-10 06:39 AM
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
2020-06-10 03:20 PM
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.
2020-06-10 03:33 PM
Documentation doesn't mention shutdown mode at flags in option bytes.
2020-06-10 11:44 PM
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!
2020-06-11 01:52 AM
> 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
2022-07-14 02:22 AM
Is this solution suitable for all MCUs?
I tried it on STM32WB55CE with no success.
2022-08-08 12:05 AM
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.