Commit 97c03182 authored by Francois Ramu's avatar Francois Ramu Committed by Christopher Friedt
Browse files

drivers: adc: stm32 disable the ADC before setting the Oversampling



On those STM32 series, setting of this feature is conditioned to
the ADC state: it is allowed to set/reset the oversampler (OVSE bit)
and set the Oversampling ratio (OVSR bits) in the ADC_CFGR2 register
only when ADC is disabled or enabled without conversion on going.
Then is the ADC re-enabled.

Signed-off-by: default avatarFrancois Ramu <francois.ramu@st.com>
parent 572ab242
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -441,8 +441,16 @@ static int start_read(const struct device *dev,
	defined(CONFIG_SOC_SERIES_STM32H7X) || \
	defined(CONFIG_SOC_SERIES_STM32L0X) || \
	defined(CONFIG_SOC_SERIES_STM32L4X) || \
	defined(CONFIG_SOC_SERIES_STM32L5X) || \
	defined(CONFIG_SOC_SERIES_STM32WBX) || \
	defined(CONFIG_SOC_SERIES_STM32WLX)
	/*
	 * setting OVS bits is conditioned to ADC state: ADC must be disabled
	 * or enabled without conversion on going : disable it, it will stop
	 */
	LL_ADC_Disable(adc);
	while (LL_ADC_IsEnabled(adc) == 1UL) {
	}
	switch (sequence->oversampling) {
	case 0:
		LL_ADC_SetOverSamplingScope(adc, LL_ADC_OVS_DISABLE);
@@ -521,8 +529,11 @@ static int start_read(const struct device *dev,
		break;
	default:
		LOG_ERR("Invalid oversampling");
		LL_ADC_Enable(adc);
		return -EINVAL;
	}
	/* re-enable ADC after changing the OVS */
	LL_ADC_Enable(adc);
#else
	if (sequence->oversampling) {
		LOG_ERR("Oversampling not supported");