Skip to content

Commit f1a4928

Browse files
FRASTMkartben
authored andcommitted
drivers: clock control: stm32 function to get 48MHz freq
Add a function to compute the clock48 from the clock tree of a stm32f412/f413 mcu. The value depends on its clock source Requires to identify the PLL source HSE or HSI. Signed-off-by: Francois Ramu <[email protected]>
1 parent 7044876 commit f1a4928

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

drivers/clock_control/clock_stm32_ll_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ static int stm32_clock_control_get_subsys_rate(const struct device *clock,
483483
#endif /* STM32_HSI48_ENABLED */
484484
#if defined(STM32_CK48_ENABLED)
485485
case STM32_SRC_CK48:
486-
*rate = STM32_CK48_FREQ;
486+
*rate = get_ck48_frequency();
487487
break;
488488
#endif /* STM32_CK48_ENABLED */
489489

drivers/clock_control/clock_stm32_ll_common.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ void config_enable_default_clocks(void);
6161
void config_regulator_voltage(uint32_t hclk_freq);
6262
int enabled_clock(uint32_t src_clk);
6363

64+
#if defined(STM32_CK48_ENABLED)
65+
uint32_t get_ck48_frequency(void);
66+
#endif
67+
6468
/* functions exported to the soc power.c */
6569
int stm32_clock_control_init(const struct device *dev);
6670
void stm32_clock_control_standby_exit(void);

drivers/clock_control/clock_stm32f2_f4_f7.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,46 @@ uint32_t get_pllsrc_frequency(void)
5050
return 0;
5151
}
5252

53+
#if defined(STM32_CK48_ENABLED)
54+
/**
55+
* @brief calculate the CK48 frequency depending on its clock source
56+
*/
57+
__unused
58+
uint32_t get_ck48_frequency(void)
59+
{
60+
uint32_t source;
61+
62+
if (LL_RCC_GetCK48MClockSource(LL_RCC_CK48M_CLKSOURCE) ==
63+
LL_RCC_CK48M_CLKSOURCE_PLL) {
64+
/* Get the PLL48CK source : HSE or HSI */
65+
source = (LL_RCC_PLL_GetMainSource() == LL_RCC_PLLSOURCE_HSE)
66+
? HSE_VALUE
67+
: HSI_VALUE;
68+
/* Get the PLL48CK Q freq. No HAL macro for that */
69+
return __LL_RCC_CALC_PLLCLK_48M_FREQ(source,
70+
LL_RCC_PLL_GetDivider(),
71+
LL_RCC_PLL_GetN(),
72+
LL_RCC_PLL_GetQ()
73+
);
74+
} else if (LL_RCC_GetCK48MClockSource(LL_RCC_CK48M_CLKSOURCE) ==
75+
LL_RCC_CK48M_CLKSOURCE_PLLI2S) {
76+
/* Get the PLL I2S source : HSE or HSI */
77+
source = (LL_RCC_PLLI2S_GetMainSource() == LL_RCC_PLLSOURCE_HSE)
78+
? HSE_VALUE
79+
: HSI_VALUE;
80+
/* Get the PLL I2S Q freq. No HAL macro for that */
81+
return __LL_RCC_CALC_PLLI2S_48M_FREQ(source,
82+
LL_RCC_PLLI2S_GetDivider(),
83+
LL_RCC_PLLI2S_GetN(),
84+
LL_RCC_PLLI2S_GetQ()
85+
);
86+
}
87+
88+
__ASSERT(0, "Invalid source");
89+
return 0;
90+
}
91+
#endif
92+
5393
/**
5494
* @brief Set up pll configuration
5595
*/

0 commit comments

Comments
 (0)