Post Go back to editing

AD7176-2 Overlay for RPi - Error in Selecting Matching Device

Category: Software
Product Number: AD7176-2
Software Version: Python 3.9.2, Kuiper Linux 2021_R2, Pyadi-iio 0.0.13

Hi All,

Following up on my previous post, I've made a DT overlay for the AD7176-2 based on an overlay for the AD7124-8. But I'm still running into the same issue that the device is not able to be selected.

This is my DT Overlay

/dts-v1/;
/plugin/;

/ {
	compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";

	fragment@0 {
		target-path = "/";
		__overlay__ {
			vref: fixedregulator@0 {
				compatible = "regulator-fixed";
				regulator-name = "fixed-supply";
				regulator-min-microvolt = <5000000>;
				regulator-max-microvolt = <5000000>;
				regulator-boot-on;
			};
		};
	};

	fragment@1 {
		target-path = "/";
		__overlay__ {
			clocks {
				ad7176_mclk: clock@0 {
					#clock-cells = <0>;
					compatible = "fixed-clock";
					clock-frequency = <16000000>;
				};
			};
		};
	};

	fragment@2 {
		target = <&spi0>;
		__overlay__ {
			#address-cells = <1>;
			#size-cells = <0>;
			status = "okay";

			ad7176@0 {
				compatible = "adi,ad7176-2";
				reg = <0>;
				spi-max-frequency = <5000000>;
				interrupts = <25 2>;
				interrupt-parent = <&gpio>;
				refin1-supply = <&vref>;
				clocks = <&ad7124_mclk>;
				clock-names = "mclk";

				#address-cells = <1>;
				#size-cells = <0>;

				channel@0 {
					reg = <0>;
					diff-channels = <0 1>;
				};

				channel@1 {
					reg = <1>;
					diff-channels = <2 3>;
				};
			};
		};
	};

	fragment@3 {
		target = <&spidev0>;
		__overlay__ {
			status = "disabled";
		};
	};

	fragment@4 {
		target = <&spidev1>;
		__overlay__ {
			status = "disabled";
		};
	};
};

And this is the error message I get;

Traceback (most recent call last):
File "/home/analog/AD7176/AD7176_adi.py", line 4, in <module>
my_adi = adi.ad717x(uri="local:")
File "/usr/local/lib/python3.9/dist-packages/adi/ad717x.py", line 85, in __init__
raise Exception("Error in selecting matching device")
Exception: Error in selecting matching device

I have compiled using the command; $ dtc -O dtb -o rpi-ad7176-myOverlay.dtbo rpi-ad7176-myOverlay.dts in Kuiper Linux command line and moved the .dtbo file into the /boot/overlays folder. I've added the following line into the /boot/config.txt file; dtoverlay=rpi-ad7176-myOverlay.

Any insight into where I'm going wrong would be greatly appreciated.

I'd also like to make the inputs single ended (I believe you have to specify this in the .dts/.dtbo file) - if anyone has an example they can show me of how to do this that'd be awesome!

Parents
  • Hi All,

    I've made some changes to my .dts file - taking out fragment@0 & fragment@1. I'm using an ADR445 as my voltage reference an external crystal so I don't believe I need to declare these in my DTOverlay (please correct me if I'm wrong). The updated .dts file is;

    /dts-v1/;
    /plugin/;
    
    / {
    	compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";
    
    	fragment@0 {
    		target = <&spi0>;
    		__overlay__ {
    			#address-cells = <1>;
    			#size-cells = <0>;
    			status = "okay";
    
    			ad7176@0 {
    				compatible = "adi,ad7176-2";
    				reg = <0>;
    				spi-max-frequency = <5000000>;
    				interrupts = <25 2>;
    				interrupt-parent = <&gpio>;
    
    				#address-cells = <1>;
    				#size-cells = <0>;
    
    				channel@0 {
    					reg = <0>;
    					diff-channels = <0 1>;
    				};
    
    				channel@1 {
    					reg = <1>;
    					diff-channels = <2 3>;
    				};
    			};
    		};
    	};
    
    	fragment@3 {
    		target = <&spidev0>;
    		__overlay__ {
    			status = "disabled";
    		};
    	};
    
    	fragment@4 {
    		target = <&spidev1>;
    		__overlay__ {
    			status = "disabled";
    		};
    	};
    };
    

    I've compiled and moved the .dtbo file as described in my original post. Unfortunately I'm still getting the same error. I did some digging in the kernel logs ($ dmesg) and found the following error;

    [    6.743529] ad7173 spi0.0: Unexpected device id: 4040, expected: c90

    It's very odd that it's thinking that an AD7173 should be there.

    I think I'm on the right track but if anyone can spot any errors please let me know!

  • Hello SJayawardena,

    It is good that you were inspired by AD7124-8 overlay, but when creating a device tree, you should always check the documentation in Documentation/devicetree/bindings. You have this for your device.

    An other note on your device tree, you should not use fragments. Instead check out this devicetree for reference.

Reply Children
  • Hi  ,

    Thanks for your reply!

    I've updated the .dts file based on your advice however, I'm still getting the "Exception Error in selecting matching device" error when running the python script detailed in my original post.

    /dts-v1/;
    /plugin/;
    
    
    /{
        ad7173 {
            compatible = "adi,ad7176-2";
            reg = <0>;
            interrupt-parent = <&gpio>;
            interrupts = <25 2>;
            spi-max-frequency = <32000000>;
            spi-cpol;
            spi-cpha;
            spi-cs-high;
    
            adi,channels {
                #address-cells = <2>;
                #size-cells = <0>;
                
                channel@0 {
                    reg = <21 2>;
                };
                
                channel@1 {
                    reg = <22 2>;
                };
                
                channel@2 {
                    reg = <23 2>;
                };
    
                channel@4 {
                    reg = <24 2>;
                };
            };
        };
    };

    I am getting a number of warning when I compile;

    rpi-ad7176-myOverlay2.dts:11.9-19: Warning (reg_format): /ad7176:reg: property has invalid length (4 bytes) (#address-cells == 2, #size-cells == 1)
    rpi-ad7176-myOverlay2.dts:9.12-39.7: Warning (unit_address_vs_reg): /ad7176: node has a reg or ranges property, but no unit name
    rpi-ad7176-myOverlay2.dtbo: Warning (pci_device_reg): Failed prerequisite 'reg_format'
    rpi-ad7176-myOverlay2.dtbo: Warning (pci_device_bus_num): Failed prerequisite 'reg_format'
    rpi-ad7176-myOverlay2.dtbo: Warning (simple_bus_reg): Failed prerequisite 'reg_format'
    rpi-ad7176-myOverlay2.dtbo: Warning (i2c_bus_reg): Failed prerequisite 'reg_format'
    rpi-ad7176-myOverlay2.dtbo: Warning (spi_bus_reg): Failed prerequisite 'reg_format'
    rpi-ad7176-myOverlay2.dts:9.12-39.7: Warning (avoid_default_addr_size): /ad7176: Relying on default #address-cells value
    rpi-ad7176-myOverlay2.dts:9.12-39.7: Warning (avoid_default_addr_size): /ad7176: Relying on default #size-cells value
    rpi-ad7176-myOverlay2.dtbo: Warning (avoid_unnecessary_addr_size): Failed prerequisite 'avoid_default_addr_size'
    rpi-ad7176-myOverlay2.dtbo: Warning (unique_unit_address): Failed prerequisite 'avoid_default_addr_size'

    From my understanding, these errors/warnings can generally be ignored because the compiler only understands syntax errors and not semantic errors.

    Any help would be greatly appreciated!

    I note that I'm not stating which processors are compatible (e.g. brcm2835...) nor am I disabling spiDev in this updated code - is this something that I still need to do? If so, how would I do this without the use of fragments/with this updated syntax?

    I'm a bit confused as to why we shouldn't use fragments. Has there been an update to the formatting of DTOverlays? Do you have any references which I could read?

  • Hello ,

    Your hunch is correct. You should indeed include of the Broadcom Soc into the devicetree.

    Firstly, you should not have the devicetree node of the sensor directly connected to root node(/). Instead your devicetree should start like this:

    / {
    
        compatible =  = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709"
    
    }

    Now you are using nodes instead of fragments, but the logic is quite similar. Instead of:

    	fragment@0 {
    		target = <&spi0>;
    		__overlay__ {
    			#address-cells = <1>;
    			#size-cells = <0>;
    			status = "okay";
    			...

    you should use:

    &spi0 {
    		#address-cells = <1>;
    		#size-cells = <0>;
    		status = "okay";
            ...
    }

    There are multiple devicetrees which you could check in the folder:

    linux/arch/arm/boot/dts/overlays at rpi-5.15.y · analogdevicesinc/linux · GitHub

    Using nodes instead of fragments is rather a suggestion than a must. Nowadays devicetree programmers do not use them.

    These are some useful links to read about the devicetree; I will list them in order of importance:

    1. Release v0.4 · devicetree-org/devicetree-specification · GitHub - the official documentation posted by the guys who are developing the devicetree. I strongly recommend you read this, sometime. It helps a lot understanding the basics of the devicetree.

    2. Title (bootlin.com) - a great summary done by Thomas Petazzoni. There are multiple versions of this PPT available online and you can find videos on Youtube going through this. There are minor additional explanations in the videos, which could help, but usually the PDF is enough.

    3. Linux and the Devicetree — The Linux Kernel documentation