@@ -390,6 +390,62 @@ static void set_regu_voltage(uint32_t hclk_freq)
390
390
}
391
391
}
392
392
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
+
393
449
__unused
394
450
static void clock_switch_to_hsi (void )
395
451
{
@@ -432,8 +488,7 @@ static int set_up_plls(void)
432
488
433
489
LL_RCC_PLL1_Disable ();
434
490
435
- /* Configure PLL source */
436
- /* Can be HSE , HSI MSI */
491
+ /* Configure PLL source : Can be HSE, HSI, MSIS */
437
492
if (IS_ENABLED (STM32_PLL_SRC_HSE )) {
438
493
/* Main PLL configuration and activation */
439
494
LL_RCC_PLL1_SetMainSource (LL_RCC_PLL1SOURCE_HSE );
@@ -447,13 +502,21 @@ static int set_up_plls(void)
447
502
return - ENOTSUP ;
448
503
}
449
504
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
+
450
512
r = get_vco_input_range (STM32_PLL_M_DIVISOR , & vco_input_range , PLL1_ID );
451
513
if (r < 0 ) {
452
514
return r ;
453
515
}
454
516
455
517
LL_RCC_PLL1_SetDivider (STM32_PLL_M_DIVISOR );
456
518
519
+ /* Set VCO Input before enabling the PLL, depends on freq used for PLL1 */
457
520
LL_RCC_PLL1_SetVCOInputRange (vco_input_range );
458
521
459
522
LL_RCC_PLL1_SetN (STM32_PLL_N_MULTIPLIER );
0 commit comments