Skip to content

Commit 6a01230

Browse files
erwangonashif
authored andcommitted
drivers/adc: stm32: Use bitfield for multiple channels detection
For multiple channels detection, channels variable was compared with the output of find_lsb_set which actually is a decimal number. Since channel is a bitfield the comparison was not behaving as expected (detecting several channels while only one channel was used). Rework the code to use the already existing bitfield "index" for the test. Signed-off-by: Erwan Gouriou <[email protected]>
1 parent c07bb77 commit 6a01230

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/adc/adc_stm32.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,15 +319,15 @@ static int start_read(const struct device *dev,
319319
}
320320

321321
uint32_t channels = sequence->channels;
322-
if (channels > find_lsb_set(channels)) {
322+
uint8_t index = find_lsb_set(channels) - 1;
323+
324+
if (channels > BIT(index)) {
323325
LOG_ERR("Only single channel supported");
324326
return -ENOTSUP;
325327
}
326328

327329
data->buffer = sequence->buffer;
328-
uint8_t index;
329330

330-
index = find_lsb_set(channels) - 1;
331331
uint32_t channel = __LL_ADC_DECIMAL_NB_TO_CHANNEL(index);
332332
#if defined(CONFIG_SOC_SERIES_STM32H7X)
333333
/*

0 commit comments

Comments
 (0)