Showing results for 
Show  only  | Search instead for 
Did you mean: 
Registered: ‎02-04-2021

Establish SPI in Zynq PS


I want to communicate from Zynq board to an external device through SPI. The external device is stacked on top of Zynq boardon the GPIO pins. Firstly, in vivado hardware design, I selected Zynq PS and enabled SPI0 and SPI1. Then,  I enabled the SPI Device drivers in petalinux kernel configuration (Cadence SPI controller, Xilinx SPI controller common module, Xilinx Zynq QSPI controller and User mode SPI device driver support are all enabled on the kernel configuration menu).
I added below entry to device tree (system-user.dtsi). The entire contents of system-user.dtsi is as below:

/include/ "system-conf.dtsi"
/ {
/* USB PHY */
    usb_phy0: usb_phy@0 {
        compatible = "ulpi-phy";
        #phy-cells = <0>;
        reg = <0xe0002000 0x1000>;
        view-port = <0x0170>;
&usb0 {
   dr_mode = "host";
   //dr_mode = "peripheral";
    usb-phy = <&usb_phy0>;
} ;

   status = "okay";
    axispidevice: spidev@0 {
         compatible = "spidev";
          reg = <0>;
           spi-max-frequency = <3125000>;

Now there is spi available at /dev/spi1.0 but, when I run my program to communicate with the external device it fails. I want to test the spi communication.
I did a loopback test by connecting the pin 19 and pin 21 (MISO and MOSI pins) and running the program which is available at this website.
I am receiving only x"00" not the sent data.

root@arm:/home/pi/Dexter# ./spidev_test -D /dev/spidev1.0                                             
spi mode: 0                                                                                           
bits per word: 8                                                                                       
max speed: 500000 Hz (500 KHz)                                                                         
00 00 00 00 00 00                                                                                     
00 00 00 00 00 00                                                                                     
00 00 00 00 00 00                                                                                     
00 00 00 00 00 00                                                                                     
00 00 00 00 00 00                                                                                     
00 00 00 00 00 00                                                                                     
00 00       

I believe the MISO and MOSI pins are the same as in raspberrypi. Please correct me if I am wrong and how can I confirm the MISO and MOSI pins in Zynq board?
Could someone help me if the steps I followed to enable SPI is correct? or how can I check if the spi is enabled correctly or not?

Thanks in advance.

Tags (2)
0 Kudos
2 Replies
Registered: ‎04-09-2019

Hi @deepak Since you are able to see the following /dev/spi1.0 which means that the controller is enabled in the design.

Your process is correct.



0 Kudos
Registered: ‎02-04-2021

Hello @venui .

Thanks for the reply.

I made the SPI clk and SPI chip_select signals also as external pins and routed them to respective GPIO pins.

J8 Pin      Name       Zynq Pin         Signal
19           GPIO10       H14         SPI0_MOSI_O_0
21           GPIO9         J13          SPI0_MISO_I_0
23           GPIO11       J15          SPI0_SCLK_O_0
24           GPIO8         L15          SPI0_SS_O_0

I assigned the signals to the respective GPIO pins based on the Brickpi3 schematics I got from these websites.

The spi loopback test ( receives the sent data when I loop the GPIO 19 and 21 pins and run the program.
But still the same error when trying to communicate with Brickpi3 "No SPI Response".

Could you please tell me how I can troubleshoot this error further ?

Thanks for your time and consideration.

Best Regards

0 Kudos