Skip to content

Commit c045cbd

Browse files
Delsiangalak
authored andcommitted
drivers: adc: STM32 Add common path
Enable common path for internal voltage voltage reference source. Signed-off-by: Eug Krashtan <[email protected]>
1 parent 2b8c123 commit c045cbd

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

drivers/adc/adc_stm32.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ static const uint32_t table_samp_time[] = {
202202
};
203203
#endif
204204

205+
/* Bugfix for STM32G4 HAL */
206+
#if !defined(ADC_CHANNEL_TEMPSENSOR)
207+
#define ADC_CHANNEL_TEMPSENSOR ADC_CHANNEL_TEMPSENSOR_ADC1
208+
#endif
209+
205210
/* External channels (maximum). */
206211
#define STM32_CHANNEL_COUNT 20
207212

@@ -461,6 +466,10 @@ static int adc_stm32_read_async(const struct device *dev,
461466

462467
static int adc_stm32_check_acq_time(uint16_t acq_time)
463468
{
469+
if (acq_time == ADC_ACQ_TIME_MAX) {
470+
return ARRAY_SIZE(acq_time_tbl) - 1;
471+
}
472+
464473
for (int i = 0; i < 8; i++) {
465474
if (acq_time == ADC_ACQ_TIME(ADC_ACQ_TIME_TICKS,
466475
acq_time_tbl[i])) {
@@ -476,6 +485,20 @@ static int adc_stm32_check_acq_time(uint16_t acq_time)
476485
return -EINVAL;
477486
}
478487

488+
/*
489+
* Enable internal voltage reference source
490+
*/
491+
static void adc_stm32_set_common_path(const struct device *dev)
492+
{
493+
const struct adc_stm32_cfg *config =
494+
(const struct adc_stm32_cfg *)dev->config;
495+
ADC_TypeDef *adc = (ADC_TypeDef *)config->base;
496+
(void) adc; /* Avoid 'unused variable' warning for some families */
497+
498+
LL_ADC_SetCommonPathInternalCh(__LL_ADC_COMMON_INSTANCE(adc),
499+
LL_ADC_PATH_INTERNAL_TEMPSENSOR);
500+
}
501+
479502
static void adc_stm32_setup_speed(const struct device *dev, uint8_t id,
480503
uint8_t acq_time_index)
481504
{
@@ -544,6 +567,11 @@ static int adc_stm32_channel_setup(const struct device *dev,
544567
return -EINVAL;
545568
}
546569

570+
if (channel_cfg->channel_id == ADC_CHANNEL_TEMPSENSOR ||
571+
channel_cfg->channel_id == ADC_CHANNEL_VREFINT) {
572+
adc_stm32_set_common_path(dev);
573+
}
574+
547575
adc_stm32_setup_speed(dev, channel_cfg->channel_id,
548576
acq_time_index);
549577

0 commit comments

Comments
 (0)