How do I enable I2C Interface in a ZedBoard for MATLAB R2023b?

I am trying to use Simulink with the SoC Blockset to communicate with my ZedBoard hardware. My hardware contains a Zynq 7000 FPGA and an ARM processor that use Linux. If I "ssh" into the hardware, I can see serial, USB, I2C, etc. in the device tree. However, I2C is disabled, and I am not sure how to enable it. Is there a setting for enabling I2C interfaces?

 Accepted Answer

For the I2C connection, the default ZedBoard device tree has the I2C nodes disabled. You can "de-compile" the currently running device tree on hardware and confirm I2C is disabled. To do this, execute these commands from the MATLAB Command Window and observe the output: 
>> z = socHardwareBoard('ZedBoard','hostname',<board IP Address>,'username','root','password','root');
>> z.system('dtc -@ -O dts -I fs -o /mnt/current_devicetree.dts /proc/device-tree');
>> z.system('sed -n ''/i2c@e00.*{/,/};/p'' /mnt/current_devicetree.dts')
ans =
    ' i2c@e0005000 {
      compatible = "cdns,i2c-r1p10";
      clocks = <0x2 0x27>;
      status = "disabled"; // <--- Disabled
      interrupt-parent = <0x1>;
      #address-cells = <0x1>;
      interrupts = <0x0 0x30 0x4>;
      #size-cells = <0x0>;
      phandle = <0xf>;
      reg = <0xe0005000 0x1000>;
      linux,phandle = <0xf>;
      };
      i2c@e0004000 {
      compatible = "cdns,i2c-r1p10";
      clocks = <0x2 0x26>;
      status = "disabled"; <--- Disabled
      interrupt-parent = <0x1>;
      #address-cells = <0x1>;
      interrupts = <0x0 0x19 0x4>;
      #size-cells = <0x0>;
      phandle = <0xe>;
      reg = <0xe0004000 0x1000>;
      linux,phandle = <0xe>;
      };
     '
To enable these I2C nodes in the device tree, you can create an override device tree and include the "current_devicetree.dts" file following the steps below:
 
1. In the MATLAB Editor, create a file named "enable_i2c.dts". Enter the following text in that file and save it:
/dts-v1/;
/include/ "current_devicetree.dts"
/ {
        amba {
                i2c@e0005000 {
                        status = "okay";
                };
                i2c@e0004000 {
                        status = "okay";
                };
        };
};
2. Execute the following commands from the MATLAB Command Window to put this file on the hardware and compile a new device tree binary from that:
>> z.putFile('enable_i2c.dts','/mnt/enable_i2c.dts');
>> z.system('dtc -@ -O dtb -I dts -i /mnt -o /mnt/devicetree_with_i2c.dtb /mnt/enable_i2c.dts');
>> z.system('fw_setenv devicetree_image devicetree_with_i2c.dtb'); % Use the new device-tree with I2C enabled
>> z.system('sync'); % Save changes to SD card
>> z.system('reboot'); % Restart

More Answers (0)

Products

Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!