Open Source > Open source hardware

ZynqBerry SPI

(1/3) > >>

Hello everyone!

I'm trying to interface an SPI device with my ZynqBerry board. For that I enabled Zynq PS' SPI0 on my hardware project and routed it via EMIO to the J8 connector of the board.
Then on PetaLinux I made sure that 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. Finally I also added to my system-top.dts file the following lines:

&spi1 {
  is-decoded-cs = <0>;
  num-cs = <1>;
  status = "okay";
  spidev@0x00 {
    compatible = "spidev";
    spi-max-frequency = <1000000>;
    reg = <0>;

For now I just to want to test a single SPI slave to verify if everything is working correctly. Later I'll need 4 SPI slaves connected to the same master and I know that I'll need a slave decoder but one step at a time.
PetaLinux creates a /dev/spidev32765.0 interface. I've connected to my board a LSM9DS0 breakout board from Adafruit and I want to probe this device only to see if SPI is working correctly. I've researched the subject and I found that everyone uses the spidev_test.c application for that purpose. I've compiled it with the following command:

arm-xilinx-linux-gnueabi-gcc -o spidevtest /opt/Petalinux/petalinux-v2016.2-final/components/linux-kernel/xlnx-4.4/Documentation/spi/spidev_test.c

This will create a new file named spidevtest on that directory. Then I copy that file to PetaLinux via SSH (with scp command) to /usr/ directory. Then I try to run the application:

./spidevtest -d /dev/spidev32765.0

But nothing happens and I get the following response:

-sh: ./spidevtest: No such file or directory

Am I missing something? Is there a simpler way to probe SPI from the command line with a tool such i2c-tools for I2C ?

Thanks for the attention!

Best regards,


Andrei Errapart:
Before running the application, add the execute permission to the file as follows:

--- Code: ---chmod +x spidevtest
--- End code ---

Without it the Linux kernel won't recognize the file as executable. Let me note that the Linux kernel itself has no concept of file extensions. The dot "." does play a special role: there are special directories named "." and ".." and there is a convention that filenames beginning with dot are usually hidden from the user unless requested for.

The program you are using should suffice for most of the needs for SPI testing. I am not aware of any other tools that come with petalinux. Creating a corresponding petalinux application is trivial, though.

The name of the device created can be changed by adding aliases to the device tree, for example, as follows:

--- Code: ---aliases {
   spi100 = &spi0; // creates /dev/spidev100

--- End code ---

I have found (out the hard way) that alias named "spi0" will cause u-boot to search for the root image on the SPI flash memory connected to this bus and boot will fail when this is not the case, that's why the "spi100" in the example. Depending on your circumstances, this might not apply to you.

Hello Andrei, thanks for the reply!

I did try the chmod command but without success. Nevertheless was able to compile spidev_test.c with PetaLinux.
This is what I did:
I've created a new C application with the petalinux-create command and replaced the default code with spidev_test.c source code. With this Petalinux successfully compiles the code and I can successfully run the application created.

Maybe the problem was that Petalinux uses a different compiler than I was using.

Right now I am able to test SPI but I still couldn't get it to work.
I'm using an oscilloscope to see SPI chip select and clock signals but I get no activity in both of them.

I believe that I routed them correctly in Vivado. Any ideas?

Best regards.

Andrei Errapart:
Can you try without the line

--- Code: ---status = "okay";
--- End code ---

Does regenerating the FSBL help? The FSBL contains the initialization code for the various Zynq devices. Without initialization the devices (incl. SPI) will remain disabled for Linux, too.

The petalinux uses the hardware floating-point version of the toolchain; the C compiler executable should be "arm-linux-gnueabihf-gcc" and you can find it in the Petalinux installation directory, too.

Hello Andrei. Thanks for the reply!

The problem was that added to my system-top.dts file &spi1, but I enabled SPI0 in Vivado. Once this was corrected eveything was working fine.

Right now I'm trying to read a specific register from my SPI device but still without success. Any hints on how to modify spidev_test.c to read a specific register and print the response on the terminal?

Best regards


[0] Message Index

[#] Next page

Go to full version