Skip to content

Commit

Permalink
drivers: adc: stm32 adc disable causing endless loop
Browse files Browse the repository at this point in the history
Setting Oversampling also applies on stm32L5 but disabling
the ADC will cause endless loop except for the stm32L0 serie.
Errata applies only on stm32G0 soc series when
writing ADC_CFGR1 register.

Signed-off-by: Francois Ramu <[email protected]>
  • Loading branch information
FRASTM authored and Rushybrook committed Oct 21, 2021
1 parent 5da2084 commit 83753c9
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions drivers/adc/adc_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,18 +409,10 @@ static int start_read(const struct device *dev,
return err;
}

#if defined(CONFIG_SOC_SERIES_STM32G0X) || \
defined(CONFIG_SOC_SERIES_STM32G4X) || \
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)
#if defined(CONFIG_SOC_SERIES_STM32G0X)
/*
* Errata: Writing ADC_CFGR1 register while ADEN bit is set
* resets RES[1:0] bitfield. We need to disable and enable adc.
* On all those stm32 devices it is allowed to write these bits only when ADEN = 0.
*/
if (LL_ADC_IsEnabled(adc) == 1UL) {
LL_ADC_Disable(adc);
Expand All @@ -436,6 +428,15 @@ static int start_read(const struct device *dev,
LL_ADC_SetResolution(adc, resolution);
#endif

#ifdef CONFIG_SOC_SERIES_STM32L0X
/*
* 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) {
}
#endif /* CONFIG_SOC_SERIES_STM32L0X */
#if defined(CONFIG_SOC_SERIES_STM32G0X) || \
defined(CONFIG_SOC_SERIES_STM32G4X) || \
defined(CONFIG_SOC_SERIES_STM32H7X) || \
Expand All @@ -444,13 +445,7 @@ static int start_read(const struct device *dev,
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);
Expand Down

0 comments on commit 83753c9

Please sign in to comment.