Skip to content

Commit d409100

Browse files
erwangonashif
authored andcommitted
drivers/clock_control: stm32wl: Consider new options for HSE clock
On STM32WL, HSE clock can take 2 specific options: -hse-tcxo -hse-div2 Enable support for these options. Signed-off-by: Erwan Gouriou <[email protected]>
1 parent 05fbf57 commit d409100

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

drivers/clock_control/clock_stm32_ll_common.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -486,18 +486,24 @@ int stm32_clock_control_init(const struct device *dev)
486486
LL_RCC_MSI_Disable();
487487

488488
#elif STM32_PLL_SRC_HSE
489-
int hse_bypass;
490489

490+
#ifndef CONFIG_SOC_SERIES_STM32WLX
491+
int hse_bypass;
491492
if (IS_ENABLED(STM32_HSE_BYPASS)) {
492493
hse_bypass = LL_UTILS_HSEBYPASS_ON;
493494
} else {
494495
hse_bypass = LL_UTILS_HSEBYPASS_OFF;
495496
}
497+
#else
498+
if (IS_ENABLED(STM32_HSE_TCXO)) {
499+
LL_RCC_HSE_EnableTcxo();
500+
}
501+
if (IS_ENABLED(STM32_HSE_DIV2)) {
502+
LL_RCC_HSE_EnableDiv2();
503+
}
504+
#endif
496505

497506
/* Switch to PLL with HSE as clock source */
498-
#ifdef CONFIG_SOC_SERIES_STM32WLX
499-
LL_RCC_HSE_EnableTcxo();
500-
#endif
501507
LL_PLL_ConfigSystemClock_HSE(
502508
#if !defined(CONFIG_SOC_SERIES_STM32WBX) && !defined(CONFIG_SOC_SERIES_STM32WLX)
503509
CONFIG_CLOCK_STM32_HSE_CLOCK,
@@ -520,8 +526,14 @@ int stm32_clock_control_init(const struct device *dev)
520526
GET_CURRENT_FLASH_PRESCALER());
521527

522528
/* Calculate new SystemCoreClock variable based on HSE freq */
523-
new_hclk_freq = __LL_RCC_CALC_HCLK_FREQ(CONFIG_CLOCK_STM32_HSE_CLOCK,
524-
hclk_prescaler);
529+
uint32_t hse_freq;
530+
if (IS_ENABLED(STM32_HSE_DIV2)) {
531+
hse_freq = CONFIG_CLOCK_STM32_HSE_CLOCK / 2;
532+
} else {
533+
hse_freq = CONFIG_CLOCK_STM32_HSE_CLOCK;
534+
}
535+
new_hclk_freq = __LL_RCC_CALC_HCLK_FREQ(hse_freq, hclk_prescaler);
536+
525537
#if defined(CONFIG_SOC_SERIES_STM32WBX) || defined(CONFIG_SOC_SERIES_STM32WLX)
526538
new_flash_freq = RCC_CALC_FLASH_FREQ(CONFIG_CLOCK_STM32_HSE_CLOCK,
527539
flash_prescaler);
@@ -542,18 +554,18 @@ int stm32_clock_control_init(const struct device *dev)
542554

543555
/* Enable HSE if not enabled */
544556
if (LL_RCC_HSE_IsReady() != 1) {
545-
/* Check if need to enable HSE bypass feature or not */
546-
if (IS_ENABLED(STM32_HSE_BYPASS)) {
547557
#ifdef CONFIG_SOC_SERIES_STM32WLX
558+
if (IS_ENABLED(STM32_HSE_TCXO)) {
548559
LL_RCC_HSE_EnableTcxo();
549-
} else {
550-
LL_RCC_HSE_DisableTcxo();
560+
}
551561
#else
562+
/* Check if need to enable HSE bypass feature or not */
563+
if (IS_ENABLED(STM32_HSE_BYPASS)) {
552564
LL_RCC_HSE_EnableBypass();
553565
} else {
554566
LL_RCC_HSE_DisableBypass();
555-
#endif
556567
}
568+
#endif
557569

558570
/* Enable HSE */
559571
LL_RCC_HSE_Enable();

0 commit comments

Comments
 (0)