Skip to content

Commit 687330a

Browse files
FRASTMfabiobaltieri
authored andcommitted
drivers: clock_control: stm32u5 enables the EPOD
With the stm32U5, when the sysclock is > 55 MHz, the EPOD booster must be configured before the PLL1 is enabled (see refMan). This is the case when sysclock is on PLL1 sourced by MSIS or HSE higher than 16MHz. Signed-off-by: Francois Ramu <[email protected]>
1 parent 055c1c6 commit 687330a

File tree

1 file changed

+65
-2
lines changed

1 file changed

+65
-2
lines changed

drivers/clock_control/clock_stm32_ll_u5.c

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,62 @@ static void set_regu_voltage(uint32_t hclk_freq)
390390
}
391391
}
392392

393+
#if defined(STM32_PLL_ENABLED)
394+
/*
395+
* Dynamic voltage scaling:
396+
* Enable the Booster mode before enabling then PLL for sysclock above 55MHz
397+
* The goal of this function is to set the epod prescaler, so that epod clock freq
398+
* is between 4MHz and 16MHz.
399+
* Up to now only MSI as PLL1 source clock can be > 16MHz, requiring a epod prescaler > 1
400+
* For HSI16, epod prescaler is default (div1, not divided).
401+
* Once HSE is > 16MHz, the epod prescaler would also be also required.
402+
*/
403+
static void set_epod_booster(void)
404+
{
405+
/* Reset Epod Prescaler in case it was set earlier with another DIV value */
406+
LL_PWR_DisableEPODBooster();
407+
while (LL_PWR_IsActiveFlag_BOOST() == 1) {
408+
}
409+
410+
LL_RCC_SetPll1EPodPrescaler(LL_RCC_PLL1MBOOST_DIV_1);
411+
412+
if (MHZ(55) <= CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC) {
413+
/*
414+
* Set EPOD clock prescaler based on PLL1 input freq
415+
* (MSI/PLLM or HSE/PLLM when HSE is > 16MHz
416+
* Booster clock frequency should be between 4 and 16MHz
417+
* This is done in following steps:
418+
* Read MSI Frequency or HSE oscillaor freq
419+
* Divide PLL1 input freq (MSI/PLL or HSE/PLLM)
420+
* by the targeted freq (8MHz).
421+
* Make sure value is not higher than 16
422+
* Shift in the register space (/2)
423+
*/
424+
int tmp;
425+
426+
if (IS_ENABLED(STM32_PLL_SRC_MSIS)) {
427+
tmp = __LL_RCC_CALC_MSIS_FREQ(LL_RCC_MSIRANGESEL_RUN,
428+
STM32_MSIS_RANGE << RCC_ICSCR1_MSISRANGE_Pos);
429+
} else if (IS_ENABLED(STM32_PLL_SRC_HSE) && (MHZ(16) < STM32_HSE_FREQ)) {
430+
tmp = STM32_HSE_FREQ;
431+
} else {
432+
return;
433+
}
434+
435+
tmp = MIN(tmp / STM32_PLL_M_DIVISOR / 8000000, 16);
436+
tmp = tmp / 2;
437+
438+
/* Configure the epod clock frequency between 4 and 16 MHz */
439+
LL_RCC_SetPll1EPodPrescaler(tmp << RCC_PLL1CFGR_PLL1MBOOST_Pos);
440+
441+
/* Enable EPOD booster and wait for booster ready flag set */
442+
LL_PWR_EnableEPODBooster();
443+
while (LL_PWR_IsActiveFlag_BOOST() == 0) {
444+
}
445+
}
446+
}
447+
#endif /* STM32_PLL_ENABLED */
448+
393449
__unused
394450
static void clock_switch_to_hsi(void)
395451
{
@@ -432,8 +488,7 @@ static int set_up_plls(void)
432488

433489
LL_RCC_PLL1_Disable();
434490

435-
/* Configure PLL source */
436-
/* Can be HSE , HSI MSI */
491+
/* Configure PLL source : Can be HSE, HSI, MSIS */
437492
if (IS_ENABLED(STM32_PLL_SRC_HSE)) {
438493
/* Main PLL configuration and activation */
439494
LL_RCC_PLL1_SetMainSource(LL_RCC_PLL1SOURCE_HSE);
@@ -447,13 +502,21 @@ static int set_up_plls(void)
447502
return -ENOTSUP;
448503
}
449504

505+
/*
506+
* Configure the EPOD booster
507+
* before increasing the system clock freq
508+
* and after pll clock source is set
509+
*/
510+
set_epod_booster();
511+
450512
r = get_vco_input_range(STM32_PLL_M_DIVISOR, &vco_input_range, PLL1_ID);
451513
if (r < 0) {
452514
return r;
453515
}
454516

455517
LL_RCC_PLL1_SetDivider(STM32_PLL_M_DIVISOR);
456518

519+
/* Set VCO Input before enabling the PLL, depends on freq used for PLL1 */
457520
LL_RCC_PLL1_SetVCOInputRange(vco_input_range);
458521

459522
LL_RCC_PLL1_SetN(STM32_PLL_N_MULTIPLIER);

0 commit comments

Comments
 (0)