cancel
Showing results for 
Search instead for 
Did you mean: 

System clock restore to default

CTabo.1
Senior

Hello,
I need to restore the system clock to its default state, after it has been configured to generate 64MHz clock signal from an external 24MHz oscillator.

I used the HAL_RCC_DeInit() function, that seems to do most of the job, but not all apparently.

Some register, indeed, mantains the 64 MHz configuration value.
For example the main regulator output voltage settings (PWR->CR1.PWR_CR1_VOS), and flash wait states are not restored to default values.

Is it problem?
Is it enough to call HAL_RCC_DeInit(), or I need to call some other functions to complete the clock restore operation?

Thank you,
Carlo

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

Yes, it looks like HAL_RCC_DeInit in this family does not reset wait states back to normal. On other families, it does.

If wait states and VOS setting are important, you can set these explicitly with a call to the appropriate functions.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

5 REPLIES 5

You don't mention a part.

Enable the HSI or MSI clock source, and configure the RCC to use/switch to that as the SYSCLK source.

Check also flash wait states, and APB/AHB clock dividers AFTER you've switched clocks. Then turn OFF HSE, PLL, etc.

Perhaps look at the RCC configuration in the Reference Manual, and registers at startup, to understand what's happening or needed, rather than rely of HAL code to hide all of the salient details. The Manuals also tend to go into the detail and order things need to occur.

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

What chip are you using?

HAL_RCC_DeInit should reset clock to default.

If you feel a post has answered your question, please click "Accept as Solution".

Hello,

I am using a STM32G0 MCU and the following software package:

CTabo1_0-1694532020673.png

During clock configuration, the clock initialization routine, generated by CubeMx, calls the following APIs:

- HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);

- HAL_RCC_ClockConfig() -> __HAL_FLASH_SET_LATENCY(FLatency);

The register settings performed by this functions aren't restored from HAL_RCC_DeInit().

 

 

TDK
Guru

Yes, it looks like HAL_RCC_DeInit in this family does not reset wait states back to normal. On other families, it does.

If wait states and VOS setting are important, you can set these explicitly with a call to the appropriate functions.

If you feel a post has answered your question, please click "Accept as Solution".

Thank you very much!