aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George2018-05-02 12:06:23 +1000
committerDamien George2018-05-02 12:17:45 +1000
commitd4f8414ebdc5e61ef9127778ab0ce4c09f8839e9 (patch)
tree17a5d6a699bc2b523be239a4cf70b688d3e57855
parent3022947343bc54e09ba144084d391fc83db11f96 (diff)
stm32/adc: Use mp_hal_pin_config() instead of HAL_GPIO_Init().
This makes ADCAll work correctly on L4 MCUs.
-rw-r--r--ports/stm32/adc.c25
1 files changed, 4 insertions, 21 deletions
diff --git a/ports/stm32/adc.c b/ports/stm32/adc.c
index fdb31ba9c..297efe5d6 100644
--- a/ports/stm32/adc.c
+++ b/ports/stm32/adc.c
@@ -248,21 +248,9 @@ STATIC void adc_init_single(pyb_obj_adc_t *adc_obj) {
}
if (ADC_FIRST_GPIO_CHANNEL <= adc_obj->channel && adc_obj->channel <= ADC_LAST_GPIO_CHANNEL) {
- // Channels 0-16 correspond to real pins. Configure the GPIO pin in
- // ADC mode.
- const pin_obj_t *pin = pin_adc1[adc_obj->channel];
- mp_hal_gpio_clock_enable(pin->gpio);
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.Pin = pin->pin_mask;
-#if defined(STM32F4) || defined(STM32F7) || defined(STM32H7)
- GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
-#elif defined(STM32L4)
- GPIO_InitStructure.Mode = GPIO_MODE_ANALOG_ADC_CONTROL;
-#else
- #error Unsupported processor
-#endif
- GPIO_InitStructure.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(pin->gpio, &GPIO_InitStructure);
+ // Channels 0-16 correspond to real pins. Configure the GPIO pin in ADC mode.
+ const pin_obj_t *pin = pin_adc1[adc_obj->channel];
+ mp_hal_pin_config(pin, MP_HAL_PIN_MODE_ADC, MP_HAL_PIN_PULL_NONE, 0);
}
adcx_init_periph(&adc_obj->handle, ADC_RESOLUTION_12B);
@@ -637,12 +625,7 @@ void adc_init_all(pyb_adc_all_obj_t *adc_all, uint32_t resolution, uint32_t en_m
// ADC mode.
const pin_obj_t *pin = pin_adc1[channel];
if (pin) {
- mp_hal_gpio_clock_enable(pin->gpio);
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.Pin = pin->pin_mask;
- GPIO_InitStructure.Mode = GPIO_MODE_ANALOG;
- GPIO_InitStructure.Pull = GPIO_NOPULL;
- HAL_GPIO_Init(pin->gpio, &GPIO_InitStructure);
+ mp_hal_pin_config(pin, MP_HAL_PIN_MODE_ADC, MP_HAL_PIN_PULL_NONE, 0);
}
}
}