Skip to main content
Visitor II
June 23, 2025
Question

APB clock to RTC required for the RTC to be able to wake from sleep?

  • June 23, 2025
  • 1 reply
  • 425 views

I find that I need to enable the APB clock to the RTC during sleep (i.e. by setting the RTCAPBSMEN bit in the RCC APBSMENR1 register) otherwise my code won’t wake after calling __WFI(); is the AI explanation below correct? The AI also says it’s EXTI line 20, whereas the manual (RM0503 Rev. 2) indicates RTC on 28 and TAMP on 29, so I assume it’s wrong about that?

The AI answer:

  • In Sleep mode, the CPU is halted but the APB bus remains active — if the corresponding APBSMEN bits are set.
  • If RTCAPBSMEN is cleared, the RTC peripheral’s APB interface is clock-gated, meaning you can’t access its registers — and more importantly, EXTI line 20 won’t see the RTC wakeup event, because the EXTI-RCC bridge path is broken.

So even though the RTC’s core logic is ticking away on LSE, the event routing to EXTI and the ability to clear flags depends on that APB interface being live.

    This topic has been closed for replies.

    1 reply

    ST Employee
    June 24, 2025

    Hello @kswST

    The RTC requires the APB clock to be enabled to distribute the PCLK and handle interrupts in the synchronous domain, you can do this using the macro __HAL_RCC_RTCAPB_CLKAM_ENABLE()

    for the dedicated EXTI line, you have to check the RM, AI's reference is incorrect!

    SarraS_0-1750688652626.png

     

    kswSTAuthor
    Visitor II
    June 25, 2025

    Thanks – I can’t find the macro __HAL_RCC_RTCAPB_CLKAM_ENABLE() – which file is it contained in for the STM32U031 library?

    But regardless of that, my problem is that I find my STM32U031 (and also an STM32u083 I tried) will only wake if the APB clock is enabled during sleep (by setting the RTCAPBSMEN) so the AI response seems reasonable to me, i.e. the wakeup isn’t getting through to the relevent blocks (presumably the EXTI) unless the APB clock to the RTC is enabled during sleep. I can live with this, although I would like to minimise current consumption by turning off all unneccesary clock in sleep.

    kswSTAuthor
    Visitor II
    June 27, 2025

    I asked my AI chum about __HAL_RCC_RTCAPB_CLKAM_ENABLE() and it said:

    “If you're just entering Sleep mode, where the CPU clock is off but most peripherals (including the RTC) can still operate normally, you typically don't need to enable the RTC in autonomous mode. However, for deeper low-power modes like Stop or Standby, enabling the RTC clock autonomously ensures it remains functional even when the main system clocks are gated.”

    My question is regarding the necessity for the RTC APB clock to run during sleep to allow it to wake the CPU, which appears to be the case from my tests.