Skip to main content
Visitor II
March 19, 2025
Question

how get the remaining time of RTC wakeup timer

  • March 19, 2025
  • 2 replies
  • 710 views

STM 32L 051 

use HAL_RTCEx_SetWakeUpTimer_IT() to wake up standby mode,it is work well.

when the wake up source is not RTC(maybe wkup pin  or NRST pin) ,how get the remaining time of RTC timer?

The value of HAL_RTCEx_GetWakeUpTimer() is not change.it is the value of HAL_RTCEx_SetWakeUpTimer_IT() set.

    This topic has been closed for replies.

    2 replies

    Technical Moderator
    March 19, 2025
    jinyi7016Author
    Visitor II
    March 20, 2025

    thanks reply. 

    HAL_RTC_GetTime() can get the calendar time to calculate the remaining time.

    but I really want to know:

    1、

    Can function HAL_RTCEx_GetWakeUpTimer()    get the remaining time of RTC timer? or only the value  HAL_RTCEx_SetWakeUpTimer_IT() set.

     

     

     

    Technical Moderator
    March 21, 2025

    Hello @jinyi7016 

    The function HAL_RTCEx_GetWakeUpTimer() get just the value of WUTR register previously set with the function HAL_RTCEx_SetWakeUpTimer_IT(). 

    Please refer to the UM174 more details.

    Saket_Om_0-1742546765122.png

     

     

    ST Employee
    March 21, 2025

    Hi @jinyi7016,

    Here is a solution. However, it supposes you are not using the RTC Calendar, only the RTC WUT (Wake-Up Timer).

    To better illustrate it, I join the figure below adapted from the reference manual of the STM32L0 series. The idea is the following:

    • manage to tune the RTC's prescalers to make the RTC_SSR register synchronous with the WUT counter,
    • read the RTC_SSR register once the WUT counter is launched, then when we want to know the current value of the WUT counter, to finally calculate the difference.

    There are two cases:

    1. The source clock of the wake-up timer is the RTC's clock source RTCCLK (HSE, LSE, or LSI clock) divided by the WUT prescaler.
    2. The source clock of the wake-up timer must be the RTC's asynchronous prescaler counter.

    Let's dive into the details and steps:

    1. The source clock of the wake-up timer is the RTC's clock source RTCCLK (HSE, LSE, or LSI clock) divided by the WUT prescaler.
      • For this, WUCKSEL[2:0] = 0xx in the RTC_CR register.
      • Make the RTC_SSR register synchronous with the WUT counter. For this:

        • Set the synchronous prescaler to 0. For this, PREDIV_S[14:0] = 0 in the RTC_PRER register.
        • Set the asynchronous prescaler to the same value as the WUT prescaler. For this,
          • PREDIV_A[6:0] = 15 in the RTC_PRER register if WUCKSEL[2:0] = 000xb in the RTC_CR register.
          • PREDIV_A[6:0] = 7   in the RTC_PRER register if WUCKSEL[2:0] = 001xb in the RTC_CR register. 
          • PREDIV_A[6:0] = 3   in the RTC_PRER register if WUCKSEL[2:0] = 010xb in the RTC_CR register. 
          • PREDIV_A[6:0] = 1   in the RTC_PRER register if WUCKSEL[2:0] = 011xb in the RTC_CR register. 
    2.  The source clock of the wake-up timer must be the RTC's asynchronous prescaler counter.
      • For this, WUCKSEL[2:0] = 1xx in the RTC_CR register.
      • Make the RTC_SSR register synchronous with the WUT counter. For this:
        • Set the synchronous prescaler to 0. For this, PREDIV_S[14:0] = 0 in the RTC_PRER register.

     

    Now, to estimate the current value in the WUT counter:

    • Read the RTC_SSR register when the WUT counter is launched at t=0µs.
    • Read the RTC_SSR register at t>0µs.
    • Calculate the difference.

     

    I hope this helps.

    With regards,

     

    ALABSTM_1-1742568920962.png