Trying to enable SPI slave mode in Nano 2GB

Hi,
I’m trying to enable an SPI port in slave mode, but I’m not well versed in … many things.
I understand the concepts of SPI, and the idea of the DTB but I’ve seen many examples using macros that are not present in the base DTB I’m using (Default image, T32 version 5.1 sources)
I’ve seen references to a tegra210-spi-slave that is not in the source tree, and others to tegra124-spi-slave (which is there).
I do not fully understand the values needed by the driver, nor the required dma/clock/interrupt/reset resources to be referenced when using SPI0 (@7000d400) or SPI1 (@7000d600).

My goal is to keep SPIO as master and have SPI1 as slave to be able to test/debug communication in a single board.

Questions:
1- Is there a reference (explained?) DTB for a slave SPI ?
Would be nice if that included the pin definitions too.
2-Is this documented somewhere so I can do the honours ? (RTFM :-)

Thanks!

You can configure the SPI0/SPI1 by jetson-io and run spidev_test for loopback test.
Have a reference to below topic for the spidev_test loopback test.

Shane,
thanks, loopback test works fine, in master mode obviously. But I want to make master-slave to actually test both sides of the protocol.
jetson-io goes upto the point of assigning pins and drivers, but AFAIK both ports in master mode.
So my questions stand.
After setting the second SPI port as slave by changing the driver to tegra124-spi-slave, I get an error when trying the test mentioned elsewhere:
spi-tegra124-slave 7000d600.spi: Tx is not supported in mode 0
spi-tegra124-slave 7000d600.spi: spi can not start transfer, err -22
so I’m missing something it seems…

Well, I have to read about that “mode 0”. It seems that the slave has no support for buffering TX, but if you ask the slave just to read (and the master just to write) it works.
Still, I’m playing sorcerer’s apprentice here: my slave side has some secret sauce that I don’t know what it does, nor if it’s needed:
spi1_0 {
compatible = “spidev”;
reg = <0x0>;
spi-max-frequency = <0x1f78a40>;
controller-data {
nvidia,cs-setup-clk-count = <0x1e>;
nvidia,cs-hold-clk-count = <0x1e>;
nvidia,rx-clk-tap-delay = <0x1f>;
nvidia,tx-clk-tap-delay = <0x00>;
};
};
which comes from one of the many posts I’ve read on the subject, but I’ve found no docs about.

FTR, here’s the two commands of the test and their output:

$ ./spidev_test -D/dev/spidev1.0 -n1 -s20000 -g12 -p4 -zz -r
Disabling transmit
using device: /dev/spidev1.0
setting spi mode for read,write
setting spi bpw
setting max speed for rd/wr
spi mode: 0
bits per word: 8 bytes per word: 1
max speed: 20000 Hz (20 KHz)
no. runs: 1
Using seed:0x6051e2c7
loop count = 0
transfer: Return actual transfer length: 12
receive packet bytes [12]
0000: FE EE CA AB FF FF FF FF 00 00 00 00
/dev/spidev1.0: TEST PASSED

$ ./spidev_test -D/dev/spidev0.0 -n1 -s20000 -g12 -p4 -zz -t
Disabling receive
using device: /dev/spidev0.0
setting spi mode for read,write
setting spi bpw
setting max speed for rd/wr
spi mode: 0
bits per word: 8 bytes per word: 1
max speed: 20000 Hz (20 KHz)
no. runs: 1
Using seed:0x6051e2cd
loop count = 0
Using rand() buffer
Using crc check
transfer packet bytes [12]
0000: FE EE CA AB FF FF FF FF 00 00 00 00
/dev/spidev0.0: TEST PASSED

The read blocks until the write comes… nice.

FTR, using the “internal” spidev_test, and using -H (clock phase) then bidirectional tests work.
like:

./spidev_test_nv -zz -D/dev/spidev1.0 -n2 -s10000000 -g16 -p1 -H -d1000000 & sleep 1;
./spidev_test_nv -zz -D/dev/spidev0.0 -n2 -s10000000 -g16 -p1 -H -d100

does interchange 2 x 16 bytes messages full duplex.

I don’t really understand why the said spidev_test source code is not made available though…

Hii @ShaneCCC, @tron1

I’m also trying to do the same communication master and slave but gives error for same commands on slave, my results are :-

Master -

$ ./spidev_test -D/dev/spidev1.0 -n1 -s20000 -g12 -p4 -zzz -t
Disabling receive
using device: /dev/spidev1.0
setting spi mode for read,write
setting spi bpw
setting max speed for rd/wr
spi mode: 0
bits per word: 8 bytes per word: 1
max speed: 20000 Hz (20 KHz)
no. runs: 1
Using seed:0x5f6737fa
loop count = 0 
Using rand() buffer 
Using crc check 
transfer packet bytes [12]
0000: FE EE CA AB FF FF FF FF 00 00 00 00 
/dev/spidev1.0: TEST PASSED 
====== Transfer stats ====
Transmit:
       total: 12B (0KiB 0MiB)
       total: 1P 
       ioerr: 0B (0KiB 0MiB)
       ioerr: 0P
 Rate:
  wire total: -1B/s (0KB/s)
       total: -1B/s (0KB/s)
  wire total: -1P/s
       total: -1P/s

  Total time: 0.001363s

Slave -

./spidev_test -D/dev/spidev1.0 -n1 -s20000 -g12 -p4 -zzz -r
Disabling transmit
using device: /dev/spidev1.0
setting spi mode for read,write
setting spi bpw
setting max speed for rd/wr
spi mode: 0
bits per word: 8 bytes per word: 1
max speed: 20000 Hz (20 KHz)
no. runs: 1
Using seed:0x5f673c2b
loop count = 0 

transfer: Return actual transfer length: 12
receive packet bytes [12]
0000: 00 00 00 00 00 00 00 00 00 00 00 00 
transfer: received packet size:12 len:0 stat:-6
/dev/spidev1.0: TEST FAILED !!!!! (status:-1)
====== Transfer stats ====
Receive:
       total: 12B (0KiB 0MiB)
       total: 0P 
        good: 0B (0KiB 0MiB)
        good: 0P
       ioerr: 0P
     dataerr: 0P
 Rate:
        good: 0B/s (0KB/s)
        good: 0P/s
 packet drop: -1/10000

  Total time: 18.685935s

would you suggest me something to remove the error. I’m trying to understand what’s the error.

Thank You.

Could you try below command.

spidev_test -D /dev/spidev1.0 -g 512 -s 11000000 -t -p0 -zzz
spidev_test -D /dev/spidev1.0 -g 512 -s 11000000 -r -p0 -zzz

Hii @ShaneCCC ,

Test on master

ssh root@192.168.0.2
The authenticity of host '192.168.0.2 (192.168.0.2)' can't be established.
ECDSA key fingerprint is SHA256:J/n17748wgm5CS09fvJ7NPzuMrWEFxg/M+FfQZwtBQc.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Failed to add the host to the list of known hosts (/home/kd/.ssh/known_hosts).
"System is booting up. Unprivileged users are not permitted to log in yet. Please come back later. For technical details, see pam_nologin(8)."
root@b2qt-jetson-nano-emmc:~# 
root@b2qt-jetson-nano-emmc:~# 
root@b2qt-jetson-nano-emmc:~# ./spidev_test -D /dev/spidev1.0 -g 512 -s 11000000 -t -p0 -zzz
using device: /dev/spidev1.0
setting spi mode for read,write
setting spi bpw
setting max speed for rd/wr
spi mode: 0
bits per word: 8 bytes per word: 1
max speed: 11000000 Hz (11000 KHz)
no. runs: 1
Using seed:0x5f67332c
loop count = 0 
using sequential pattern ....
transfer bytes [512]
0000: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 
0010: 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 
0020: 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 
0030: 30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 
0040: 40 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 
0050: 50 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F 
0060: 60 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 
0070: 70 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F 
0080: 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F 
0090: 90 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F 
00A0: A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF 
00B0: B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF 
00C0: C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF 
00D0: D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF 
00E0: E0 E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF 
00F0: F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE 00 
0100: 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 
0110: 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 
0120: 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 
0130: 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40 
0140: 41 42 43 44 45 46 47 48 49 4A 4B 4C 4D 4E 4F 50 
0150: 51 52 53 54 55 56 57 58 59 5A 5B 5C 5D 5E 5F 60 
0160: 61 62 63 64 65 66 67 68 69 6A 6B 6C 6D 6E 6F 70 
0170: 71 72 73 74 75 76 77 78 79 7A 7B 7C 7D 7E 7F 80 
0180: 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F 90 
0190: 91 92 93 94 95 96 97 98 99 9A 9B 9C 9D 9E 9F A0 
01A0: A1 A2 A3 A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF B0 
01B0: B1 B2 B3 B4 B5 B6 B7 B8 B9 BA BB BC BD BE BF C0 
01C0: C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF D0 
01D0: D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF E0 
01E0: E1 E2 E3 E4 E5 E6 E7 E8 E9 EA EB EC ED EE EF F0 
01F0: F1 F2 F3 F4 F5 F6 F7 F8 F9 FA FB FC FD FE 00 01 
/dev/spidev1.0: TEST PASSED 
====== Transfer stats ====
Transmit:
       total: 512B (0KiB 0MiB)
       total: 1P 
       ioerr: 0B (0KiB 0MiB)
       ioerr: 0P
 Rate:
  wire total: -1B/s (0KB/s)
       total: -1B/s (0KB/s)
  wire total: -1P/s
       total: -1P/s

  Total time: 0.001099s

Test on slave

./spidev_test -D /dev/spidev1.0 -g 512 -s 11000000 -r -p0 -zzz
using device: /dev/spidev1.0
setting spi mode for read,write
setting spi bpw
setting max speed for rd/wr
spi mode: 0
bits per word: 8 bytes per word: 1
max speed: 11000000 Hz (11000 KHz)
no. runs: 1
Using seed:0x5f673328
loop count = 0 
transfer: Return actual transfer length: 512
receive bytes [512]
0000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00A0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00B0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00C0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00D0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00E0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
00F0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0110: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0120: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0150: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0160: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0170: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0180: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
0190: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
01A0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
01B0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
01C0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
01D0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
01E0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
01F0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 
mismatch index 1 
^^^ 00 00 00 00 00 00 00 00 00 00 00 transfer: received packet size:512 len:512 stat:-6
/dev/spidev1.0: TEST FAILED !!!!! (status:-1)
====== Transfer stats ====
Receive:
       total: 512B (0KiB 0MiB)
       total: 1P 
        good: 0B (0KiB 0MiB)
        good: 0P
       ioerr: 0P
     dataerr: 1P
 Rate:
        good: 0B/s (0KB/s)
        good: 0P/s
 packet drop: -1/10000

  Total time: 1.718782s

Thank You.

Have you connected any pins ?

Hii @tron1,
Yes I have 2 jetson nano connected as master and slave. connected as MISO → MISO, MOSI → MOSI, CS → CS, CLK → CLK

Thank You.

Dump the REG to check if the PINs configuration.

nvidia@nvidia-desktop:~$ sudo cat /sys/kernel/debug/tegra_pinctrl_reg | grep -i spi
[sudo] password for nvidia:
Bank: 1 Reg: 0x70003050 Val: 0x0000e044 -> spi1_mosi_pc0
Bank: 1 Reg: 0x70003054 Val: 0x0000e044 -> spi1_miso_pc1
Bank: 1 Reg: 0x70003058 Val: 0x0000e044 -> spi1_sck_pc2
Bank: 1 Reg: 0x7000305c Val: 0x0000e048 -> spi1_cs0_pc3
Bank: 1 Reg: 0x70003060 Val: 0x0000e048 -> spi1_cs1_pc4
Bank: 1 Reg: 0x70003064 Val: 0x00006044 -> spi2_mosi_pb4
Bank: 1 Reg: 0x70003068 Val: 0x00006044 -> spi2_miso_pb5
Bank: 1 Reg: 0x7000306c Val: 0x00006044 -> spi2_sck_pb6
Bank: 1 Reg: 0x70003070 Val: 0x00006044 -> spi2_cs0_pb7
Bank: 1 Reg: 0x70003074 Val: 0x00006044 -> spi2_cs1_pdd0
Bank: 1 Reg: 0x70003078 Val: 0x0000e015 -> spi4_mosi_pc7
Bank: 1 Reg: 0x7000307c Val: 0x0000e015 -> spi4_miso_pd0
Bank: 1 Reg: 0x70003080 Val: 0x0000e015 -> spi4_sck_pc5
Bank: 1 Reg: 0x70003084 Val: 0x0000e015 -> spi4_cs0_pc6

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.