Enabling PS I2C for Microzed with xillinux

Questions and discussions about Xillinux

Enabling PS I2C for Microzed with xillinux

Postby Guest »

I have worked myself through the posts at
http://zedboard.org/content/ps-i2c-xillinux
and
viewtopic.php?f=4&t=319
to enable I2C communication via the PS I2C interface on the PMOD-type connector and while they were very useful, they are partially incomplete, have non-intuitive titles, and/or have broken links, so I figured I post the whole procedure as it worked for me.
I'm using a Microzed (2016) and Xillinux 1.3c

The Xillinux MicroZed SD card has a small FAT partition with
devicetree.dtb specifies processor and peripherals for Linux
boot.bin Zynq boot image with FSBL and uboot
xillydemo.bit PL bitstream
uImage Linux boot image

By default, the pins in the PMOD connector are set as GPIO. To assign them to the built-in I2C controller, the first 2 files have to be modified.
(The 3rd contains the PL logic and is created by Vivado, no need to change since the PMOD I2C is using only PS pins; and the 4th is part of the SD card download)

***************************** Vivado ***************************
(I'm using 2015.4)
1. Open xillydemo > xillybus_ins > system_i > vivado_system_i (the block diagram)
2. Open (double click) block for Zynq processing_system7 (opens recustomize IP)
3. Under Peripheral I/O Pins:
- Enable I2C0 for pins MIO 10/11
- Enable I2C interrupt, MIO 9
4. Under MIO Configuration:
- I/O Peripherals > GPIO > USB Reset: check USB0 Reset and assign MIO7
(came undone or was not originally set, and USB wouldn't work without it)
5. Click ok
6. Recompile Vivado project (generate bitstream)
7. File > Export > Hardware to a local folder. Do not include bitstream
for example, to …/SDK/xillydemo.hdf
8. File > Launch SDK

***************************** SDK *****************************
1 File > New > application project
2 Page 1, specify project name = “MZ_I2C”,
OS = “standalone”,
hardware platform = “xillydemo_hw_platform” as just exported
Processor = “ps7_cortexa9_0” (not sure if _1 makes a difference)
3 Next > Page 2, specify template = “Zynq FSBL”
4 Finish
=> Creates MZ_I2C and MZ_I2C_bsp

5 right click on MZ_I2C > create boot image.
6 In dialog: new bif file
boot image partitions i) MZ_I2C.elf (edit > type: bootloader)
ii) add > u-boot-xillinux-1.3.elf (type datafile)
(can be downloaded from http://xillybus.com/downloads/u-boot-xi ... .3.elf.zip)
create Image
7 creates boot.bin

***************************** Device tree *****************************
To modify the device tree, can either generate it from scratch (http://www.wiki.xilinx.com/Build+Device+Tree+Blob) or paste it together from formum posts plus some experimentation. See also http://xillybus.com/tutorials/device-tree-zynq-1. The dtb file is compiled with dtc from a dts source file in Xillinux.
1. Go to /usr/src/kernels/3.?.?-xillinux-?.?/
The dtc compiler is the folders below
2. The original dts file is in /boot
3. Add entries for I2C0 (below)
4. Compile to dtb by command
$ scripts/dtc/dtc -I dts -O dtb -o /path/to/my-tree.dtb /path/to/my-tree.dts

Working I2C entry:
i2c0: i2c@e0004000 {
compatible = "xlnx,ps7-i2c-1.00.a"; // calls out a xlnx driver already present in xillinux
reg = <0xE0004000 0x1000>; // memory address and size, fixed by Zynq HW for I2C0
bus-id = <0>;
clocks = <&clkc 38>; // ref to sys clk #38 = I2C clock. Simply <4000000> didn’t work
i2c-clk = <100000>; // 100kHz standard slow I2C
interrupt-parent = <&ps7_scugic_0>; // see note
interrupts = <0 25 4>;
#address-cells = <1>; //default
#size-cells = <0>; // default
};
Notes re Interrupt: In other dts files, <1> or <&intc> is often used. This did not work; Linux boot complained about interrupt error. Other xillinux dts entries use the Use <&ps7..> in apparent equivalence to <&intc>, so I tried it here also and it worked.

***************************** Linux *****************************
Checking the kernel config file (per /boot/ config-3.12.0-xillinux-1.3):
CONFIG_I2C=y
CONFIG_I2C_BOARDINFO=y
CONFIG_I2C_COMPAT=y
CONFIG_I2C_CHARDEV=y
CONFIG_I2C_MUX=y
So this seems to be already addressing the “final” issue in http://zedboard.org/content/ps-i2c-xillinux
No need to recompile the kernel

With new boot.bin and devicetree.dtb on SD card FAT partition, Linux boot reports
i2c /dev entries driver
xi2cps e0004000.i2c: 100 kHz mmio e0004000 irq 57
and there is an entry in /sys/class/i2c-adapter and /sys/class/i2c-dev, but not in /dev

i2cdetect is not installed in original xillinux, so install from Ubuntu: apt-get install i2c-tools
I2ctools provides I2cset, i2cget, i2cdetect
i2cdetect -l finds Xilinx I2C.
i2cget toggles MZ PMOD pins 2 (clk) and 3 (data)

Note: The MicroZed claims to be "PMOD compatible" but it seems that the available pinout for I2C (set in Vivado) does not map to the Digilet PMOD I2C modules. An adapter cable may be required?
Guest
 

Return to Xillinux (Linux distribution for Zynq-7000)

cron