2019-09-04 16:37:52 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2019 Richard Osterloh <richard.osterloh@gmail.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <soc.h>
|
2020-11-21 03:28:06 +08:00
|
|
|
#include <stm32_ll_bus.h>
|
|
|
|
#include <stm32_ll_pwr.h>
|
|
|
|
#include <stm32_ll_rcc.h>
|
|
|
|
#include <stm32_ll_utils.h>
|
2022-05-06 16:25:46 +08:00
|
|
|
#include <zephyr/drivers/clock_control.h>
|
|
|
|
#include <zephyr/sys/util.h>
|
|
|
|
#include <zephyr/drivers/clock_control/stm32_clock_control.h>
|
2019-09-04 16:37:52 +08:00
|
|
|
#include "clock_stm32_ll_common.h"
|
|
|
|
|
2022-06-29 03:50:20 +08:00
|
|
|
#if defined(STM32_PLL_ENABLED)
|
2019-09-04 16:37:52 +08:00
|
|
|
|
|
|
|
/**
|
2022-04-22 17:37:28 +08:00
|
|
|
* @brief Return PLL source
|
2019-09-04 16:37:52 +08:00
|
|
|
*/
|
2022-04-22 17:37:28 +08:00
|
|
|
__unused
|
|
|
|
static uint32_t get_pll_source(void)
|
2019-09-04 16:37:52 +08:00
|
|
|
{
|
2022-04-22 17:37:28 +08:00
|
|
|
/* Configure PLL source */
|
|
|
|
if (IS_ENABLED(STM32_PLL_SRC_HSI)) {
|
|
|
|
return LL_RCC_PLLSOURCE_HSI;
|
|
|
|
} else if (IS_ENABLED(STM32_PLL_SRC_HSE)) {
|
|
|
|
return LL_RCC_PLLSOURCE_HSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
__ASSERT(0, "Invalid source");
|
|
|
|
return 0;
|
|
|
|
}
|
2020-02-26 16:05:40 +08:00
|
|
|
|
drivers/clock_control: stm32 common pll src support(g0,g4,l4,l5,wb,wl)
This commit adds support to select pll outputs as peripheral clock
sources to the stm32 common driver.
With this commit they are only available on
STM32G0, STM32G4, STM32L4, STM32L5, STM32WB, and STM32WL.
Support for STM32F2, and STM32F4, which also have p,q,r dividers,
is not enabled in this commit.
Also, stm32_clock_control_get_subsys_rate is extended to return
the configured frequency in case they are enabled, otherwise 0.
Signed-off-by: Thomas Stranger <thomas.stranger@outlook.com>
2022-06-29 02:12:41 +08:00
|
|
|
/**
|
|
|
|
* @brief get the pll source frequency
|
|
|
|
*/
|
|
|
|
__unused
|
|
|
|
uint32_t get_pllsrc_frequency(void)
|
|
|
|
{
|
|
|
|
if (IS_ENABLED(STM32_PLL_SRC_HSI)) {
|
|
|
|
return STM32_HSI_FREQ;
|
|
|
|
} else if (IS_ENABLED(STM32_PLL_SRC_HSE)) {
|
|
|
|
return STM32_HSE_FREQ;
|
|
|
|
}
|
|
|
|
|
|
|
|
__ASSERT(0, "Invalid source");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-04-22 17:37:28 +08:00
|
|
|
/**
|
|
|
|
* @brief Set up pll configuration
|
|
|
|
*/
|
|
|
|
__unused
|
|
|
|
void config_pll_sysclock(void)
|
|
|
|
{
|
2020-02-26 16:05:40 +08:00
|
|
|
/* set power boost mode for sys clock greater than 150MHz */
|
|
|
|
if (sys_clock_hw_cycles_per_sec() >= MHZ(150)) {
|
|
|
|
LL_PWR_EnableRange1BoostMode();
|
|
|
|
}
|
2022-03-23 22:34:16 +08:00
|
|
|
|
2022-04-22 17:37:28 +08:00
|
|
|
LL_RCC_PLL_ConfigDomain_SYS(get_pll_source(),
|
|
|
|
pllm(STM32_PLL_M_DIVISOR),
|
|
|
|
STM32_PLL_N_MULTIPLIER,
|
|
|
|
pllr(STM32_PLL_R_DIVISOR));
|
2022-03-23 22:34:16 +08:00
|
|
|
|
|
|
|
LL_RCC_PLL_EnableDomain_SYS();
|
2022-04-22 17:37:28 +08:00
|
|
|
}
|
2022-03-23 22:34:16 +08:00
|
|
|
|
2022-06-29 03:50:20 +08:00
|
|
|
#endif /* defined(STM32_PLL_ENABLED) */
|
2019-09-04 16:37:52 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Activate default clocks
|
|
|
|
*/
|
|
|
|
void config_enable_default_clocks(void)
|
|
|
|
{
|
|
|
|
/* Enable the power interface clock */
|
|
|
|
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);
|
|
|
|
}
|