Skip to content

Commit 97c0318

Browse files
FRASTMcfriedt
authored andcommitted
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: Francois Ramu <[email protected]>
1 parent 572ab24 commit 97c0318

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

drivers/adc/adc_stm32.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,16 @@ static int start_read(const struct device *dev,
441441
defined(CONFIG_SOC_SERIES_STM32H7X) || \
442442
defined(CONFIG_SOC_SERIES_STM32L0X) || \
443443
defined(CONFIG_SOC_SERIES_STM32L4X) || \
444+
defined(CONFIG_SOC_SERIES_STM32L5X) || \
444445
defined(CONFIG_SOC_SERIES_STM32WBX) || \
445446
defined(CONFIG_SOC_SERIES_STM32WLX)
447+
/*
448+
* setting OVS bits is conditioned to ADC state: ADC must be disabled
449+
* or enabled without conversion on going : disable it, it will stop
450+
*/
451+
LL_ADC_Disable(adc);
452+
while (LL_ADC_IsEnabled(adc) == 1UL) {
453+
}
446454
switch (sequence->oversampling) {
447455
case 0:
448456
LL_ADC_SetOverSamplingScope(adc, LL_ADC_OVS_DISABLE);
@@ -521,8 +529,11 @@ static int start_read(const struct device *dev,
521529
break;
522530
default:
523531
LOG_ERR("Invalid oversampling");
532+
LL_ADC_Enable(adc);
524533
return -EINVAL;
525534
}
535+
/* re-enable ADC after changing the OVS */
536+
LL_ADC_Enable(adc);
526537
#else
527538
if (sequence->oversampling) {
528539
LOG_ERR("Oversampling not supported");

0 commit comments

Comments
 (0)