Eval-ad5370 device tree questions

Hi,

I am new to AD537x DACs. Currently I want to control the evaluation board eval-ad5370 via SPI directly with my Raspberry Pi 4. I built the kernel (wiki.analog.com/.../raspberrypi) and add the Linux iio drivers for Eval-ad5370 via "make menuconfig" . However, I encounter troubles when writing the device tree overlay file. I copied and change the codes on dtbo file of ad5686 from (https://github.com/analogdevicesinc/linux/commit/4a5b5b72149ad91fe7aa857a75d24fc97f13722e#diff-dc041e47200262dfab1ff9f9e0ef64c7). The code is shown as follows:

dts-v1/;

/plugin/;



/ {

	compatible = "brcm,bcm2708";



	fragment@0 {

		target-path = "/";

		__overlay__ {

			adc_vref: fixedregulator@0 {

				compatible = "regulator-fixed";

				regulator-name = "fixed-supply";

				regulator-min-microvolt = <3000000>;

				regulator-max-microvolt = <3000000>;

				regulator-boot-on;

			};

		};

	};



	fragment@1 {

		target = <&spi0>;

		__overlay__ {

			#address-cells = <1>;

			#size-cells = <0>;

			status = "okay";



			ad5370@0{

				compatible = "adi,ad5370";

				reg = <0>;

				spi-max-frequency = <1000000>;

				spi-cpha;

				vcc-supply = <&adc_vref>;

			};

		};

	};

};

The codes actually compiled with one warning, using  "dtc -I dts -O dtb -o" commands. However, it fails to makefile using

sudo dtoverlay rpi-ad5370-overlay.dtbo

I also did not see my dac is connected using  

cd /sys/bus/iio/devices/
ls

So I think my codes for device tree file has issues. I am wondering if someone can help me with the correct setting. I may need the required properties to build the device tree, such as this link (github.com/.../dac) or this link (wiki.analog.com/.../ad5676)

I think there are some threads talking about using Raspberry Pi to control the ad5370. However, I am not sure how they successfully added the device tree.

My ultimate goal is using python codes to control it, such as this link (github.com/.../AD5370). So I think after successfully adding the device tree overlay, I can achieve my goal.

Another option is using windows. However, I may need to program the channels and make a system with feedback(No speed requirements). If there are APIs on python with on windows platform, it will also be great.

Thanks a lot in advance for your help!

Parents
  • 0
    •  Analog Employees 
    on Jul 14, 2020 9:11 AM

    Hi SamFeng,

    The issue with your device tree is that it requires 2 vref for ad5370. The names for this would be "vref0" and "vref1". Here is the line of code that refers to this : https://github.com/analogdevicesinc/linux/blob/rpi-4.19.y/drivers/iio/dac/ad5360.c#L431

    So your device tree should be something like this:

    dts-v1/;
    
    /plugin/;
    
    / {
    	compatible = "brcm,bcm2708";
    
    	fragment@0 {
    		target-path = "/";
    		__overlay__ {
    			vref0: fixedregulator@0 {
    				compatible = "regulator-fixed";
    				regulator-name = "fixed-supply";
    				regulator-min-microvolt = <3000000>;
    				regulator-max-microvolt = <3000000>;
    				regulator-boot-on;
    			};
    			vref1: fixedregulator@1 {
    				compatible = "regulator-fixed";
    				regulator-name = "fixed-supply";
    				regulator-min-microvolt = <3000000>;
    				regulator-max-microvolt = <3000000>;
    				regulator-boot-on;
    			};
    		};
    	};
    
    	fragment@1 {
    		target = <&spi0>;
    		__overlay__ {
    			#address-cells = <1>;
    			#size-cells = <0>;
    			status = "okay";
    
    			ad5370@0{
    				compatible = "adi,ad5370";
    				reg = <0>;
    				spi-max-frequency = <1000000>;
    				spi-cpha;
    				vref0-supply = <&vref0>;
    				vref1-supply = <&vref1>;
    			};
    		};
    	};
    };

    Let me know if this works. You could also use the Linux image from Analog Devices based on Raspbian it has a lot of ADI tools installed along with libiio and pyadi-iio for interfacing with IIO drivers. The only thing you have to do is compile the device tree and copy it to the sd card and configure it inside config.txt just like any other Raspbian sd card.

    The kernel in the image is the one from Analog Devices and has all ADI drivers already enabled including the ad5370.

    Here is the link to download the image: https://wiki.analog.com/resources/tools-software/linux-software/adi-kuiper_images

    Regards,

    Mircea

  • Hi Mircea,

    Here are some updates.

    I followed your instructions and downloaded the image: https://wiki.analog.com/resources/tools-software/linux-software/adi-kuiper_images. Then I compiled the dts files again. The same warning still occurred.

    However, after adding the device tree via "dtoverlay rpi-ad5370.dtbo", it seems the driver has been added, now I can see the device (iio:device0) in "/sys/bus/iio/devices" path.

    Though I have not connected my Pi to the real device. I think it is a breakthrough since the driver is added. I will update in weekdays to confirm that I can control the DAC with my RPi.

    Cheers,

    Sam Feng

  • Update: The driver is added. However,I currently cannot control the device with codes. There are several issues,

    Firstly, I cannot do the following things

    root:/sys/devices/platform/bfin-spi.0/spi0.3/iio:device0> cat name
    ad5360

    I understand that bfin may refer to the "blackfin" processor. Therefore, I do not need to follow its procedure. However, I can't see any other useful information in this folder. I can do "cat name" in other folders, such as:

    root:/sys/devices/platform/bfin-spi.0/spi0.3/iio:device0> cat name

    and shows "ad5370", but I cannot control the voltage with the built-in codes in https://wiki.analog.com/resources/tools-software/linux-drivers/iio-dac/ad5360

    I also try to control the codes with python by sending commands to SPI device directly. The codes available on Github and may be verified by others.  However, errors occurred: "spi.open(0,0) IOError: Errno 2 No such file or directory" . I cannot see spi0.0 by using "ls /dev/spi*". However, I can see spi0.0 in "/sys/bus/spi/devices" and actually "iio:device0" folder is also in "/sys/bus/spi/devices" . Therefore, I should open spi0.0 though I cannot do it.

    I am not sure what wrong it is, I will also check if the connections of SPI and GPIO pins are correct. 

    Best,

    Chenghao Feng

Reply
  • Update: The driver is added. However,I currently cannot control the device with codes. There are several issues,

    Firstly, I cannot do the following things

    root:/sys/devices/platform/bfin-spi.0/spi0.3/iio:device0> cat name
    ad5360

    I understand that bfin may refer to the "blackfin" processor. Therefore, I do not need to follow its procedure. However, I can't see any other useful information in this folder. I can do "cat name" in other folders, such as:

    root:/sys/devices/platform/bfin-spi.0/spi0.3/iio:device0> cat name

    and shows "ad5370", but I cannot control the voltage with the built-in codes in https://wiki.analog.com/resources/tools-software/linux-drivers/iio-dac/ad5360

    I also try to control the codes with python by sending commands to SPI device directly. The codes available on Github and may be verified by others.  However, errors occurred: "spi.open(0,0) IOError: Errno 2 No such file or directory" . I cannot see spi0.0 by using "ls /dev/spi*". However, I can see spi0.0 in "/sys/bus/spi/devices" and actually "iio:device0" folder is also in "/sys/bus/spi/devices" . Therefore, I should open spi0.0 though I cannot do it.

    I am not sure what wrong it is, I will also check if the connections of SPI and GPIO pins are correct. 

    Best,

    Chenghao Feng

Children