stm32/powerctrl: Don't configure clocks if already at desired frequency.
Configuring clocks is a critical operation and is best to avoid when possible. If the clocks really need to be reset to the same values then one can pass in a slightly higher value, eg 168000001 Hz to get 168MHz.
This commit is contained in:
parent
bc54c57590
commit
6ea6c7cc9e
@ -128,6 +128,14 @@ STATIC uint32_t calc_apb_div(uint32_t wanted_div) {
|
||||
}
|
||||
|
||||
int powerctrl_set_sysclk(uint32_t sysclk, uint32_t ahb, uint32_t apb1, uint32_t apb2) {
|
||||
// Return straightaway if the clocks are already at the desired frequency
|
||||
if (sysclk == HAL_RCC_GetSysClockFreq()
|
||||
&& ahb == HAL_RCC_GetHCLKFreq()
|
||||
&& apb1 == HAL_RCC_GetPCLK1Freq()
|
||||
&& apb2 == HAL_RCC_GetPCLK2Freq()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Default PLL parameters that give 48MHz on PLL48CK
|
||||
uint32_t m = HSE_VALUE / 1000000, n = 336, p = 2, q = 7;
|
||||
uint32_t sysclk_source;
|
||||
|
Loading…
x
Reference in New Issue
Block a user