Skip to main content
Visitor II
June 27, 2024
Solved

HAL_RTCEx_DeactivateWakeUpTimer returns HAL_RTC_STATE_TIMEOUT

  • June 27, 2024
  • 1 reply
  • 995 views

I am using STM32L0 with LSE rtc xtal, CubeMX/HAL. I have a 20 second wakup using

 

 

if (HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 40960, RTC_WAKEUPCLOCK_RTCCLK_DIV16) != HAL_OK)
{
 Error_Handler();
}

AND

HAL_SuspendTick();
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
HAL_ResumeTick();

 

 

this works ok as long as I don't use //HAL_PWR_DisableBkUpAccess(); or it never enters stop mode

now I use HAL_PWR_EnterSTANDBYMode(); to shutdown the device but it wakes 20 seconds later.

so I tried adding

 

 

if (HAL_RTCEx_DeactivateWakeUpTimer(&hrtc) != HAL_OK)
{									
 ErrorHandler(ERR_ALARM_DEACT);
}

 

 

 but the call returns HAL_RTC_STATE_TIMEOUT

 

Any ideas?

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

    OK as none has commented here I will fill in the solution, it looks like I was calling

    HAL_PWR_DisableBkUpAccess();

    in another place I did not realise and this was stopping

    (HAL_RTCEx_DeactivateWakeUpTimer(&hrtc) != HAL_OK)

    from completing without error.

    I find it strange that wakeup timer is dependant on backup register access being disabled, I would not expect this behavior and no note in the function header to inform users this is so.

    "@note  Ensure HAL_PWR_EnableBkUpAccess is called before this function" would be helpful.

    1 reply

    markHAuthorAnswer
    Visitor II
    July 1, 2024

    OK as none has commented here I will fill in the solution, it looks like I was calling

    HAL_PWR_DisableBkUpAccess();

    in another place I did not realise and this was stopping

    (HAL_RTCEx_DeactivateWakeUpTimer(&hrtc) != HAL_OK)

    from completing without error.

    I find it strange that wakeup timer is dependant on backup register access being disabled, I would not expect this behavior and no note in the function header to inform users this is so.

    "@note  Ensure HAL_PWR_EnableBkUpAccess is called before this function" would be helpful.