ADC (IIO) channels swapped after about 13 hours of operation

Hi,

I’m running a program that is retrieving the raw ADC counts of ADC2 and ADC3 regularly using userspace (/sys/bus/iio/devices/iio:device0).
This seems to be working just fine for the first few hours and the files “in_voltage6_raw” and “in_voltage7_raw” nicely represent the correct values.

After about 13 hours though, it seems like the channels get swapped and when retrieving the value from “in_voltage6_raw” I am actually reading the value that I would expect from “in_voltage7_raw” and the other way around.
It seems like these channels get swapped for some reason.

After rebooting the entire OS, the problem is gone and I can retrieve the correct values from the correct files again.

Here is some serial output that visualizes this issue:

ge7_raw ibri-imx6:/sys/bus/iio/devices/iio:device0# cat in_voltage6_raw in_voltag
2047
0
ge7_raw ibri-imx6:/sys/bus/iio/devices/iio:device0# cat in_voltage6_raw in_voltag
2049
0
ge7_raw ibri-imx6:/sys/bus/iio/devices/iio:device0# cat in_voltage6_raw in_voltag
2047
0
ge7_raw ibri-imx6:/sys/bus/iio/devices/iio:device0# cat in_voltage6_raw in_voltag
2045
0
root@colibri-imx6:/sys/bus/iio/devices/iio:device0# reboot now
login as: root
Last login: Mon Apr 29 09:05:35 2019 from ##.##.##.##
root@colibri-imx6:~# cd /sys/bus/iio/devices/iio\:device0
root@colibri-imx6:/sys/bus/iio/devices/iio:device0# cat in_voltage6_raw in_voltage7_raw
0
2047
root@colibri-imx6:/sys/bus/iio/devices/iio:device0# cat in_voltage6_raw in_voltage7_raw
0
2039
root@colibri-imx6:/sys/bus/iio/devices/iio:device0# cat in_voltage6_raw in_voltage7_raw
0
2048

Does anyone have any idea what could be causing this?

Thanks in advance!

Hi @DemKev

This issue is known and we will try to fix this soon.

Best regards,
Jaski

Hi @DemKev,

Thank you for pointing this out. There is indeed an issue here. Another customer reported the same issue: STMPE811 IIO timeouts on read and confuses values - Technical Support - Toradex Community

This is planned to be fixed in Q2.

Which kernel version are you using?

Thanks for your reply.

I’m using the following kernel version: 4.9.144-2.8.5+g5758a8e.

Is there any workaround that we could use in the meantime to prevent this issue?

We don’t have any workaround yet, but the other customer mentioned the following: “With the profiler flag disabled, it also barely occurs.” So Could you try this. Thanks.

@DemKev could you also try if the same occurs on a mainline kernel? since 5.1-rc1 this driver is included in mainline.

Hi @DemKev

We have a fix for this Issue. You can get it from here.

Best regards,
Jaski

Hi Jaski,

This seems indeed to have fixed our issue. Thank you for the quick response!

Kind regards,
Ramon

Hi Roman,
Perfect, that it works. Thanks for the feedback.