2026-01-07 4:53 AM - last edited on 2026-01-07 5:00 AM by Andrew Neil
I’m working with an STM32F103RCT6 on a custom board, and I’m trying to use the built-in RTC using ST Low-Layer (LL) drivers.
When I enter debug mode, the application gets stuck inside LL_RTC_Init(). It neither returns SUCCESS nor ERROR — it keeps looping internally, apparently waiting for a flag that never gets set.
Here is the function from my application:
void LL_RTC_Init_Custom()
{ // TODO: RTC clock needs to be set to LSE. On the dev kit, LSE isn't available
LL_RTC_InitTypeDef rtcInit =
{ .AsynchPrescaler = RTC_CLK_PRESCALE, .OutPutSource = LL_RTC_CALIB_OUTPUT_NONE };
ErrorStatus status = LL_RTC_Init(RTC, &rtcInit);
if (status != SUCCESS)
Error_Handler();
}Inside this function, it stucks here, in this while loop below.
ErrorStatus LL_RTC_ExitInitMode(RTC_TypeDef *RTCx)
{
__IO uint32_t timeout = RTC_INITMODE_TIMEOUT;
ErrorStatus status = SUCCESS;
uint32_t tmp = 0U;
/* Check the parameter */
assert_param(IS_RTC_ALL_INSTANCE(RTCx));
/* Disable initialization mode */
LL_RTC_EnableWriteProtection(RTCx);
/* Wait till RTC is in INIT state and if Time out is reached exit */
tmp = LL_RTC_IsActiveFlag_RTOF(RTCx);
while ((timeout != 0U) && (tmp != 1U))
{
if (LL_SYSTICK_IsActiveCounterFlag() == 1U)
{
timeout --;
}
tmp = LL_RTC_IsActiveFlag_RTOF(RTCx);
if (timeout == 0U)
{
status = ERROR;
}
}
return status;
}While debugging, it looks like LL_RTC_Init() is waiting on a ready flag (likely related to RTC clock or synchronization), but in reality that flag never becomes set, so the code loops forever.
Some additional context:
Custom board, not an ST dev kit
Using LL drivers, not HAL
RTC clock is intended to be LSE, but I suspect LSE may not be running or available
Backup domain access and RTC clock configuration may be relevant
My questions:
Is this behavior expected if LSE is not present or not oscillating?
Does LL_RTC_Init() block indefinitely if the RTC clock source is invalid?
If I leave the Vbat pin unconnected, can RTC still work? since the Vdd is present.
If the 3.3 appears at the Vbat pin can I rule out all the power related issues?
Any guidance or debugging tips would be appreciated.
Thanks in advance.
Edited to apply source code formatting - please see How to insert source code for future reference.
2026-01-07 5:01 AM - edited 2026-01-07 6:26 AM
@Zaeem-Ahmed wrote:
Custom board, not an ST dev kit
So you'll need to give details of your board - schematics, etc:
How to write your question to maximize your chances to find a solution
PS:
Also, have you tried this on an ST board - to rule out any hardware issues?
And Using ST Examples?