stm32: adc: use ADC properties to configure temp and vref channels
Use the devicetree properties to determine if the dedicated temperature or voltage reference channels should be configured for the ADC. Fixes #43750. Signed-off-by: Benedikt Schmidt <benedikt.schmidt@embedded-solutions.at>
This commit is contained in:
parent
0907e35bef
commit
09d2199589
|
@ -256,6 +256,8 @@ struct adc_stm32_cfg {
|
|||
void (*irq_cfg_func)(void);
|
||||
struct stm32_pclken pclken;
|
||||
const struct pinctrl_dev_config *pcfg;
|
||||
bool has_temp_channel;
|
||||
bool has_vref_channel;
|
||||
};
|
||||
|
||||
#ifdef CONFIG_ADC_STM32_SHARED_IRQS
|
||||
|
@ -798,96 +800,17 @@ static void adc_stm32_setup_speed(const struct device *dev, uint8_t id,
|
|||
|
||||
static void adc_stm32_setup_channels(const struct device *dev, uint8_t channel_id)
|
||||
{
|
||||
#if defined(CONFIG_SOC_SERIES_STM32G4X) || \
|
||||
defined(CONFIG_SOC_SERIES_STM32F3X) || \
|
||||
defined(CONFIG_SOC_SERIES_STM32F3X) || \
|
||||
defined(CONFIG_SOC_SERIES_STM32F7X) || \
|
||||
defined(CONFIG_SOC_SERIES_STM32H7X) || \
|
||||
defined(CONFIG_SOC_SERIES_STM32L4X) || \
|
||||
defined(CONFIG_SOC_SERIES_STM32L5X) || \
|
||||
defined(CONFIG_SOC_SERIES_STM32MP1X)
|
||||
const struct adc_stm32_cfg *config = dev->config;
|
||||
ADC_TypeDef *adc = config->base;
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_SOC_SERIES_STM32G4X)
|
||||
/* In the G4 model, once can access internal temperature on ADCs 1 and 5. */
|
||||
if ((adc == ADC1 &&
|
||||
__LL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_TEMPSENSOR_ADC1) == channel_id) ||
|
||||
(adc == ADC5 &&
|
||||
__LL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_TEMPSENSOR_ADC5) == channel_id)) {
|
||||
if (config->has_temp_channel &&
|
||||
__LL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_TEMPSENSOR) == channel_id) {
|
||||
adc_stm32_set_common_path(dev, LL_ADC_PATH_INTERNAL_TEMPSENSOR);
|
||||
}
|
||||
/* In the G4 model, once can access internal reference voltage on all ADCs besides 2. */
|
||||
else if (adc != ADC2 &&
|
||||
|
||||
if (config->has_vref_channel &&
|
||||
__LL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_VREFINT) == channel_id) {
|
||||
adc_stm32_set_common_path(dev, LL_ADC_PATH_INTERNAL_VREFINT);
|
||||
}
|
||||
#elif defined(CONFIG_SOC_SERIES_STM32F3X)
|
||||
/* Some F3X have ADC 1 and 2, some have 1, 2, 3 and 4.
|
||||
* Temperature can only be read on ADC1.
|
||||
* Refint can be read on all ADCs.
|
||||
*/
|
||||
if (adc == ADC1 &&
|
||||
__LL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_TEMPSENSOR) == channel_id) {
|
||||
adc_stm32_set_common_path(dev, LL_ADC_PATH_INTERNAL_TEMPSENSOR);
|
||||
} else if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_VREFINT) == channel_id) {
|
||||
adc_stm32_set_common_path(dev, LL_ADC_PATH_INTERNAL_VREFINT);
|
||||
}
|
||||
#elif defined(CONFIG_SOC_SERIES_STM32F7X)
|
||||
if (adc == ADC1) {
|
||||
if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_TEMPSENSOR) == channel_id) {
|
||||
adc_stm32_set_common_path(dev, LL_ADC_PATH_INTERNAL_TEMPSENSOR);
|
||||
} else if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_VREFINT) == channel_id) {
|
||||
adc_stm32_set_common_path(dev, LL_ADC_PATH_INTERNAL_VREFINT);
|
||||
}
|
||||
}
|
||||
#elif defined(CONFIG_SOC_SERIES_STM32H7X)
|
||||
if (adc == ADC3) {
|
||||
if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_TEMPSENSOR) == channel_id) {
|
||||
adc_stm32_set_common_path(dev, LL_ADC_PATH_INTERNAL_TEMPSENSOR);
|
||||
} else if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_VREFINT) == channel_id) {
|
||||
adc_stm32_set_common_path(dev, LL_ADC_PATH_INTERNAL_VREFINT);
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined(CONFIG_SOC_SERIES_STM32L4X)
|
||||
/* Temperature available on ADCs 1 and 3.
|
||||
* Refint available on ADC 1 only.
|
||||
*/
|
||||
if ((adc == ADC1 || adc == ADC3) &&
|
||||
__LL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_TEMPSENSOR) == channel_id) {
|
||||
adc_stm32_set_common_path(dev, LL_ADC_PATH_INTERNAL_TEMPSENSOR);
|
||||
} else if (adc == ADC1 &&
|
||||
__LL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_VREFINT) == channel_id) {
|
||||
adc_stm32_set_common_path(dev, LL_ADC_PATH_INTERNAL_VREFINT);
|
||||
}
|
||||
#elif defined(CONFIG_SOC_SERIES_STM32L5X)
|
||||
if (adc == ADC1) {
|
||||
if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_TEMPSENSOR) == channel_id) {
|
||||
adc_stm32_set_common_path(dev, LL_ADC_PATH_INTERNAL_TEMPSENSOR);
|
||||
} else if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_VREFINT) == channel_id) {
|
||||
adc_stm32_set_common_path(dev, LL_ADC_PATH_INTERNAL_VREFINT);
|
||||
}
|
||||
}
|
||||
#elif defined(CONFIG_SOC_SERIES_STM32MP1X)
|
||||
if (adc == ADC2) {
|
||||
if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_TEMPSENSOR) == channel_id) {
|
||||
adc_stm32_set_common_path(dev, LL_ADC_PATH_INTERNAL_TEMPSENSOR);
|
||||
} else if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_VREFINT) == channel_id) {
|
||||
adc_stm32_set_common_path(dev, LL_ADC_PATH_INTERNAL_VREFINT);
|
||||
}
|
||||
}
|
||||
#else
|
||||
/* For everything else, temperature and refint are available on all ADCs.
|
||||
* Most other models only have 1 ADC anyway.
|
||||
*/
|
||||
if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_TEMPSENSOR) == channel_id) {
|
||||
adc_stm32_set_common_path(dev, LL_ADC_PATH_INTERNAL_TEMPSENSOR);
|
||||
} else if (__LL_ADC_CHANNEL_TO_DECIMAL_NB(ADC_CHANNEL_VREFINT) == channel_id) {
|
||||
adc_stm32_set_common_path(dev, LL_ADC_PATH_INTERNAL_VREFINT);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static int adc_stm32_channel_setup(const struct device *dev,
|
||||
|
@ -1202,6 +1125,8 @@ static const struct adc_stm32_cfg adc_stm32_cfg_##index = { \
|
|||
.bus = DT_INST_CLOCKS_CELL(index, bus), \
|
||||
}, \
|
||||
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(index), \
|
||||
.has_temp_channel = DT_INST_PROP(index, has_temp_channel), \
|
||||
.has_vref_channel = DT_INST_PROP(index, has_vref_channel), \
|
||||
};
|
||||
#else
|
||||
#define ADC_STM32_CONFIG(index) \
|
||||
|
@ -1221,6 +1146,8 @@ static const struct adc_stm32_cfg adc_stm32_cfg_##index = { \
|
|||
.bus = DT_INST_CLOCKS_CELL(index, bus), \
|
||||
}, \
|
||||
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(index), \
|
||||
.has_temp_channel = DT_INST_PROP(index, has_temp_channel), \
|
||||
.has_vref_channel = DT_INST_PROP(index, has_vref_channel), \
|
||||
};
|
||||
#endif /* CONFIG_ADC_STM32_SHARED_IRQS */
|
||||
|
||||
|
|
Loading…
Reference in a new issue