@@ -124,6 +124,11 @@ LOG_MODULE_REGISTER(adc_stm32);
124124 st_adc_has_deep_powerdown,\
125125 0, 1) 0)
126126
127+ #define ANY_ADC_HAS_CHANNEL_PRESELECTION \
128+ (DT_INST_FOREACH_STATUS_OKAY_VARGS(IS_EQ_PROP_OR, \
129+ st_adc_has_channel_preselection,\
130+ 0, 1) 0)
131+
127132#define ANY_CHILD_NODE_IS_DIFFERENTIAL (inst ) \
128133 (DT_INST_FOREACH_CHILD_VARGS(inst, IS_EQ_NODE_PROP_OR, \
129134 zephyr_differential, \
@@ -217,6 +222,7 @@ struct adc_stm32_cfg {
217222 int8_t oversampler_type ;
218223 int8_t internal_regulator ;
219224 bool has_deep_powerdown :1 ;
225+ bool has_channel_preselection :1 ;
220226 int8_t res_table_size ;
221227 const uint32_t res_table [];
222228};
@@ -936,16 +942,16 @@ static int set_sequencer(const struct device *dev)
936942
937943#if ANY_ADC_SEQUENCER_TYPE_IS (FULLY_CONFIGURABLE )
938944 if (config -> sequencer_type == FULLY_CONFIGURABLE ) {
939- #if defined( CONFIG_SOC_SERIES_STM32H7X ) || \
940- defined( CONFIG_SOC_SERIES_STM32N6X ) || \
941- defined( CONFIG_SOC_SERIES_STM32U3X ) || \
942- defined( CONFIG_SOC_SERIES_STM32U5X )
943- /*
944- * Each channel in the sequence must be previously enabled in PCSEL .
945- * This register controls the analog switch integrated in the IO level.
946- */
947- LL_ADC_SetChannelPreselection ( adc , channel );
948- #endif /* CONFIG_SOC_SERIES_STM32H7X || CONFIG_SOC_SERIES_STM32U5X */
945+ #if ANY_ADC_HAS_CHANNEL_PRESELECTION
946+ if ( config -> has_channel_preselection ) {
947+ /*
948+ * Each channel in the sequence must be previously enabled in PCSEL.
949+ * This register controls the analog switch integrated in the IO
950+ * level .
951+ */
952+ LL_ADC_SetChannelPreselection ( adc , channel );
953+ }
954+ #endif /* ANY_ADC_HAS_CHANNEL_PRESELECTION */
949955 LL_ADC_REG_SetSequencerRanks (adc , table_rank [channel_index ], channel );
950956 LL_ADC_REG_SetSequencerLength (adc , table_seq_len [channel_index ]);
951957 }
@@ -1168,10 +1174,12 @@ static void adc_context_on_complete(struct adc_context *ctx, int status)
11681174 data -> acq_time_index [0 ] = -1 ;
11691175 data -> acq_time_index [1 ] = -1 ;
11701176
1171- #if defined(CONFIG_SOC_SERIES_STM32H7X ) || defined(CONFIG_SOC_SERIES_STM32U5X )
1172- /* Reset channel preselection register */
1173- LL_ADC_SetChannelPreselection (adc , 0 );
1174- #endif /* CONFIG_SOC_SERIES_STM32H7X || CONFIG_SOC_SERIES_STM32U5X */
1177+ #if ANY_ADC_HAS_CHANNEL_PRESELECTION
1178+ if (config -> has_channel_preselection ) {
1179+ /* Reset channel preselection register */
1180+ LL_ADC_SetChannelPreselection (adc , 0 );
1181+ }
1182+ #endif /* ANY_ADC_HAS_CHANNEL_PRESELECTION */
11751183}
11761184
11771185static int adc_stm32_read (const struct device * dev ,
@@ -1980,7 +1988,8 @@ static const struct adc_stm32_cfg adc_stm32_cfg_##index = { \
19801988 .oversampler_type = DT_INST_STRING_UPPER_TOKEN(index, st_adc_oversampler), \
19811989 .internal_regulator = CONCAT(INTERNAL_REGULATOR_, \
19821990 DT_INST_STRING_UPPER_TOKEN(index, st_adc_internal_regulator)), \
1983- .has_deep_powerdown = DT_INST_PROP(index, st_adc_has_deep_powerdown), \
1991+ .has_deep_powerdown = DT_INST_PROP(index, st_adc_has_deep_powerdown), \
1992+ .has_channel_preselection = DT_INST_PROP(index, st_adc_has_channel_preselection), \
19841993 .sampling_time_table = DT_INST_PROP(index, sampling_times), \
19851994 .num_sampling_time_common_channels = \
19861995 DT_INST_PROP_OR(index, num_sampling_time_common_channels, 0),\
0 commit comments