Skip to content

boards/nucleo-l412kb: enable ADC #21566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions boards/nucleo-l412kb/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ CPU = stm32
CPU_MODEL = stm32l412kb

# Put defined MCU peripherals here (in alphabetical order)
FEATURES_PROVIDED += periph_adc
FEATURES_PROVIDED += periph_i2c
FEATURES_PROVIDED += periph_pwm
FEATURES_PROVIDED += periph_rtt
Expand Down
49 changes: 49 additions & 0 deletions boards/nucleo-l412kb/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,55 @@ static const spi_conf_t spi_config[] = {
#define SPI_NUMOF ARRAY_SIZE(spi_config)
/** @} */

/**
* @brief ADC configuration
*
* Note that we do not configure all ADC channels,
* and not in the STM32L412KB order. Instead, we
* just define 5 ADC channels, for the Nucleo
* Arduino Nano header pins A0-A3 and A6 - all which are
* enabled by default and without collision with other
* features, for example, I2C or VCP_TX.
*
* To find appropriate device and channel find in the
* board manual, table showing pin assignments and
* information about ADC - a text similar to ADC[X]_IN[Y],
* where:
* [X] - describes used device - indexed from 0,
* for example ADC1_IN10 is device 0,
* [Y] - describes used channel - indexed from 1,
* for example ADC1_IN10 is channel 10
*
* For Nucleo-L431KB this information is in board manual,
* Table 15 or STM32L412KB MCU datasheet - Table 14.
*
* VBAT is connected ADC1_IN18 internal line and a voltage divider
* is used, so that only 1/3 of the actual VBAT is measured. This
* allows for a supply voltage higher than the reference voltage.
*
* For STM32L412KB more information is provided in the MCU datasheet,
* in section 3.15.3 - Vbat battery voltage monitoring.
*
* @{
*/
static const adc_conf_t adc_config[] = {
{GPIO_PIN(PORT_A, 0), .dev = 0, .chan = 5}, /* ADC1_IN5 */
{GPIO_PIN(PORT_A, 1), .dev = 0, .chan = 6}, /* ADC1_IN6 */
{GPIO_PIN(PORT_A, 3), .dev = 0, .chan = 8}, /* ADC1_IN8 */
{GPIO_PIN(PORT_A, 4), .dev = 0, .chan = 9}, /* ADC1_IN9 */
{GPIO_PIN(PORT_A, 7), .dev = 0, .chan = 12}, /* ADC1_IN12 */
{GPIO_UNDEF, .dev = 0, .chan = 18}, /* VBAT */
};

/**
* @brief Number of ADC devices
*/
#define ADC_NUMOF ARRAY_SIZE(adc_config)

#define VBAT_ADC ADC_LINE(5) /**< VBAT ADC line */

/** @} */

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion cpu/stm32/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ STM32_WITH_VBAT = stm32f031% stm32f038% stm32f042% stm32f048% \
stm32f7% \
stm32g0% \
stm32g4% stm32gbk1cb \
stm32l433% stm32l45% stm32l47% stm32l49% stm32l4r% \
stm32l412% stm32l433% stm32l45% stm32l47% stm32l49% stm32l4r% \
stm32l5% \
stm32u5% \
stm32wb% \
Expand Down
9 changes: 5 additions & 4 deletions cpu/stm32/include/periph/l4/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ extern "C" {
#error "Can't determine the number of ADC devices"
#endif

#if defined(CPU_MODEL_STM32L476RG) || defined(CPU_MODEL_STM32L476VG) || \
defined(CPU_MODEL_STM32L475VG) || defined(CPU_MODEL_STM32L452RE) || \
defined(CPU_MODEL_STM32L432KC) || defined(CPU_MODEL_STM32L496ZG) || \
defined(CPU_MODEL_STM32L4R5ZI) || defined(CPU_MODEL_STM32L496AG)
#if defined(CPU_MODEL_STM32L412KB) || defined(CPU_MODEL_STM32L476RG) || \
defined(CPU_MODEL_STM32L476VG) || defined(CPU_MODEL_STM32L475VG) || \
defined(CPU_MODEL_STM32L452RE) || defined(CPU_MODEL_STM32L432KC) || \
defined(CPU_MODEL_STM32L496ZG) || defined(CPU_MODEL_STM32L4R5ZI) || \
defined(CPU_MODEL_STM32L496AG)
/**
* @brief ADC voltage regulator start-up time [us]
*/
Expand Down
3 changes: 3 additions & 0 deletions cpu/stm32/periph/adc_l4_wb.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
#if defined ADC_DEVS && ADC_DEVS == 1
#define ADC ADC1_COMMON
#endif
#if defined ADC_DEVS && ADC_DEVS == 2
#define ADC ADC12_COMMON
#endif
#if defined ADC_DEVS && ADC_DEVS == 3
#define ADC ADC123_COMMON
#endif
Expand Down