Skip to main content
Associate
November 27, 2024
Solved

Watchdog functionality in Sleep mode for STM32U535CET microcontroller

  • November 27, 2024
  • 2 replies
  • 2246 views

Hello,

I am facing reset problem when I am waking up from Sleep mode. I am using WWDG in Software mode.

APB1 Frequency as 40MHz. COnfiguration of WWDG:

hwwdg.Instance = WWDG;

hwwdg.Init.Prescaler = WWDG_PRESCALER_128;

hwwdg.Init.Window = 127;

hwwdg.Init.Counter = 127;

hwwdg.Init.EWIMode = WWDG_EWI_DISABLE;

 

I am calling MX_WWDG_Init function after initialization of peripherals and functionality needed.

Then I am refreshing it in while loop of main function.

1st Tested Scenario:

While entering sleep mode I just refresh the WWDG. Then by waking up

from sleep mode by push button, I am getting reset and it's started from main function again instead of Re-init function.

2nd Tested Scenario:

While entering in sleep mode, I am refreshing WWDG first, then disabling APB1 clock and after that

when I wake up from push button I am enabling the APB1 clock. In this scenario I assumed that WWDG

clock should be stop in sleep mode and it should resume after wakeup.

When controller wakes up by pressing button, I am getting reset.

Please suggest me the setting if I am missing anything.

 

Best answer by Sarra.S

so, just before entering stop mode, refresh the WWDG counter: 

void SleepControlTask(void)
{
 delayStop(&SleepWakeUpDelay);
 SleepACK = false;
 HAL_WWDG_Refresh(&hwwdg); // Refresh WWDG before entering sleep mode
 SleepWakeUpMode();
}
void SleepWakeUpMode(void)
{
 GPIO_deInit();
 __HAL_RCC_RTC_DISABLE();
 HAL_PWR_EnableBkUpAccess();
 HAL_SuspendTick();
 HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
 __HAL_RCC_RTC_ENABLE();
 HAL_ResumeTick();
 SystemClock_Config();
 HAL_WWDG_Refresh(&hwwdg); // Refresh WWDG immediately after waking up
}

and when exiting stop mode, re-enable the WWDG clock and re-initialize it  

// After waking up from sleep mode
__HAL_RCC_WWDG_CLK_SLEEP_ENABLE(); // Re-enable the WWDG clock after waking up
MX_WWDG_Init(); // Re-initialize the WWDG
HAL_WWDG_Refresh(&hwwdg); // Refresh the WWDG counter

 

2 replies

ST Employee
November 27, 2024

Hello @shwetapal02, Welcome to ST Community, 

Please check this bit in the RCC_APB1SMENR1 register

SarraS_0-1732723813359.png

 

Associate
December 1, 2024

Hello @Sarra.S

Thanks for reply. I am setting and resetting the suggested bit by calling below function.

I am calling __HAL_RCC_WWDG_CLK_SLEEP_ENABLE(); after waking up and calling __HAL_RCC_WWDG_CLK_SLEEP_DISABLE(); function during going in sleep mode. But Once it woke up from sleep mode (by pressing button) it is giving me reset. 

I am not able to understand why?

I tried this scenario with WWDG_SW 0 and 1 in both case. But it's not working.

Please help me ASAP.

Associate
December 2, 2024

Hello,

I need support for the above issue on urgent basis. Please help for the same.

Thanks, your understanding and kind support!!

Sarra.SBest answer
ST Employee
December 3, 2024

so, just before entering stop mode, refresh the WWDG counter: 

void SleepControlTask(void)
{
 delayStop(&SleepWakeUpDelay);
 SleepACK = false;
 HAL_WWDG_Refresh(&hwwdg); // Refresh WWDG before entering sleep mode
 SleepWakeUpMode();
}
void SleepWakeUpMode(void)
{
 GPIO_deInit();
 __HAL_RCC_RTC_DISABLE();
 HAL_PWR_EnableBkUpAccess();
 HAL_SuspendTick();
 HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
 __HAL_RCC_RTC_ENABLE();
 HAL_ResumeTick();
 SystemClock_Config();
 HAL_WWDG_Refresh(&hwwdg); // Refresh WWDG immediately after waking up
}

and when exiting stop mode, re-enable the WWDG clock and re-initialize it  

// After waking up from sleep mode
__HAL_RCC_WWDG_CLK_SLEEP_ENABLE(); // Re-enable the WWDG clock after waking up
MX_WWDG_Init(); // Re-initialize the WWDG
HAL_WWDG_Refresh(&hwwdg); // Refresh the WWDG counter

 

Associate
December 3, 2024

Thank you so much for your quick reply. It was really helpful. Now my code is working.

Thanks a lot!!