summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriabdalkader <i.abdalkader@gmail.com>2021-07-01 16:15:31 +0200
committerDamien George <damien@micropython.org>2021-07-02 23:33:51 +1000
commit0e11966ce9ea2345458d2e6127ee28486c4cb65d (patch)
treeae34e5f361f1fc7ec91faaec2d52978746dcd48e
parentff7be31f264c359b6f11fcc2cec8489dfe4905bd (diff)
stm32/adc: Define the ADC instance used for internal channels.
-rw-r--r--ports/stm32/adc.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/ports/stm32/adc.c b/ports/stm32/adc.c
index 6f709e909..55dc3083b 100644
--- a/ports/stm32/adc.c
+++ b/ports/stm32/adc.c
@@ -55,6 +55,17 @@
#define PIN_ADC_MASK PIN_ADC1
#define pin_adc_table pin_adc1
+#if defined(STM32H7)
+// On the H7 ADC3 is used for ADCAll to be able to read internal
+// channels. For all other GPIO channels, ADC12 is used instead.
+#define ADCALLx (ADC3)
+#define pin_adcall_table pin_adc3
+#else
+// Use ADC1 for ADCAll instance by default for all other MCUs.
+#define ADCALLx (ADC1)
+#define pin_adcall_table pin_adc1
+#endif
+
#define ADCx_CLK_ENABLE __HAL_RCC_ADC1_CLK_ENABLE
#if defined(STM32F0)
@@ -724,24 +735,14 @@ void adc_init_all(pyb_adc_all_obj_t *adc_all, uint32_t resolution, uint32_t en_m
if (en_mask & (1 << channel)) {
// Channels 0-16 correspond to real pins. Configure the GPIO pin in
// ADC mode.
- #if defined(STM32H7)
- const pin_obj_t *pin = pin_adc3[channel];
- #else
- const pin_obj_t *pin = pin_adc_table[channel];
- #endif
+ const pin_obj_t *pin = pin_adcall_table[channel];
if (pin) {
mp_hal_pin_config(pin, MP_HAL_PIN_MODE_ADC, MP_HAL_PIN_PULL_NONE, 0);
}
}
}
- #if defined(STM32H7)
- // On the H7 the internal channels are connected to ADC3. To read internal channels
- // with ADCAll, ADC3 must be used here, and ADC12 is used to read the GPIO channels.
- adc_all->handle.Instance = ADC3;
- #else
- adc_all->handle.Instance = ADCx;
- #endif
+ adc_all->handle.Instance = ADCALLx;
adcx_init_periph(&adc_all->handle, resolution);
}