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?
2022-08-09 03:47 AM
For a complete list of related issues and solutions, look here:
@Community member @karpy