Trouble reading differential ADC channel on STM32MP157C under Linux
I am trying to measure voltages using the STM32MP157C's built-in ADC on channel 18 in differential mode, but keep getting wrong values. Linux kernel is 6.1.28.
Here are the relevant bits from the Linux device tree:
&pinctrl {
adc_pins_mx: adc_mx-0 {
pins {
pinmux = <STM32_PINMUX('A', 4, ANALOG)>, /* ADC1_INP18 */
<STM32_PINMUX('A', 5, ANALOG)>; /* ADC1_INN18 */
};
};
};
&adc1 {
status = "okay";
assigned-resolution-bits = <16>;
channel@18 {
reg = <18>;
diff-channels = <18 18>;
st,min-sample-time-ns = <10000>;
};
};
Voltmeter readings:
- 1.71 mV between INP18 (PA4) and GND
- 1.39 mV between INN18 (PA5) and GND
- 0.32 mV between INP18 and INN18
IIO values in /sys/bus/iio/devices/iio:device0:
- in_voltage-voltage_offset = -32768
- in_voltage-voltage_scale = 0.100708007
- in_voltage18-voltage18_raw = 37273
So that's (37273 + -32768) * 0.100708007 = ~453.69 mV instead of the expected 0.32 mV as per Voltmeter.
In single-ended mode ("diff-channels" property removed), the IIO values make more sense:
- in_voltage_offset = 0
- in_voltage_scale = 0.050354003
- in_voltage18_raw = 22
Here I get (22 + 0) * 0.050354003 = ~1.11 mV, which is close enough to the 1.71 mV measured by the voltmeter.
In differential mode, it looks like the computed values are off by a factor of 1000. I am, however, unsure if the "diff-channels" value is correct.
Am I doing this wrong? Is there a bug in the ADC driver in kernel 6.1?
Thanks and best regards,
Robert


