From abc3fec255ebb26a79baff7b4d40cc003fdc59f8 Mon Sep 17 00:00:00 2001 From: Francois Ramu Date: Thu, 15 May 2025 16:44:44 +0200 Subject: [PATCH] drivers: clock control: stm32H7 has the same clock source for all PLL Select the PLL clock source for PLL2 or PLL3 as well as main PLL This choice is useful if main PLL is off (sysclock from fixed clock) but PLL2 or PLL3 are on for other peripherals All PLL must have the same source else this is an error. Signed-off-by: Francois Ramu --- drivers/clock_control/clock_stm32_ll_h7.c | 36 ++++++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/drivers/clock_control/clock_stm32_ll_h7.c b/drivers/clock_control/clock_stm32_ll_h7.c index 5d6bcb72fa9..bedacd9222c 100644 --- a/drivers/clock_control/clock_stm32_ll_h7.c +++ b/drivers/clock_control/clock_stm32_ll_h7.c @@ -53,15 +53,29 @@ /* This check should only be performed for the M7 core code */ #ifdef CONFIG_CPU_CORTEX_M7 -/* Choose PLL SRC */ -#if defined(STM32_PLL_SRC_HSI) +/* Choose PLL SRC : same source for all the PLL */ +#if defined(STM32_PLL_SRC_HSI) || defined(STM32_PLL2_SRC_HSI) || defined(STM32_PLL3_SRC_HSI) #define PLLSRC_FREQ ((STM32_HSI_FREQ)/(STM32_HSI_DIVISOR)) -#elif defined(STM32_PLL_SRC_CSI) +#endif + +#if defined(STM32_PLL_SRC_CSI) || defined(STM32_PLL2_SRC_CSI) || defined(STM32_PLL3_SRC_CSI) +#if !defined(PLLSRC_FREQ) #define PLLSRC_FREQ STM32_CSI_FREQ -#elif defined(STM32_PLL_SRC_HSE) +#else +#error "All PLLs must have the same clock source" +#endif +#endif + +#if defined(STM32_PLL_SRC_HSE) || defined(STM32_PLL2_SRC_HSE) || defined(STM32_PLL3_SRC_HSE) +#if !defined(PLLSRC_FREQ) #define PLLSRC_FREQ STM32_HSE_FREQ #else -#define PLLSRC_FREQ 0 +#error "All PLLs must have the same clock source" +#endif +#endif + +#if !defined(PLLSRC_FREQ) +#define PLLSRC_FREQ 0 #endif /* Given source clock and dividers, computed the output frequency of PLLP */ @@ -782,13 +796,19 @@ static int set_up_plls(void) /* Configure PLL source */ /* Can be HSE , HSI 64Mhz/HSIDIV, CSI 4MHz*/ - if (IS_ENABLED(STM32_PLL_SRC_HSE)) { + if (IS_ENABLED(STM32_PLL_SRC_HSE) || + IS_ENABLED(STM32_PLL2_SRC_HSE) || + IS_ENABLED(STM32_PLL3_SRC_HSE)) { /* Main PLL configuration and activation */ LL_RCC_PLL_SetSource(LL_RCC_PLLSOURCE_HSE); - } else if (IS_ENABLED(STM32_PLL_SRC_CSI)) { + } else if (IS_ENABLED(STM32_PLL_SRC_CSI) || + IS_ENABLED(STM32_PLL2_SRC_CSI) || + IS_ENABLED(STM32_PLL3_SRC_CSI)) { /* Main PLL configuration and activation */ LL_RCC_PLL_SetSource(LL_RCC_PLLSOURCE_CSI); - } else if (IS_ENABLED(STM32_PLL_SRC_HSI)) { + } else if (IS_ENABLED(STM32_PLL_SRC_HSI) || + IS_ENABLED(STM32_PLL2_SRC_HSI) || + IS_ENABLED(STM32_PLL3_SRC_HSI)) { /* Main PLL configuration and activation */ LL_RCC_PLL_SetSource(LL_RCC_PLLSOURCE_HSI); } else {