From 085cdd927733d6856573b1c2432b9e0fb9009ea6 Mon Sep 17 00:00:00 2001 From: Francois Ramu Date: Wed, 6 Jul 2022 14:42:46 +0200 Subject: [PATCH] drivers: adc: stm32f1 adc driver enable peripheral This commit avoid re-enabling the ADC, because this starts conversion. According to the RefMan (RM0008) of the stm32F10x mcu, enabling the ADC will start the conversion if the ADC is already enabled. "Conversion starts when this bit holds a value of 1 and a 1 is written to it." That's not what we want. Signed-off-by: Francois Ramu --- drivers/adc/adc_stm32.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/adc/adc_stm32.c b/drivers/adc/adc_stm32.c index fc971aff07..6a1af2d557 100644 --- a/drivers/adc/adc_stm32.c +++ b/drivers/adc/adc_stm32.c @@ -471,6 +471,9 @@ static void adc_stm32_oversampling(ADC_TypeDef *adc, uint8_t ratio, uint32_t shi */ static int adc_stm32_enable(ADC_TypeDef *adc) { + if (LL_ADC_IsEnabled(adc) == 1UL) { + return 0; + } #if defined(CONFIG_SOC_SERIES_STM32L4X) || \ defined(CONFIG_SOC_SERIES_STM32L5X) || \ defined(CONFIG_SOC_SERIES_STM32WBX) || \ @@ -479,10 +482,6 @@ static int adc_stm32_enable(ADC_TypeDef *adc) defined(CONFIG_SOC_SERIES_STM32H7X) || \ defined(CONFIG_SOC_SERIES_STM32WLX) - if (LL_ADC_IsEnabled(adc) == 1UL) { - return 0; - } - LL_ADC_ClearFlag_ADRDY(adc); LL_ADC_Enable(adc); @@ -503,6 +502,11 @@ static int adc_stm32_enable(ADC_TypeDef *adc) } } #else + /* + * On the stm32F10x, do not re-enable the ADC : + * if ADON holds 1 (LL_ADC_IsEnabled is true) and 1 is written, + * then conversion starts ; that's not what is expected + */ LL_ADC_Enable(adc); #endif