Hello,
Indeed, if the Hardware Time Server (HW_TS) is not initialized (via MX_APPE_Init()) quickly enough after the RTC initialization (via MX_RTC_Init()), the code might get stuck in an infinite loop in the HW_TS_RTC_Wakeup_Handler() function.
To avoid this problem there is 2 solutions:
Remove the following code in MX_RTC_Init function in main.c file:
/** Enable the WakeUp
*/
if (HAL_RTCEx_SetWakeUpTimer(&hrtc, 0, RTC_WAKEUPCLOCK_RTCCLK_DIV16) != HAL_OK)
{
Error_Handler();
}
You will have to remove it after every new code generation with STM32CubeMX.
To avoid to do modification every new code generation with STM32CubeMX.
> Change Wake Up Counter value:
If you used CubeMX, in RTC configuration change default value by 0xFFFF:
Or in MX_RTC_Init function in main.c, change the second parameter of this function by replace 0 value:
HAL_RTCEx_SetWakeUpTimer(&hrtc, 0, RTC_WAKEUPCLOCK_RTCCLK_DIV16)
by 0xFFFF:
HAL_RTCEx_SetWakeUpTimer(&hrtc, 0xFFFF, RTC_WAKEUPCLOCK_RTCCLK_DIV16)
> Add the following line in RTC_Init 2 User Code Section (in MX_RTC_Init function in main.c) :
__HAL_RTC_WAKEUPTIMER_DISABLE(&hrtc);
Best Regards,