Clock Configuration Issue: HAL_RCC_OscConfig HAL_TIMEOUT Error
Hello ST Community,
I am encountering a clock configuration issue that I need assistance with.
I initially began with a blank template using an internal clock, and the code ran without any problems. However, when I attempted to configure a 24MHz external oscillator, I encountered an error loop during debugging. Here's the sequence of events:
- Started with a blank template using an internal clock - Code ran as expected without any issues.
- Configured the clock tree to use a 24MHz external oscillator, set the main clock rate to 170MHz, and allowed the clock tree to resolve the rest.
- Compiled and uploaded the code again, but it failed to progress beyond the SystemClock_Config stage.
Upon investigating further, I discovered that the HSE ready bit is not set in time for some reason during the clock configuration. As a result, HAL_RCC_OscConfig() returned HAL_TIMEOUT, leading the program into an error loop. I tried Increasing the timeout value from 100 to 1000 but it didn't help.
/* Wait till HSE is ready */
while (READ_BIT(RCC->CR, RCC_CR_HSERDY) == 0U)
{
if ((HAL_GetTick() - tickstart) > HSE_TIMEOUT_VALUE)
{
return HAL_TIMEOUT;
}
}
My clock tree is shown below:

I also recorded a 5-minute video of my process:
The code is uploaded in the zip attachment
I faced the same issue on two brand-new G431KB NUCLEO boards. I would appreciate any insights, suggestions, or guidance on resolving this issue. If anyone has encountered a similar problem or has expertise in clock configuration on this platform, your assistance would be invaluable.


