2025-03-22 1:55 PM
Hi,
I’m working with an STM32H743 and trying to use the RTC. Everything works fine using the LSI, but when I try to use the LSE (with an external oscillator permanently connected to VBAT to keep track of time even when the system is powered off), I cannot initialize the clock. I get a timeout during the LSE initialization. The clock is working correctly, and the signal is a perfect square wave at 32.768Hz as observed with the oscilloscope.
What’s strange is that sometimes, if I configure the microcontroller to use the LSI and then reprogram it to use the LSE while it's running, it successfully restarts after reprogramming without any timeout. The problem only occurs when I power off and restart the board; it seems like the CPU doesn't recognize that the clock is already running before it's activated, or something similar. It’s very strange.
Here is the code that initializes everything correctly:
/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48 | RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = 2;
RCC_OscInitStruct.PLL.PLLN = 64;
RCC_OscInitStruct.PLL.PLLP = 2;
RCC_OscInitStruct.PLL.PLLQ = 10;
RCC_OscInitStruct.PLL.PLLR = 4;
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_3;
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
RCC_OscInitStruct.PLL.PLLFRACN = 0;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
If I change just these two lines (the only change from CubeMX), the clock doesn’t start, and I get a timeout:
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48 | RCC_OSCILLATORTYPE_LSE | RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.LSEState = RCC_LSE_BYPASS;
The RTC initialization also changes to use the LSE, but it doesn’t even reach that point. The error occurs during the clock initialization, not the peripheral initialization.
The following code (in the stm32h7xx_hal_rcc.c) where the error happens and causes the timeout:
/* Set the new LSE configuration -----------------------------------------*/
__HAL_RCC_LSE_CONFIG(RCC_OscInitStruct->LSEState);
/* Check the LSE State */
if ((RCC_OscInitStruct->LSEState) != RCC_LSE_OFF)
{
/* Get Start Tick*/
tickstart = HAL_GetTick();
/* Wait till LSE is ready */
while (__HAL_RCC_GET_FLAG(RCC_FLAG_LSERDY) == 0U)
{
if ((HAL_GetTick() - tickstart) > RCC_LSE_TIMEOUT_VALUE)
{
return HAL_TIMEOUT;
}
}
}
I wouldn’t dare say it’s a bug, but I can’t find anywhere where the issue might be. The clock applied to the PC14-OSC32 IN pin is correct, with a perfect square wave. I’m not sure if using an oscillator instead of a crystal or resonator in this way could cause any problems under these conditions, but this is such a basic configuration, entirely standard.
Can anyone help me with this?
2025-03-22 2:14 PM - edited 2025-03-23 3:32 AM
Hi,
which 743 ? 144 pin ? custom board ? whats on PDR_ON pin ?
+
Set HSE drive to high. (RCC -> parameters -> LSE .. high drive )
2025-03-22 2:20 PM
All signs point to the LSE clock source not being ready in time. Seems like you're doing things correctly.
Is the signal compatible with the logic levels the chip expects? What is the part number of the chip generating the signal? Does it take 5 seconds before the LSE times out?
2025-03-23 4:44 AM
Hi,
The CPU is the H743XIH6, TFBGA-240 on a custom board. PDR_ON is pulled up to +3V3, and AFAIK, this has nothing to do with the RCC.
About the high drive: it’s an external oscillator, so it does not need drive configuration.
Thanks
2025-03-23 4:49 AM
Hi,
Regarding the clock not being ready in time: it’s an oscillator that never stops, it’s ready before the CPU even boots, and that’s what I can’t understand.
The external clock is this part: https://ecsxtal.com/store/pdf/ECS-327TXO.pdf and the signal levels are, of course, compatible. The timeout occurs according to the value set in "LSE Startup Timeout Value (ms)", whether it’s 5s, 10s, it doesn’t matter.
Thanks!
2025-03-23 4:58 AM
...no, >nothing to do with the RCC , it has ! RCC floating...gives what you see. (I tried...unintentionally.)
So you have a battery for the lse + Vbat , or not ?
2025-03-23 6:52 AM
I have a supercap for Vbat and for the oscillator, yes.
2025-03-23 7:15 AM
Could be a manufacturing issue, maybe an issue at the PC14 pin.
Configure PC14 as a regular GPIO input and verify the 14th bit in GPIOC->IDR toggles between 0 and 1.