drivers: clock_control: stm32 set adc prescaler in rcc

For STM32F1 and F3, set the ADC prescaler in RCC if defined in dts.

Signed-off-by: Guillaume Gautier <guillaume.gautier-ext@st.com>
This commit is contained in:
Guillaume Gautier 2023-06-23 14:33:55 +02:00 committed by Fabio Baltieri
parent 5a55a185dd
commit 208d962eb8
4 changed files with 38 additions and 0 deletions

View file

@ -842,6 +842,15 @@ int stm32_clock_control_init(const struct device *dev)
#if DT_NODE_HAS_PROP(DT_NODELABEL(rcc), ahb4_prescaler)
LL_RCC_SetAHB4Prescaler(ahb_prescaler(STM32_AHB4_PRESCALER));
#endif
#if DT_NODE_HAS_PROP(DT_NODELABEL(rcc), adc_prescaler)
LL_RCC_SetADCClockSource(adc_prescaler(STM32_ADC_PRESCALER));
#endif
#if DT_NODE_HAS_PROP(DT_NODELABEL(rcc), adc12_prescaler)
LL_RCC_SetADCClockSource(adc_prescaler(STM32_ADC12_PRESCALER));
#endif
#if DT_NODE_HAS_PROP(DT_NODELABEL(rcc), adc34_prescaler)
LL_RCC_SetADCClockSource(adc_prescaler(STM32_ADC34_PRESCALER));
#endif
/* configure MCO1/MCO2 based on Kconfig */
stm32_clock_control_mco_init();

View file

@ -15,6 +15,28 @@
#include <zephyr/drivers/clock_control/stm32_clock_control.h>
#include "clock_stm32_ll_common.h"
#if defined(RCC_CFGR_ADCPRE)
#define z_adc_prescaler(v) LL_RCC_ADC_CLKSRC_PCLK2_DIV_ ## v
#define adc_prescaler(v) z_adc_prescaler(v)
#elif defined(RCC_CFGR2_ADC1PRES)
#define z_adc12_prescaler(v) \
COND_CODE_1(IS_EQ(v, 0), \
LL_RCC_ADC1_CLKSRC_HCLK, \
LL_RCC_ADC1_CLKSRC_PLL_DIV_ ## v)
#define adc12_prescaler(v) z_adc12_prescaler(v)
#else
#define z_adc12_prescaler(v) \
COND_CODE_1(IS_EQ(v, 0), \
LL_RCC_ADC12_CLKSRC_HCLK, \
LL_RCC_ADC12_CLKSRC_PLL_DIV_ ## v)
#define adc12_prescaler(v) z_adc12_prescaler(v)
#define z_adc34_prescaler(v) \
COND_CODE_1(IS_EQ(v, 0), \
LL_RCC_ADC34_CLKSRC_HCLK, \
LL_RCC_ADC34_CLKSRC_PLL_DIV_ ## v)
#define adc34_prescaler(v) z_adc34_prescaler(v)
#endif
#if defined(STM32_PLL_ENABLED)
/**

View file

@ -21,6 +21,9 @@
#define STM32_USB_PRE_ENABLED RCC_CFGR_OTGFSPRE
#endif
#define z_adc_prescaler(v) LL_RCC_ADC_CLKSRC_PCLK2_DIV_ ## v
#define adc_prescaler(v) z_adc_prescaler(v)
#if defined(STM32_PLL_ENABLED)
/*

View file

@ -82,6 +82,10 @@
#define STM32_FLASH_PRESCALER STM32_CORE_PRESCALER
#endif
#define STM32_ADC_PRESCALER DT_PROP(DT_NODELABEL(rcc), adc_prescaler)
#define STM32_ADC12_PRESCALER DT_PROP(DT_NODELABEL(rcc), adc12_prescaler)
#define STM32_ADC34_PRESCALER DT_PROP(DT_NODELABEL(rcc), adc34_prescaler)
/** STM2H7 specifics RCC dividers */
#define STM32_D1CPRE DT_PROP(DT_NODELABEL(rcc), d1cpre)
#define STM32_HPRE DT_PROP(DT_NODELABEL(rcc), hpre)