diff --git a/boards/nucleo-f302r8/Kconfig b/boards/nucleo-f302r8/Kconfig index 060013119c..6b42fa4d96 100644 --- a/boards/nucleo-f302r8/Kconfig +++ b/boards/nucleo-f302r8/Kconfig @@ -15,6 +15,7 @@ config BOARD_NUCLEO_F302R8 select CPU_MODEL_STM32F302R8 # Put defined MCU peripherals here (in alphabetical order) + select HAS_PERIPH_ADC select HAS_PERIPH_I2C select HAS_PERIPH_PWM select HAS_PERIPH_RTC diff --git a/boards/nucleo-f302r8/Makefile.features b/boards/nucleo-f302r8/Makefile.features index 24c9d4bfc0..1627d7a9d2 100644 --- a/boards/nucleo-f302r8/Makefile.features +++ b/boards/nucleo-f302r8/Makefile.features @@ -2,6 +2,7 @@ CPU = stm32 CPU_MODEL = stm32f302r8 # Put defined MCU peripherals here (in alphabetical order) +FEATURES_PROVIDED += periph_adc FEATURES_PROVIDED += periph_i2c FEATURES_PROVIDED += periph_pwm FEATURES_PROVIDED += periph_rtc diff --git a/boards/nucleo-f302r8/include/periph_conf.h b/boards/nucleo-f302r8/include/periph_conf.h index 034fcde657..cda93b981f 100644 --- a/boards/nucleo-f302r8/include/periph_conf.h +++ b/boards/nucleo-f302r8/include/periph_conf.h @@ -34,6 +34,28 @@ extern "C" { #endif +/** + * @name ADC configuration + * + * Note that we do not configure all ADC channels, + * and not in the STM32F302 order. Instead, we + * just define 6 ADC channels, for the Nucleo + * Arduino header pins A0-A5 + * + * @{ + */ +static const adc_conf_t adc_config[] = { + { .pin = GPIO_PIN(PORT_A, 0), .dev = 0, .chan = 1 }, /* ADC_IN1, fast */ + { .pin = GPIO_PIN(PORT_A, 1), .dev = 0, .chan = 2 }, /* ADC_IN2, fast */ + { .pin = GPIO_PIN(PORT_A, 4), .dev = 0, .chan = 5 }, /* ADC_IN5, fast */ + { .pin = GPIO_PIN(PORT_B, 0), .dev = 0, .chan = 11 }, /* ADC_IN11, slow */ + { .pin = GPIO_PIN(PORT_C, 1), .dev = 0, .chan = 7 }, /* ADC_IN7, slow */ + { .pin = GPIO_PIN(PORT_C, 0), .dev = 0, .chan = 6 }, /* ADC_IN6, slow */ +}; + +#define ADC_NUMOF ARRAY_SIZE(adc_config) +/** @} */ + /** * @name UART configuration * @{ diff --git a/cpu/stm32/periph/adc_f3.c b/cpu/stm32/periph/adc_f3.c index 18e1b11fbe..332169bd08 100644 --- a/cpu/stm32/periph/adc_f3.c +++ b/cpu/stm32/periph/adc_f3.c @@ -28,6 +28,12 @@ #define SMP_SLOW (0x2) /*< Sampling time for slow channels (0x2 = 4.5 ADC clock cycles) */ +#ifdef ADC1_COMMON +#define ADC_INSTANCE ADC1_COMMON +#else +#define ADC_INSTANCE ADC12_COMMON +#endif + /** * @brief Allocate locks for all available ADC devices */ @@ -77,11 +83,11 @@ int adc_init(adc_t line) * prescaler is 1 */ if (!(RCC->CFGR & RCC_CFGR_HPRE_3)) { /* set ADC clock to HCLK/1 */ - ADC12_COMMON->CCR |= ADC_CCR_CKMODE_0; + ADC_INSTANCE->CCR |= ADC_CCR_CKMODE_0; } else { /* set ADC clock to HCLK/2 otherwise */ - ADC12_COMMON->CCR |= ADC_CCR_CKMODE_1; + ADC_INSTANCE->CCR |= ADC_CCR_CKMODE_1; } /* Configure the pin */