cancel
Showing results for 
Search instead for 
Did you mean: 

Clock config fails if using debug and external loader (HAL_RCC_OscConfig() problem?)

TMack.1
Associate II

I have a touchGFX project (created using the STM32G071RB Nucleo AZ1 board setup) which, if run under debug (cubeIDE), will fail during SystemClock_Config(). This needs an external loader to program the external flash.

If I perform a hardware reset the code runs fine.

After a bit of debugging I have found that the problem appears to be with HAL_RCC_OscConfig(). The application is setting the clock to HSI with PLL. If HAL_RCC_OscConfig detects that HSI with PLL is already set then it only checks if the PLL is set correctly and fails with HAL_ERROR if it is not. It would appear that something (I assume the external loader) is also using HSI with PLL but with different PLL settings. So the application clock setup fails.

If I do a hardware reset then the loader is obviously not used and the clocks are in the reset state so HAL_RCC_OscConfig works ok.

To fix this I have set the clock source to HSI (no pll) before SystemClock_Config (eg RCC->CFGR = 0;) to force HAL_RCC_OscConfig to update the RCC correctly.

Am I missing something? Is this a bug in HAL_RCC_OscConfig or is there a reason it behaves this way?

Thanks, Toby

1 ACCEPTED SOLUTION

Accepted Solutions

Probably because the PLL can't be changed on-the-fly.

Rather than make the libraries massively complex for all corner cases, there's an expectation that you'll call it in Reset conditions, or walk it through some safe intermediate states, based on your understanding of the available clocks, and if a boot loader​ already brought the system up.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

2 REPLIES 2

Probably because the PLL can't be changed on-the-fly.

Rather than make the libraries massively complex for all corner cases, there's an expectation that you'll call it in Reset conditions, or walk it through some safe intermediate states, based on your understanding of the available clocks, and if a boot loader​ already brought the system up.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
TMack.1
Associate II

That makes sense, thanks.