Skip to content

Commit

Permalink
Merge pull request #20793 from krzysztof-cabaj/stm32l476g-ADC
Browse files Browse the repository at this point in the history
boards/stm32l476g-disco: add ADC support
  • Loading branch information
benpicco authored Jul 24, 2024
2 parents 16f8160 + 99b5bc1 commit 5951fc2
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
1 change: 1 addition & 0 deletions boards/stm32l476g-disco/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ CPU = stm32
CPU_MODEL = stm32l476vg

# Put defined MCU peripherals here (in alphabetical order)
FEATURES_PROVIDED += periph_adc
FEATURES_PROVIDED += periph_rtc
FEATURES_PROVIDED += periph_rtt
FEATURES_PROVIDED += periph_timer
Expand Down
49 changes: 49 additions & 0 deletions boards/stm32l476g-disco/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,55 @@ static const uart_conf_t uart_config[] = {
#define UART_NUMOF ARRAY_SIZE(uart_config)
/** @} */

/**
* @brief ADC configuration
*
* Note that we do not configure all ADC channels,
* and not in the STM32L476VG order. Instead, we
* just define 5 ADC channels, for the next adjacent
* 5 pins, from 10 to 14, in the header P1 and the
* internal VBAT channel.
*
* 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 ADC12_IN10 is device 0 or device 1,
* [Y] - describes used channel - indexed from 1,
* for example ADC12_IN10 is channel 10
*
* For STM32L476VG this information is in MCU datasheet,
* Table 16, page 73.
*
* VBAT is connected ADC1_IN18 or ADC3_IN18 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 STM32L476VG more information is provided in MCU datasheet,
* in section 3.15.3 - Vbat battery voltage monitoring, page 42.
* @{
*/
static const adc_conf_t adc_config[] = {
{GPIO_PIN(PORT_A, 0), 0, 5}, /*< ADC12_IN5 */
{GPIO_PIN(PORT_A, 5), 0, 10}, /*< ADC12_IN10 */
{GPIO_PIN(PORT_A, 1), 0, 6}, /*< ADC12_IN6 */
{GPIO_PIN(PORT_A, 2), 0, 7}, /*< ADC12_IN7 */
{GPIO_PIN(PORT_A, 3), 0, 8}, /*< ADC12_IN8 */
{GPIO_UNDEF, 0, 18}, /* VBAT */
};

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

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

#ifdef __cplusplus
}
#endif
Expand Down
8 changes: 4 additions & 4 deletions cpu/stm32/include/periph/l4/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ extern "C" {
#error "Can't determine the number of ADC devices"
#endif

#if defined(CPU_MODEL_STM32L476RG) || 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_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

0 comments on commit 5951fc2

Please # to comment.