STMicroelectronics / STMems_Linux_IIO_drivers

DISCONTINUED (October 2022): the maintenance for this repository has been discontinued. Please refer to https://github.com/STMicroelectronics/st-mems-android-linux-drivers-iio for the up-to-date drivers repository. This repository contains Linux Kernel (v3.10, v3.14, v3.18, v4.9, v4.14, v4.19) including STMicroelectronics MEMS IIO sensor support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ASM330LHH does not generate interrupt on my board

arleywong opened this issue · comments

We are using company customized development board, connecting ASM330LHH via I2C for data interface and GPIO for interrupt. We are using vanilla ASM330LHH driver in Linux kernel 5.15. Here is my situation:
H/W department said everything is good regarding their part.
USI/I2C department said everything is good regarding their part.
So I seek help here. Thank you in advance!

I configured DTS as this:

&hsi2c_10 {
status = "okay";

   #address-cells = <0x1>;
   #size-cells = <0x0>;
   asm330lhh@6a {
           compatible = "st,asm330lhh";
           reg = <0x6a>;
           interrupt-parent = <&gpp5>;
           interrupts = <5 IRQ_TYPE_EDGE_RISING>;
   };

};

Here is the result:

1. I2C operations are all good, and I am able to access ASM330LHH registers by executing I2C commands:
Command: /usr/sbin/i2cget -f -y -a 10 0x6a 0x0F
Return: 0x6b
Command: cat /sys/bus/iio/devices/iio:device0/in_anglvel_x_raw
Return: 57

2. After Linux booting done, I checked interrupts status as following (there is one gpp5-5 GPIO interrupt was generated, but do not know how it was generated)
cat /proc/interrupts |grep -E "10c30000.pinctrl|10920000.hsi2c|gpp5"
38: 1 0 0 0 0 0 0 0 0 0 GICv3 801 Level 10c30000.pinctrl
69: 61 7 3 15 0 0 0 3 0 0 GICv3 794 Level 10920000.hsi2c
375: 1 0 0 0 0 0 0 0 0 0 gpp5 5 Edge lsm6dsx

3. However, when I run libiio command (shown as following), it always goes to Connection timed out
I found there is no GPIO interrupt generated at all. I believe this leads to timeout.
So this is my question: could you help or give me some hint? Thank you very much!

iio_readdev asm330lhh_gyro anglvel_x
WARNING: High-speed mode not enabled
Unable to refill buffer: Connection timed out

4. One wierd thing is, when I execute following two i2cset commands, one GPIO interrupt will be generated and IRQ handler of ASM330LHH driver is able to read one pair of FIFO data.
/usr/sbin/i2cset -f -y -a 10 0x6a 0x12 0x44;
/usr/sbin/i2cset -f -y -a 10 0x6a 0x12 0x64;

I checked interrupts status as following (there is one more gpp5-5 GPIO interrupt was generated)
cat /proc/interrupts |grep -E "10c30000.pinctrl|10920000.hsi2c|gpp5"
38: 2 0 0 0 0 0 0 0 0 0 GICv3 801 Level 10c30000.pinctrl
69: 61 7 3 17 0 2 0 6 0 0 GICv3 794 Level 10920000.hsi2c
375: 2 0 0 0 0 0 0 0 0 0 gpp5 5 Edge lsm6dsx

Please double check on /proc/interrupts for existing id asm330lhh,
something like:

cat /proc/interrupts | grep asm330

if it exists then try with timeout set to 0:

iio_readdev -T 0 -b 1 asm330lhh_accel -s 100

Be sure to use the correct driver (the lsm6dsx is mainline driver, the asm330lhh is the repo driver, that are using the same compatible string "st,asm330lhh")

An alternative to libiio is generic_buffer

@mariotesi

Dear Mariotesi,

Thanks for your reply!!
I changed to use repo driver at here: https://github.com/STMicroelectronics/st-mems-android-linux-drivers-iio
Now I am able to find "asm330lhh" in /proc/interrupts.
However, there is still no interrupt received. I tried both generic_buffer and libiio.

  1. Device Tree:
&hsi2c_10 {
       status = "okay";

       asm330lhhx-imu@0x6a {
               compatible = "st,asm330lhh";
               reg = <0x6a>;
               interrupt-parent = <&gpp5>;
               interrupts = <5 IRQ_TYPE_LEVEL_HIGH>;
               st,int-pin = <1>;
               st,mlc-int-pin = <2>;
               mount-matrix = "1", "0", "0",
                       "0", "1", "0",
                       "0", "0", "1";
       };
};
  1. Could you help check following logs again? Thank you very much!!
root@board:~# dmesg |grep asm330
[   21.356687] st_asm330lhhx_i2c 10-006a: supply vdd not found, using dummy regulator
[   21.364658] st_asm330lhhx_i2c 10-006a: supply vddio not found, using dummy regulator
[   21.373927] st_asm330lhhx_i2c 10-006a: Freq Fine 1875 (ts 23125)
[   21.510399] st_asm330lhhx_i2c 10-006a: use default ODR
[   21.513888] st_asm330lhhx_i2c 10-006a: Device probed


root@board:~# cat /proc/interrupts |grep asm330
375:          0 0 0 0 0 0 0 0 0 0      gpp5   5 Level     asm330lhh
root@board:~#


root@board:~# ./lsiio -v
Device 005: asm330lhhx_wk

Device 003: asm330lhhx_ff

Device 001: asm330lhh_accel
   in_accel_y_raw
   in_accel_z_raw
   in_accel_x_raw

Device 006: asm330lhhx_6d

Device 004: asm330lhhx_sc

Device 002: asm330lhh_temp
   in_temp_raw

Device 000: asm330lhh_gyro
   in_anglvel_y_raw
   in_anglvel_z_raw
   in_anglvel_x_raw

Trigger 000: asm330lhhx_wk-trigger
Trigger 001: asm330lhhx_6d-trigger
root@board:~#


root@board:~# ls /sys/bus/iio/devices/
iio:device0  iio:device1  iio:device10  iio:device11  iio:device12  iio:device2  iio:device3  iio:device4  iio:device5  iio:device6  iio:device7  iio:device8  iio:device9  trigger0  trigger1
root@board:~#


root@board:~# ls /sys/bus/iio/devices/iio:device1/
buffer                   dev                 hwfifo_flush          in_accel_scale_available  in_accel_y_raw    in_accel_z_scale  name     power_mode            sampling_frequency_available  selftest_available
buffer0                  discharded_samples  hwfifo_watermark      in_accel_x_raw            in_accel_y_scale  module_id         of_node  power_mode_available  scan_elements                 subsystem
current_timestamp_clock  events              hwfifo_watermark_max  in_accel_x_scale          in_accel_z_raw    mount_matrix      power    sampling_frequency    selftest                      uevent
root@board:~#


root@board:~# ./iio_generic_buffer -a -n asm330lhh_accel -t asm330lhhx_6d-trigger
iio device number being used is 1
iio trigger number being used is 1
Enabling all channels
Enabling: in_accel_x_en
Enabling: in_count_en
Enabling: in_accel_z_en
Enabling: in_timestamp_en
Enabling: in_accel_y_en
/sys/bus/iio/devices/iio:device1 asm330lhhx_6d-trigger
Could not open /sys/bus/iio/devices/iio:device1/trigger/current_trigger
Failed to write current_trigger file
Disabling: in_accel_x_en
Disabling: in_count_en
Disabling: in_accel_z_en
Disabling: in_timestamp_en
Disabling: in_accel_y_en
root@board:~#


root@board:~# ./iio_generic_buffer -a -g -n asm330lhh_accel
iio device number being used is 1
trigger-less mode selected
Enabling all channels
Enabling: in_accel_x_en
Enabling: in_count_en
Enabling: in_accel_z_en
Enabling: in_timestamp_en
Enabling: in_accel_y_en
Unknown event: time: 1641041852010701461, id: 700001d0000002b
Unknown event: time: 1641041852010701461, id: 701001d0000000a
Unknown event: time: 1641041852015694716, id: 700001d000000fb
Unknown event: time: 1641041852015694716, id: 701001d0000000a
Unknown event: time: 1641041852020695211, id: 700001d000001cb
Unknown event: time: 1641041852020695211, id: 701001d0000000a
Unknown event: time: 1641041852025693440, id: 700001d0000029b
Unknown event: time: 1641041852025693440, id: 701001d0000000a
Unknown event: time: 1641041852030693414, id: 700001d0000036c
Unknown event: time: 1641041852030693414, id: 701001d0000000a
Unknown event: time: 1641041852035698180, id: 700001d0000043c
Unknown event: time: 1641041852035698180, id: 701001d0000000a
Unknown event: time: 1641041852040700628, id: 700001d0000050d
Unknown event: time: 1641041852040700628, id: 701001d0000000a
Unknown event: time: 1641041852045692112, id: 700001d000005dd
Unknown event: time: 1641041852045692112, id: 701001d0000000a
Unknown event: time: 1641041852245725966, id: 700001d0000266e
Unknown event: time: 1641041852245725966, id: 701001d0000000a
^CCaught signal 2
Disabling: in_accel_x_en
Disabling: in_count_en
Disabling: in_accel_z_en
Disabling: in_timestamp_en
Disabling: in_accel_y_en
root@board:~#


root@board:~# cat /proc/interrupts |grep asm330
375:          0 0 0 0 0 0 0 0 0 0      gpp5   5 Level     asm330lhh
root@board:~#


root@board:~# iio_readdev asm330lhh_gyro
WARNING: High-speed mode not enabled
Unable to refill buffer: Connection timed out
root@board:~#

root@board:~# iio_readdev -T 0 -b 1 -s 100 asm330lhh_accel
WARNING: High-speed mode not enabled




root@board:~# cat /proc/interrupts |grep asm330
375:          0 0 0 0 0 0 0 0 0 0      gpp5   5 Level     asm330lhh
root@board:~#


root@board:~# iio_info
Library version: 0.19 (git tag: 5f5af2e)
Compiled with backends: local xml ip usb
IIO context created with local backend.
Backend version: 0.19 (git tag: 5f5af2e)
Backend description string: Linux euto-v9-discovery 5.15.74 #1 SMP PREEMPT Wed Apr 19 02:37:18 UTC 2023 aarch64
IIO context has 1 attributes:
        local,kernel: 5.15.74
IIO context has 9 devices:
        iio:device0: asm330lhh_gyro (buffer capable)
                5 channels found:
                        anglvel_x:  (input, index: 0, format: le:S16/16>>0)
                        3 channel-specific attributes found:
                                attr  0: raw value: 12
                                attr  1: scale value: 0.000610865
                                attr  2: scale_available value: 0.000152716 0.000305432 0.000610865 0.001221729 0.002443459
                        anglvel_y:  (input, index: 1, format: le:S16/16>>0)
                        3 channel-specific attributes found:
                                attr  0: raw value: -34
                                attr  1: scale value: 0.000610865
                                attr  2: scale_available value: 0.000152716 0.000305432 0.000610865 0.001221729 0.002443459
                        anglvel_z:  (input, index: 2, format: le:S16/16>>0)
                        3 channel-specific attributes found:
                                attr  0: raw value: -9
                                attr  1: scale value: 0.000610865
                                attr  2: scale_available value: 0.000152716 0.000305432 0.000610865 0.001221729 0.002443459
                        count:  (input, index: 3, format: le:S64/64>>0)
                        timestamp:  (input, index: 4, format: le:S64/64>>0)
                13 device-specific attributes found:
                                attr  0: current_timestamp_clock value: realtime

                                attr  1: discharded_samples value: 0
                                attr  2: hwfifo_flush ERROR: Permission denied (-13)
                                attr  3: hwfifo_watermark value: 1
                                attr  4: hwfifo_watermark_max value: 416
                                attr  5: module_id value: 1
                                attr  6: mount_matrix value: 1, 0, 0; 0, 1, 0; 0, 0, 1
                                attr  7: power_mode value: HP_MODE
                                attr  8: power_mode_available value: HP_MODE
                                attr  9: sampling_frequency value: 26.000000
                                attr 10: sampling_frequency_available value: 12.500000 26.000000 52.000000 104.000000 208.000000 416.000000 833.000000
                                attr 11: selftest value: na
                                attr 12: selftest_available value: positive-sign, negative-sign
                2 buffer-specific attributes found:
                                attr  0: data_available value: 0
                                attr  1: watermark value: 1
        iio:device1: asm330lhh_accel (buffer capable)
                5 channels found:
                        accel_x:  (input, index: 0, format: le:S16/16>>0)
                        3 channel-specific attributes found:
                                attr  0: raw value: 62
                                attr  1: scale value: 0.002392822
                                attr  2: scale_available value: 0.000598205 0.001196411 0.002392822 0.004785645
                        accel_y:  (input, index: 1, format: le:S16/16>>0)
                        3 channel-specific attributes found:
                                attr  0: raw value: -164
                                attr  1: scale value: 0.002392822
                                attr  2: scale_available value: 0.000598205 0.001196411 0.002392822 0.004785645
                        accel_z:  (input, index: 2, format: le:S16/16>>0)
                        3 channel-specific attributes found:
                                attr  0: raw value: 4133
                                attr  1: scale value: 0.002392822
                                attr  2: scale_available value: 0.000598205 0.001196411 0.002392822 0.004785645
                        count:  (input, index: 3, format: le:S64/64>>0)
                        timestamp:  (input, index: 4, format: le:S64/64>>0)
                13 device-specific attributes found:
                                attr  0: current_timestamp_clock value: realtime

                                attr  1: discharded_samples value: 0
                                attr  2: hwfifo_flush ERROR: Permission denied (-13)
                                attr  3: hwfifo_watermark value: 1
                                attr  4: hwfifo_watermark_max value: 416
                                attr  5: module_id value: 1
                                attr  6: mount_matrix value: 1, 0, 0; 0, 1, 0; 0, 0, 1
                                attr  7: power_mode value: HP_MODE
                                attr  8: power_mode_available value: HP_MODE
                                attr  9: sampling_frequency value: 26.000000
                                attr 10: sampling_frequency_available value: 12.500000 26.000000 52.000000 104.000000 208.000000 416.000000 833.000000
                                attr 11: selftest value: na
                                attr 12: selftest_available value: positive-sign, negative-sign
                2 buffer-specific attributes found:
                                attr  0: data_available value: 0
                                attr  1: watermark value: 1
                1 debug attributes found:
                                debug attr  0: direct_reg_access value: 0x0
        iio:device2: asm330lhh_temp (buffer capable)
                3 channels found:
                        temp:  (input)
                        4 channel-specific attributes found:
                                attr  0: offset value: 6400
                                attr  1: raw value: 915
                                attr  2: scale value: 3.906250000
                                attr  3: scale_available value: 0.000003906
                        count:  (input, index: 1, format: le:S64/64>>0)
                        timestamp:  (input, index: 2, format: le:S64/64>>0)
                7 device-specific attributes found:
                                attr  0: current_timestamp_clock value: realtime

                                attr  1: hwfifo_flush ERROR: Permission denied (-13)
                                attr  2: hwfifo_watermark value: 1
                                attr  3: hwfifo_watermark_max value: 416
                                attr  4: module_id value: 1
                                attr  5: sampling_frequency value: 52.000000
                                attr  6: sampling_frequency_available value: 12.500000 52.000000
                2 buffer-specific attributes found:
                                attr  0: data_available value: 0
                                attr  1: watermark value: 1
        iio:device3: asm330lhhx_ff
                0 channels found:
                2 device-specific attributes found:
                                attr  0: freefall_threshold value: 312
                                attr  1: module_id value: 1
        iio:device4: asm330lhhx_sc
                0 channels found:
                1 device-specific attributes found:
                                attr  0: module_id value: 1
        iio:device5: asm330lhhx_wk (buffer capable)
                2 channels found:
                        (null):  (input, WARN:iio_channel_get_type()=UNKNOWN, index: 0, format: le:U8/8>>0)
                        timestamp:  (input, index: 1, format: le:S64/64>>0)
                4 device-specific attributes found:
                                attr  0: current_timestamp_clock value: realtime

                                attr  1: module_id value: 1
                                attr  2: wakeup_duration value: 0
                                attr  3: wakeup_threshold value: 93750
                2 buffer-specific attributes found:
                                attr  0: data_available value: 0
                                attr  1: watermark value: 1
                Current trigger: trigger0(asm330lhhx_wk-trigger)
        iio:device6: asm330lhhx_6d (buffer capable)
                2 channels found:
                        (null):  (input, WARN:iio_channel_get_type()=UNKNOWN, index: 0, format: le:U8/8>>0)
                        timestamp:  (input, index: 1, format: le:S64/64>>0)
                3 device-specific attributes found:
                                attr  0: current_timestamp_clock value: realtime

                                attr  1: module_id value: 1
                                attr  2: sixd_threshold value: 60
                2 buffer-specific attributes found:
                                attr  0: data_available value: 0
                                attr  1: watermark value: 1
                Current trigger: trigger1(asm330lhhx_6d-trigger)
        trigger0: asm330lhhx_wk-trigger
                0 channels found:
        trigger1: asm330lhhx_6d-trigger
                0 channels found:

I presume it depends on irq configuration, please check interrupt pin is connected to your target board application processor, furthermore consider the interrupt configuration of device tree is related to your hardware platform, for instance on Raspberry pi 4 I use the following two overlays for SPI-0 and I2C respectively:

// i2c
fragment@0 {
	target = <&spi0>;
	__dormant__ {
		asm330lhhx: asm330lhhx@0 {
			compatible = "st,asm330lhhx";
			spi-cpol;
			spi-cpha;
			reg = <0>;
			spi-max-frequency = <10000000>;
			interrupt-parent = <&gpio>;
			interrupts = <13 IRQ_TYPE_LEVEL_HIGH>;
			st,int-pin = <1>;
			status = "okay";
		};
	};
  };

__overrides__ {
	addr = <&asm330lhhx>,"reg:0";
	intpin = <&asm330lhhx>,"st,int-pin:0";
	interrupt = <&asm330lhhx>,"interrupts:0";
	asm330lhhx = <0>, "+0";
}

// spi
fragment@0 {
	target = <&i2c_arm>;
	__dormant__ {
		#address-cells = <1>;
		#size-cells = <0>;
		status = "okay";

		asm330lhhx: asm330lhhx@6b {
			compatible = "st,asm330lhhx";
			reg = <0x6b>;
			interrupt-parent = <&gpio>;
			interrupts = <26 IRQ_TYPE_LEVEL_HIGH>;
			st,int-pin = <1>;
			drive-pullup-shub;
			status = "okay";
		};
	};
};

__overrides__ {
	addr = <&asm330lhhx>,"reg:0";
	intpin = <&asm330lhhx>,"st,int-pin:0";
	interrupt = <&asm330lhhx>,"interrupts:0";
	asm330lhhx = <0>, "+0";
}

Another check that you could do once the sensor is activated with iio_readdev / generic_buffer is to verify that the interrupt pin of the sensor is set (int pin number of sensor depends on "st,int-pin" property value set in device tree, default is int 1), in this case if the handler doesn't trigger it is a matter of the miss configuration of GPIO interrupt pin on the target board BSP.

@mariotesi

I think you are right, this very much relates to configuration with board BSP. It is just I have no knowledge about it and there is no specific clue.
Anyway, I will check further. Thank you so much!!!

Besides, there is one info. for your reference.
One wierd thing is, when I execute following two i2cset commands, the data-ready interrupt will be reported endlessly and interrupt handler is called repeatedly.

/usr/sbin/i2cset -f -y -a 10 0x6a 0x12 0x44;
/usr/sbin/i2cset -f -y -a 10 0x6a 0x12 0x64;

And when I again change 0x12 reg to value 0x44, the interrupt storm will be disabled.

root@board:~# cat /proc/interrupts |grep asm330
375:          4442355 0 0 0 0 0 0 0 0 0      gpp5   5 Level     asm330lhh
root@board:~#

So I guess:

  • the physical interrupt line is connected OK.
  • high probably it is dts configuration issue.
&hsi2c_10 {
       status = "okay";

       asm330lhhx-imu@0x6a {
               compatible = "st,asm330lhh";
               reg = <0x6a>;
               interrupt-parent = <&gpp5>;
               interrupts = <5 IRQ_TYPE_LEVEL_HIGH>;
               st,int-pin = <1>;
               st,mlc-int-pin = <2>;
               mount-matrix = "1", "0", "0",
                       "0", "1", "0",
                       "0", "0", "1";
       };
};

Moreover, if "drive-open-drain" is added as following, after device probe is done, the data-ready interrupt will also be reported endlessly and interrupt handler is called repeatedly.
This time, no need to execute i2cset commands at all.

&hsi2c_10 {
       status = "okay";

       asm330lhhx-imu@0x6a {
               compatible = "st,asm330lhh";
               reg = <0x6a>;
               interrupt-parent = <&gpp5>;
               interrupts = <5 IRQ_TYPE_LEVEL_HIGH>;
               drive-open-drain;
               st,int-pin = <1>;
               st,mlc-int-pin = <2>;
               mount-matrix = "1", "0", "0",
                       "0", "1", "0",
                       "0", "0", "1";
       };
};

@mariotesi
Finnally, H/W part said there is H/W issue on interrupt pins.
So I should close this issue.
Thank you!