Usage of SPI 0 and SPI 1

For SAMA5D2 Xplained, SAMA5D3 Xplained and SAMA5D4 Xplained

Moderator: nferre

NTronix
Contact:
Location: Cambridgeshire United Kingdom
Posts: 5
Joined: Thu Jan 27, 2011 1:34 am

Usage of SPI 0 and SPI 1

Wed Jan 27, 2016 1:51 am

This seems to be quite a regular topic so, I thought I'd share my days work with you.

For anyone interested in using SPI on the SAMA5D3 Xplained board and have been left scratching your head wondering why things were not working.

Firstly we are using a custom board, based on SAMA5D3 Xplained. However for the sake of this conversation they can be considered the same thing.

So, we want to use SPI0 with all 4 chip selects and SPI1 with 1 chip select.

Firstly we have to edit : at91-sama5d3_xplained.dts
This can be found in /linux-at91/arch/arm/boot/dts

We edited the DTS to add the correct GPIO's for the chip selects and calls for the spidev device driver

Code: Select all

spi0: spi@f0004000 {
				cs-gpios = <&pioD 13 0>, <&pioD 14 0>, <&pioD 15 0>, <&pioD 16 0>;
				status = "okay";

/*GT*/			spidev@0 {
                                        compatible = "linux,spidev";
                                        spi-max-frequency = <24000000>;
                                        reg = <0>;
                                };

				spidev@1 {
                                        compatible = "linux,spidev";
                                        spi-max-frequency = <24000000>;
                                        reg = <1>;
                                };


				spidev@2 {
                                        compatible = "linux,spidev";
                                        spi-max-frequency = <24000000>;
                                        reg = <2>;
                                };

				spidev@3 {
                                        compatible = "linux,spidev";
                                        spi-max-frequency = <24000000>;
                                        reg = <3>;
                                };


			};
Ok so we save our edits and compile the dtb here and flash the new dtb onto the target board.

This should bring in the drivers for SPI0, you can see if this has worked by looking in /dev/ on your target board.

you should see something like this :-

Code: Select all

ls /dev/spi*
/dev/spidev32766.1	/dev/spidev32766.3
/dev/spidev32766.0  /dev/spidev32766.2
Note that spidev32765 is SPI bus 1 and spidev32766 is SPI bus 0

We also needed to have SPI bus 1, so again we edit the at91-sama5d3_xplained.dts file and modify the entry for spi1

Code: Select all

                                spi1: spi@f8008000 {
				cs-gpios = <&pioC 25 0>, <0>, <0>, <0>;
				status = "okay";

/*GT*/				spidev@0 {
                                        compatible = "linux,spidev";
                                        spi-max-frequency = <24000000>;
                                        reg = <0>;
                                };
As a side note; make sure you have all of the cs-gpios declared even if they are just a <0>

If you don't, the driver doesn't get installed correctly; it took most of the afternoon for me to work this one out. It was not an obvious error.

The default at91-sama5d3_xplained.dts file doesnt correctly specify all 4 cs-gpios it in fact looks like this:-

Code: Select all

                        spi1: spi@f8008000 {
				cs-gpios = <&pioC 25 0>;
				status = "okay";
			};
When used like this, although adding the following driver

Code: Select all

               spidev@0 {
                                        compatible = "linux,spidev";
                                        spi-max-frequency = <24000000>;
                                        reg = <0>;
                                };
Into the declaration and the driver gets installed, the port remains inaccessible and writes to it get ignored.
So all cs-gpios must be included!


Ok so now we want to quicky test each of our newly installed SPI busses, we can do this simply by echoing a known byte or string to the devices for example

echo -ne "\xAA" > /dev/spidev32766.0

This just writes a byte 0xAA to SPI Bus 0 on Chip Select 0.

or

echo -ne "Hello World SPI Bus 0.0" > /dev/spidev32766.0


If you have an oscilloscope you can watch the magic happen.


As a final note, with the most recent Kernel release the inclusion of the "linux,spidev" driver now throws device tree warnings at boot time, thankfully they can just be ignored. Anyone's guess as to why this warning was added to the root kernel build!


Well, I know how much effort I've had to make in order to get through to this stage; I hope this info is helpful to some of you.

Best Regards

Garry Thorn
-Director NTronix Ltd
tonesenna
Posts: 2
Joined: Wed Jul 20, 2016 3:31 am

Re: Usage of SPI 0 and SPI 1

Wed Jul 20, 2016 3:46 am

Hi,

I've been struggling with SPI0 on my ATSAMA5D3 based board without success. Like in your case it's not an SAMA5D3 Xplained board but it is compatible and should be regarded the same software-wise.

On which exact version of the kernel did you make this setup work? I haven't had any luck with linux-4.1 (AT91-linux-5.3) and linux-4.4 (from acmesystems - the board's vendor).

In any case I get this odd message on boot:

Code: Select all

/ahb/apb/spi@f0004000: could not get #gpio-cells for /ahb/apb/sckc@fffffe50/slowck
atmel_spi: probe of f0004000.spi failed with error -22
The error shows only for SPI0, regardless of having SPI1 enabled or not. SPI1 seems to work just fine (although not tested with real hardware)

I'm fairly new to the whole device-tree but is is simple enough to tweak an existing DTS to suit my particular needs. However, when things go south I don't have the skillz (and time) to check whether this is a DTS or kernel bug... So following the example of a proven-working solution is probably my best bet.
tonesenna
Posts: 2
Joined: Wed Jul 20, 2016 3:31 am

Re: Usage of SPI 0 and SPI 1

Wed Jul 20, 2016 10:22 am

I received an answer from acmesystems and it's worth sharing here.

The issue with linux 4.4 (and probably 4.1 as well since it spits out the same message) is that CS3 os SPI0 is shared with a PWM peripheral and the driver isn't able to handle that just yet.

So, for those who don't need CS3 of SPI0 is is enough to leave it disabled on the DTS and replace the corresponding cs-cpios entry with "<0>".

That worked wonders for me :mrgreen:

Thanks.
baranikumar.harman
Posts: 1
Joined: Wed Aug 24, 2016 5:41 pm

Re: Usage of SPI 0 and SPI 1

Wed Aug 24, 2016 5:58 pm

I'm using a custom board which makes use of SAMA5D31 cpu in which i need spi0.0, spi1.0 and spi1.1 interfaces to access the other on-board peripherals such as serialFlash and cpld modules.

After following the tutorial outlined above, I could get the spi1.0 and spi1.1 listed under /dev/ directory which is a good sign that the spi1 is enabled. However, as mentioned in the other post, I'm seeing lot of warning messages as part of the boot log. I am looking at various other forum posts to hide these warnings. Once I get that, I'll post the same here.
Starting kernel ...

...................
...................
...................
atmel_spi f0004000.spi: version: 0x213
atmel_spi f0004000.spi: DMA TX channel not available, SPI unable to use DMA
atmel_spi f0004000.spi: Atmel SPI Controller using PIO only
atmel_spi f0004000.spi: Atmel SPI Controller at 0xf0004000 (irq 26)
atmel_spi f0004000.spi: chipselect 0 already in use
spi_master spi32766: spi_device register error /ahb/apb/spi@f0004000/spidev@0
spi_master spi32766: Failed to create SPI device for /ahb/apb/spi@f0004000/spidev@0
atmel_spi f8008000.spi: version: 0x213
atmel_spi f8008000.spi: Using dma1chan0 (tx) and dma1chan1 (rx) for DMA transfers
atmel_spi f8008000.spi: Atmel SPI Controller at 0xf8008000 (irq 32)
spidev spi32765.0: buggy DT: spidev listed directly in DT
------------[ cut here ]------------
WARNING: CPU: 0 PID: 1 at drivers/spi/spidev.c:731 spidev_probe+0x16c/0x19c()
Modules linked in:
CPU: 0 PID: 1 Comm: swapper Not tainted 4.1.0-linux4sam_5.3 #2
Hardware name: Atmel SAMA5
Backtrace:
[<c0011a6c>] (dump_backtrace) from [<c0011c90>] (show_stack+0x18/0x1c)
r7:000002db r6:c031a89f r5:00000009 r4:00000000
[<c0011c78>] (show_stack) from [<c0281674>] (dump_stack+0x20/0x28)
[<c0281654>] (dump_stack) from [<c001af90>] (warn_slowpath_common+0x8c/0xb4)
[<c001af04>] (warn_slowpath_common) from [<c001b05c>] (warn_slowpath_null+0x24/0x2c)
r8:c037419c r7:00000000 r6:c39c3e00 r5:c39c3e00 r4:c037418c
[<c001b038>] (warn_slowpath_null) from [<c01d3b28>] (spidev_probe+0x16c/0x19c)
[<c01d39bc>] (spidev_probe) from [<c01d15ac>] (spi_drv_probe+0x40/0x44)
r8:c037419c r7:00000000 r6:00000000 r5:c39c3e00 r4:c037418c
[<c01d156c>] (spi_drv_probe) from [<c01a07f0>] (driver_probe_device+0xf4/0x24c)
r5:c0387c4c r4:c39c3e00
[<c01a06fc>] (driver_probe_device) from [<c01a0978>] (__device_attach+0x30/0x4c)
r9:00000000 r8:00000000 r7:c39a6800 r6:c01a0948 r5:c39c3e00 r4:c037419c
[<c01a0948>] (__device_attach) from [<c019ef34>] (bus_for_each_drv+0x8c/0x9c)
r5:c39c3e00 r4:00000000
[<c019eea8>] (bus_for_each_drv) from [<c01a06bc>] (device_attach+0x6c/0x84)
r6:c39c3e34 r5:c39c3e00 r4:c39c3e00
[<c01a0650>] (device_attach) from [<c019fd74>] (bus_probe_device+0x30/0xa0)
r7:c39a6800 r6:c39c3e00 r5:c0374094 r4:c39c3e00
[<c019fd44>] (bus_probe_device) from [<c019e198>] (device_add+0x400/0x50c)
r7:c39a6800 r6:00000000 r5:c39c3e08 r4:c39c3e00
[<c019dd98>] (device_add) from [<c01d1c98>] (spi_add_device+0xd4/0x128)
r10:c031a729 r9:c02fc738 r8:00000000 r7:c3929b10 r6:c39a6800 r5:00000000
r4:c39c3e00
[<c01d1bc4>] (spi_add_device) from [<c01d31e0>] (spi_register_master+0x588/0x698)
r7:00000000 r6:c3f639ec r5:c39c3e00 r4:c39a6800
[<c01d2c58>] (spi_register_master) from [<c01d3324>] (devm_spi_register_master+0x34/0x6c)
r10:00000020 r9:c390c340 r8:c3929b00 r7:c3929b10 r6:c39a6800 r5:c3922cd0
r4:c39a6990
[<c01d32f0>] (devm_spi_register_master) from [<c01d5298>] (atmel_spi_probe+0x480/0x568)
r7:c3929b10 r6:c39a6800 r5:00000000 r4:c39a6990
[<c01d4e18>] (atmel_spi_probe) from [<c01a1de0>] (platform_drv_probe+0x34/0x68)
r10:00000000 r9:c0378fc0 r8:c03741ec r7:00000000 r6:00000000 r5:c03741ec
r4:c3929b10
[<c01a1dac>] (platform_drv_probe) from [<c01a07f0>] (driver_probe_device+0xf4/0x24c)
r5:c0387c4c r4:c3929b10
[<c01a06fc>] (driver_probe_device) from [<c01a0a04>] (__driver_attach+0x70/0x94)
r9:c0378fc0 r8:c03638a0 r7:c036e450 r6:c03741ec r5:c3929b44 r4:c3929b10
[<c01a0994>] (__driver_attach) from [<c019ee60>] (bus_for_each_dev+0x74/0x98)
r7:c036e450 r6:c01a0994 r5:c03741ec r4:00000000
[<c019edec>] (bus_for_each_dev) from [<c01a031c>] (driver_attach+0x20/0x28)
r6:c3a1c080 r5:00000000 r4:c03741ec
[<c01a02fc>] (driver_attach) from [<c019ffc0>] (bus_add_driver+0xe8/0x1d0)
[<c019fed8>] (bus_add_driver) from [<c01a0eac>] (driver_register+0xa4/0xe8)
r7:c03638a0 r6:00000000 r5:c0350f80 r4:c03741ec
[<c01a0e08>] (driver_register) from [<c01a1d98>] (__platform_driver_register+0x50/0x64)
r5:c0350f80 r4:c3967900
[<c01a1d48>] (__platform_driver_register) from [<c0350f98>] (atmel_spi_driver_init+0x18/0x20)
[<c0350f80>] (atmel_spi_driver_init) from [<c00096c4>] (do_one_initcall+0x10c/0x1bc)
[<c00095b8>] (do_one_initcall) from [<c033fdd4>] (kernel_init_freeable+0xf8/0x1b0)
r9:c0378fc0 r8:c035a1e0 r7:c035ef10 r6:c0378fc0 r5:0000003c r4:00000007
[<c033fcdc>] (kernel_init_freeable) from [<c027fbd8>] (kernel_init+0x14/0xe8)
r9:00000000 r8:00000000 r7:00000000 r6:00000000 r5:c027fbc4 r4:c0378fc0
[<c027fbc4>] (kernel_init) from [<c000eea8>] (ret_from_fork+0x14/0x2c)
r5:c027fbc4 r4:00000000
---[ end trace e96354a0dffc233e ]---
spidev spi32765.1: buggy DT: spidev listed directly in DT
------------[ cut here ]------------
WARNING: CPU: 0 PID: 1 at drivers/spi/spidev.c:731 spidev_probe+0x16c/0x19c()
Modules linked in:
CPU: 0 PID: 1 Comm: swapper Tainted: G W 4.1.0-linux4sam_5.3 #2
Hardware name: Atmel SAMA5
Backtrace:
[<c0011a6c>] (dump_backtrace) from [<c0011c90>] (show_stack+0x18/0x1c)
r7:000002db r6:c031a89f r5:00000009 r4:00000000
[<c0011c78>] (show_stack) from [<c0281674>] (dump_stack+0x20/0x28)
[<c0281654>] (dump_stack) from [<c001af90>] (warn_slowpath_common+0x8c/0xb4)
[<c001af04>] (warn_slowpath_common) from [<c001b05c>] (warn_slowpath_null+0x24/0x2c)
r8:c037419c r7:00000000 r6:c39c3000 r5:c39c3000 r4:c037418c
[<c001b038>] (warn_slowpath_null) from [<c01d3b28>] (spidev_probe+0x16c/0x19c)
[<c01d39bc>] (spidev_probe) from [<c01d15ac>] (spi_drv_probe+0x40/0x44)
r8:c037419c r7:00000000 r6:00000000 r5:c39c3000 r4:c037418c
[<c01d156c>] (spi_drv_probe) from [<c01a07f0>] (driver_probe_device+0xf4/0x24c)
r5:c0387c4c r4:c39c3000
[<c01a06fc>] (driver_probe_device) from [<c01a0978>] (__device_attach+0x30/0x4c)
r9:00000000 r8:00000000 r7:c39a6800 r6:c01a0948 r5:c39c3000 r4:c037419c
[<c01a0948>] (__device_attach) from [<c019ef34>] (bus_for_each_drv+0x8c/0x9c)
r5:c39c3000 r4:00000000
[<c019eea8>] (bus_for_each_drv) from [<c01a06bc>] (device_attach+0x6c/0x84)
r6:c39c3034 r5:c39c3000 r4:c39c3000
[<c01a0650>] (device_attach) from [<c019fd74>] (bus_probe_device+0x30/0xa0)
r7:c39a6800 r6:c39c3000 r5:c0374094 r4:c39c3000
[<c019fd44>] (bus_probe_device) from [<c019e198>] (device_add+0x400/0x50c)
r7:c39a6800 r6:00000000 r5:c39c3008 r4:c39c3000
[<c019dd98>] (device_add) from [<c01d1c98>] (spi_add_device+0xd4/0x128)
r10:c031a729 r9:c02fc738 r8:00000000 r7:c3929b10 r6:c39a6800 r5:00000000
r4:c39c3000
[<c01d1bc4>] (spi_add_device) from [<c01d31e0>] (spi_register_master+0x588/0x698)
r7:00000000 r6:c3f63bac r5:c39c3000 r4:c39a6800
[<c01d2c58>] (spi_register_master) from [<c01d3324>] (devm_spi_register_master+0x34/0x6c)
r10:00000020 r9:c390c340 r8:c3929b00 r7:c3929b10 r6:c39a6800 r5:c3922cd0
r4:c39a6990
[<c01d32f0>] (devm_spi_register_master) from [<c01d5298>] (atmel_spi_probe+0x480/0x568)
r7:c3929b10 r6:c39a6800 r5:00000000 r4:c39a6990
[<c01d4e18>] (atmel_spi_probe) from [<c01a1de0>] (platform_drv_probe+0x34/0x68)
r10:00000000 r9:c0378fc0 r8:c03741ec r7:00000000 r6:00000000 r5:c03741ec
r4:c3929b10
[<c01a1dac>] (platform_drv_probe) from [<c01a07f0>] (driver_probe_device+0xf4/0x24c)
r5:c0387c4c r4:c3929b10
[<c01a06fc>] (driver_probe_device) from [<c01a0a04>] (__driver_attach+0x70/0x94)
r9:c0378fc0 r8:c03638a0 r7:c036e450 r6:c03741ec r5:c3929b44 r4:c3929b10
[<c01a0994>] (__driver_attach) from [<c019ee60>] (bus_for_each_dev+0x74/0x98)
r7:c036e450 r6:c01a0994 r5:c03741ec r4:00000000
[<c019edec>] (bus_for_each_dev) from [<c01a031c>] (driver_attach+0x20/0x28)
r6:c3a1c080 r5:00000000 r4:c03741ec
[<c01a02fc>] (driver_attach) from [<c019ffc0>] (bus_add_driver+0xe8/0x1d0)
[<c019fed8>] (bus_add_driver) from [<c01a0eac>] (driver_register+0xa4/0xe8)
r7:c03638a0 r6:00000000 r5:c0350f80 r4:c03741ec
[<c01a0e08>] (driver_register) from [<c01a1d98>] (__platform_driver_register+0x50/0x64)
r5:c0350f80 r4:c3967900
[<c01a1d48>] (__platform_driver_register) from [<c0350f98>] (atmel_spi_driver_init+0x18/0x20)
[<c0350f80>] (atmel_spi_driver_init) from [<c00096c4>] (do_one_initcall+0x10c/0x1bc)
[<c00095b8>] (do_one_initcall) from [<c033fdd4>] (kernel_init_freeable+0xf8/0x1b0)
r9:c0378fc0 r8:c035a1e0 r7:c035ef10 r6:c0378fc0 r5:0000003c r4:00000007
[<c033fcdc>] (kernel_init_freeable) from [<c027fbd8>] (kernel_init+0x14/0xe8)
r9:00000000 r8:00000000 r7:00000000 r6:00000000 r5:c027fbc4 r4:c0378fc0
[<c027fbc4>] (kernel_init) from [<c000eea8>] (ret_from_fork+0x14/0x2c)
r5:c027fbc4 r4:00000000
---[ end trace e96354a0dffc233f ]---

...................
...................
...................

Welcome to Buildroot

buildroot login: root
Password:
login[500]: root login on 'ttyS0'

# ls /dev/spi*
spidev32765.0 spidev32765.1

#


But the serious concern for me is that the spi0.0 is not enabled and throwing an error saying chipselect 0 is already in use. In my opinion, PIOD.13 which is used as CS0 for SPI0 is not used by any other peripheral. So I'm totally confused as to how to proceed further. Has anyone observed this problem and found out a way to solve it?
blue_z
Location: USA
Posts: 1500
Joined: Thu Apr 19, 2007 10:15 pm

Re: Usage of SPI 0 and SPI 1

Thu Aug 25, 2016 11:39 pm

baranikumar.harman wrote:I'm using a custom board which makes use of SAMA5D31 cpu...
The SAMA5D31 is a SoC, not a "cpu". It has an ARM Cortex-A5 processor.
baranikumar.harman wrote:However, as mentioned in the other post, ...
What "other" post?
baranikumar.harman wrote:spidev spi32765.0: buggy DT: spidev listed directly in DT
Based on the log message I'd guess that there are issues in your Device Tree (which you haven't posted for review).

Regards
realbright
Posts: 10
Joined: Mon Jul 07, 2014 2:36 am

Re: Usage of SPI 0 and SPI 1

Thu Sep 01, 2016 7:16 am

blue_z wrote:
baranikumar.harman wrote:I'm using a custom board which makes use of SAMA5D31 cpu...
The SAMA5D31 is a SoC, not a "cpu". It has an ARM Cortex-A5 processor.
baranikumar.harman wrote:However, as mentioned in the other post, ...
What "other" post?
baranikumar.harman wrote:spidev spi32765.0: buggy DT: spidev listed directly in DT
Based on the log message I'd guess that there are issues in your Device Tree (which you haven't posted for review).

Regards
Actually, "buggy DT: spidev listed directly in DT" warning meaningless..

refer the commit log...

Code: Select all

956b200a spi: spidev: Warn loudly if instantiated from DT as "spidev"
If you want eliminate this message just add "linux,spidev" into spidev_dt_ids (drivers/spi/spidev.c)
But this warning message does not effect any spidev operation..
realbright
Posts: 10
Joined: Mon Jul 07, 2014 2:36 am

Re: Usage of SPI 0 and SPI 1

Thu Sep 01, 2016 8:31 am

In case of spi0 creation,

You can check current pin mux through debufs.

Code: Select all

cat /sys/kernel/debug/pinctrl/pinctrl-handles
However, I think it's not a muxing problem.

below logs said, it already another device which occupy "chip select 0" ( reg = <0> in DT ) exist in the same master.
atmel_spi f0004000.spi: chipselect 0 already in use
spi_master spi32766: spi_device register error /ahb/apb/spi@f0004000/spidev@0
spi_master spi32766: Failed to create SPI device for /ahb/apb/spi@f0004000/spidev@0
Please add some debug code to of_register_spi_device() or spi_add_device()

Return to “SAMA5 Xplained”

Who is online

Users browsing this forum: No registered users and 1 guest