2025-06-23 5:17 AM
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:
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.
2025-06-24 1:56 AM
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!
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2025-06-25 2:55 AM
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.
2025-06-27 3:28 AM
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.