From 2a96cc03478a348f301649870fa1d5b88005f70b Mon Sep 17 00:00:00 2001 From: Aurelien Jarno Date: Sun, 4 Jul 2021 12:17:59 +0200 Subject: [PATCH] drivers: adc: STM32: fix support for internal voltage reference source Commit c045cbd33612 added support for internal voltage reference source, but in practice only the temp sensor is supported. Fix that. Also change the code to keep the existing paths so that VREFINT and TEMPSENSOR can be used at the same time. Signed-off-by: Aurelien Jarno --- drivers/adc/adc_stm32.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/adc/adc_stm32.c b/drivers/adc/adc_stm32.c index 22f459ab956..359f905b74c 100644 --- a/drivers/adc/adc_stm32.c +++ b/drivers/adc/adc_stm32.c @@ -549,17 +549,18 @@ static int adc_stm32_check_acq_time(uint16_t acq_time) } /* - * Enable internal voltage reference source + * Enable internal channel source */ -static void adc_stm32_set_common_path(const struct device *dev) +static void adc_stm32_set_common_path(const struct device *dev, uint32_t PathInternal) { const struct adc_stm32_cfg *config = (const struct adc_stm32_cfg *)dev->config; ADC_TypeDef *adc = (ADC_TypeDef *)config->base; (void) adc; /* Avoid 'unused variable' warning for some families */ - LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(adc), - LL_ADC_PATH_INTERNAL_TEMPSENSOR); + /* Do not remove existing paths */ + PathInternal |= LL_ADC_GetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(adc)); + LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(adc), PathInternal); } static void adc_stm32_setup_speed(const struct device *dev, uint8_t id, @@ -630,9 +631,10 @@ static int adc_stm32_channel_setup(const struct device *dev, return -EINVAL; } - if ((__LL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_TEMPSENSOR) == channel_cfg->channel_id) || - (__LL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_VREFINT) == channel_cfg->channel_id)) { - adc_stm32_set_common_path(dev); + if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_TEMPSENSOR) == channel_cfg->channel_id) { + adc_stm32_set_common_path(dev, LL_ADC_PATH_INTERNAL_TEMPSENSOR); + } else if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_VREFINT) == channel_cfg->channel_id) { + adc_stm32_set_common_path(dev, LL_ADC_PATH_INTERNAL_VREFINT); } adc_stm32_setup_speed(dev, channel_cfg->channel_id,