2023-09-12 07:18 AM
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
Solved! Go to Solution.
2023-09-12 09:13 AM
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.
2023-09-12 07:28 AM
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.
2023-09-12 07:29 AM
What chip are you using?
HAL_RCC_DeInit should reset clock to default.
2023-09-12 08:26 AM
Hello,
I am using a STM32G0 MCU and the following software package:
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().
2023-09-12 09:13 AM
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.
2023-09-12 11:46 PM
Thank you very much!