Page 1 of 2

Access to SPI interface from Linux

Posted: Thu Mar 05, 2015 1:38 pm
by noah
Hi all!

I'd like to make use of the SPI interface. I see that its already done in the hardware platform:

Code: Select all

redpitaya> dmesg | grep spi
xspips e0006000.ps7-spi: master is unqueued, this is deprecated
xspips e0006000.ps7-spi: at 0xE0006000 mapped to 0xE0866000, irq=58
xspips e0007000.ps7-spi: master is unqueued, this is deprecated
xspips e0007000.ps7-spi: at 0xE0007000 mapped to 0xE0868000, irq=81
xqspips e000d000.ps7-qspi: master is unqueued, this is deprecated
xqspips e000d000.ps7-qspi: at 0xE000D000 mapped to 0xE086A000, irq=51
Unlike i2c it doesn't yet appear in the /dev/ dir (but it does under /sys/dev/spi). How much effort lies behind it?

Thanks in advance

Re: Access to SPI interface from Linux

Posted: Wed Mar 11, 2015 12:01 am
by Nils Roos
Some browsing through Xilinx forums and the devicetree.dts from a RedPitaya build turned up the following:

To make linux aware of specific devices connected to the SPI bus, add devicetree nodes to the ps7_spi_0/1 section of the devicetree (eg by modifying this patch).
See also wiki: SPI driver, thread on Xilinx forum and the ps7_i2c_0 section of the devicetree.dts

I you want generic usermode access to the SPI bus, the kernel needs to be rebuilt with the SPI_SPIDEV option enabled (rp_defconfig)

I didn't try any of that yet, and I have no SPI devices on hand for experimenting, so these are just some pointers where to start. If you get the bus running but experience problems actually communicating with your device, this bug in the ZYNQ silicon may be of relevance.

Re: Access to SPI interface from Linux

Posted: Wed Mar 11, 2015 8:11 am
by noah
Thanks for your reply. I also searched the xlilinx forums but didn't catch a right clue, so tahnks for your hints. I'll try to modify the kernel to get usermode access as soon as i find the time.

Re: Access to SPI interface from Linux

Posted: Fri Mar 13, 2015 12:25 pm
by noah
So I managed to modify and rebuild the kernel for SPI usermode access. but nothing really changed.

How can I force mdev to mount the device? Or are additional drivers needed?

Thanks for your help!

Re: Access to SPI interface from Linux

Posted: Fri Mar 13, 2015 9:50 pm
by Nils Roos
Did you also add a spidev to the appropriate slave select signal and SPI device in the devicetree ?

Something like:

Code: Select all

ps7_spi_0: ps7-spi@e0006000 {
...
	spidev@0{
		compatible="spidev";
		reg =<0>; //chipselect 0
		spi-max-frequency= <50000000>;
	};
};
(assuming you connected your device to SS0 on SPI 0)

Re: Access to SPI interface from Linux

Posted: Sat Mar 14, 2015 3:08 pm
by noah
i had strugle finding the devicetree sources, could you briefly explain how and where i can modify them or is there already a topic i can get more info on that?

Thanks very much Nils!!

Re: Access to SPI interface from Linux

Posted: Sun Mar 15, 2015 12:51 am
by Nils Roos
Sorry, I could have been clearer earlier.
The devicetree source is generated during the build. Unless you want to get messy with the tcl scripts involved, the best way to make changes to the devicetree is to modify this patch (FPGA/release1/fpga/image/src/device_tree_vivado.patch). It is applied to the devicetree.dts after it has been generated.

I had a look, the SPI connections that are available at the E2 connector belong to ps7_spi_1, SS0.
I prepared a modified version of the patch and tested it. It's attached to this post. To use it, unzip and copy it to FPGA/release1/fpga/image/src/ and delete FPGA/patches/bsp/devicetree_vivado_patch.patch , then rebuild the ecosystem.
The device will show up as /dev/spidev2.0

Re: Access to SPI interface from Linux

Posted: Sun Mar 15, 2015 12:02 pm
by noah
Wow, thanks for doing that!! I will test it out soon and perhaps write a little tutorial for others.

Cheers

Re: Access to SPI interface from Linux

Posted: Fri Mar 20, 2015 2:41 pm
by noah
OK, so I managed to rebuild the necessary files, so I do now have the device under /dev/spidev2.0. I can open it from a C file and using ioctl to write, but the output on the pins is kind of messy and noisy. Did you test it? Do you mind sharing your test code?

Thank you!!

Re: Access to SPI interface from Linux

Posted: Fri Mar 20, 2015 2:58 pm
by Nils Roos
For a test I just tried to read from the device with "cat /dev/spidev2.0" while observing the external connections with the scope app. I also thought the clock looked a bit messy, but not severely so. I still don't have any SPI slave to connect to E2, so I did not test in more depth with an actual device.

You could try to reduce the max clock for the device in the devicetree if you experience problems with a connected slave.