Access to SPI interface from Linux

Applications, development tools, FPGA, C, WEB
noah
Posts: 33
Joined: Fri Jan 23, 2015 9:53 am
Location: Zurich

Access to SPI interface from Linux

Post by noah » Thu Mar 05, 2015 1:38 pm

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

Nils Roos
Posts: 1441
Joined: Sat Jun 07, 2014 12:49 pm
Location: Königswinter

Re: Access to SPI interface from Linux

Post by Nils Roos » Wed Mar 11, 2015 12:01 am

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.

noah
Posts: 33
Joined: Fri Jan 23, 2015 9:53 am
Location: Zurich

Re: Access to SPI interface from Linux

Post by noah » Wed Mar 11, 2015 8:11 am

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.

noah
Posts: 33
Joined: Fri Jan 23, 2015 9:53 am
Location: Zurich

Re: Access to SPI interface from Linux

Post by noah » Fri Mar 13, 2015 12:25 pm

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!

Nils Roos
Posts: 1441
Joined: Sat Jun 07, 2014 12:49 pm
Location: Königswinter

Re: Access to SPI interface from Linux

Post by Nils Roos » Fri Mar 13, 2015 9:50 pm

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)

noah
Posts: 33
Joined: Fri Jan 23, 2015 9:53 am
Location: Zurich

Re: Access to SPI interface from Linux

Post by noah » Sat Mar 14, 2015 3:08 pm

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!!

Nils Roos
Posts: 1441
Joined: Sat Jun 07, 2014 12:49 pm
Location: Königswinter

Re: Access to SPI interface from Linux

Post by Nils Roos » Sun Mar 15, 2015 12:51 am

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
You do not have the required permissions to view the files attached to this post.

noah
Posts: 33
Joined: Fri Jan 23, 2015 9:53 am
Location: Zurich

Re: Access to SPI interface from Linux

Post by noah » Sun Mar 15, 2015 12:02 pm

Wow, thanks for doing that!! I will test it out soon and perhaps write a little tutorial for others.

Cheers

noah
Posts: 33
Joined: Fri Jan 23, 2015 9:53 am
Location: Zurich

Re: Access to SPI interface from Linux

Post by noah » Fri Mar 20, 2015 2:41 pm

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!!

Nils Roos
Posts: 1441
Joined: Sat Jun 07, 2014 12:49 pm
Location: Königswinter

Re: Access to SPI interface from Linux

Post by Nils Roos » Fri Mar 20, 2015 2:58 pm

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.

Post Reply
jadalnie klasyczne ekskluzywne meble wypoczynkowe do salonu ekskluzywne meble tapicerowane ekskluzywne meble do sypialni ekskluzywne meble włoskie

Who is online

Users browsing this forum: No registered users and 18 guests