@@ -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
462467static 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+
479502static 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