R38.2 How to configure the slave mode of spi

hi:

Now there is one spi device on our board. How can I know which device tree configuration it corresponds to. Also, the spi of the soc is a slave device. Do I need special configuration

Hi mingming,

Are you using the devkit or custom board for Thor?
Please check its pinmux spreadsheet and also the device tree configuration for details.

hi:

Are you using the devkit or custom board for Thor? —-》custorm board
Please check its pinmux spreadsheet and also the device tree configuration for details.

  • pinmux spreadsheet ——》Where can I download it

We are working on configuring the thor as an SPI slave device to communicate with an external STM32 MCU acting as the SPI master

I looked at this topic:

SPI Slave Communication Issue on Jetson Orin Nano (JP 6.1, L4T 36.4.0) - Jetson & Embedded Systems / Jetson Orin Nano - NVIDIA Developer Forums

Cannot process SPI Slave Communication In JP 6.0 - Jetson & Embedded Systems / Jetson AGX Orin - NVIDIA Developer Forums

1、How to modify the spi node of the device tree as the slave mode

2、Which code does the linux kernel driver code use as the slave mode

3、How to modify pinmux and where is it located,

nvidia,enable-input = <TEGRA_PIN_DISABLE>; → nvidia,enable-input = <TEGRA_PIN_ENABLE>;

You can download it from Jetson Download Center | NVIDIA Developer.

You can simply configuringnvidia,tegra210-spi-slave as compatible string for SPI slave driver.

SPI slave driver should be spi-tegra124-slave.c.

Please use pinmux spreadsheet to configure them instead.

hi:

i try to port spi-tegra124-slave.c driver from JP5.1.1 to JP7.0,and build,It was found that there were many error reports. Please give it a try and try to correct the error message. thanks

build_error.log (6.6 KB)

Could you just update the device tree and use the SPI slave driver from the source of JP7.0?
(i.e. <Linux_for_Tegra>/source/nvidia-oot/drivers/spi/spi-tegra124-slave.c)

hi:

(i.e. <Linux_for_Tegra>/source/nvidia-oot/drivers/spi/spi-tegra124-slave.c) ——》this ko is okay,

Now I have a question: Why can’t the logs of dev_info and dev_err in the file be printed out? The printk I added myself can be printed out

I also want to confirm that the node corresponding to the device of spi1 on our schematic diagram is this spi1: spi@c6c0000

I’ve not verified that before. For the debug purpose, you can just use printk instead.

It may be depend on the order of driver probe.
Or you can simply refer to https://elinux.org/Jetson/L4T/peripheral/#Mapping for their mapping.

hi:

you can simply refer to https://elinux.org/Jetson/L4T/peripheral/#Mapping for their mapping.—->yes,this use Bus 0: /dev/spidev0.0 => spi0: 810c590000.spi => SPI1 (PJ.07, PK.00, PK.01, PK.02, PK.03)

I want to get this file, but now I find I can’t

wget https://raw.githubusercontent.com/torvalds/linux/v4.9/tools/spi/spidev_test.c

This command seems to be invalid

hi:

I found an address to download this spidev_test.c file

linux/tools/spi/spidev_test.c at master · torvalds/linux · GitHub

Now, the spi1 of the soc is slave mode,What command is needed?

Do you have -t and -r options available for your spidev_test tool?
If so, please refer to the following commands to configure one SPI as master(-t) and another as slave(-r) to verify.
How to set to spi slave mode - #8 by KevinFFF

hi:

This tool of mine doesn’t have the -r option

agi@tegra-ubuntu:~$ sudo ./spidev_test -h
./spidev_test: invalid option – ‘h’
Usage: ./spidev_test [-2348CDFHILMNORSZbdilopsvw]
general device settings:
-D --device device to use (default /dev/spidev1.1)
-s --speed max speed (Hz)
-d --delay delay (usec)
-w --word-delay word delay (usec)
-l --loop loopback
spi mode:
-H --cpha clock phase
-O --cpol clock polarity
-F --rx-cpha-flip flip CPHA on Rx only xfer
number of wires for transmission:
-2 --dual dual transfer
-4 --quad quad transfer
-8 --octal octal transfer
-3 --3wire SI/SO signals shared
-Z --3wire-hiz high impedance turnaround
data:
-i --input input data from a file (e.g. “test.bin”)
-o --output output data to a file (e.g. “results.bin”)
-p Send data (e.g. “1234\xde\xad”)
-S --size transfer size
-I --iter iterations
additional parameters:
-b --bpw bits per word
-L --lsb least significant bit first
-C --cs-high chip select active high
-N --no-cs no chip select
-R --ready slave pulls low to pause
-M --mosi-idle-low leave mosi line low when idle
misc:
-v --verbose Verbose (show tx buffer)

agi@tegra-ubuntu:~$

I executed the following command

there is error log ‘can’t send spi message: Invalid argument’

Upload this source file “spidev_test.c”

spidev_test.c.txt (11.6 KB)

the kernel log

[ 1862.516114] spi0.0: setup 8 bpw, ~cpol, ~cpha, 50000000Hz
[ 1862.516135] spi0.0: child node ‘controller-data’ not found
[ 1862.516598] spi0.0: setup 8 bpw, ~cpol, ~cpha, 50000000Hz
[ 1862.516602] spi0.0: child node ‘controller-data’ not found
[ 1862.516610] spi0.0: setup 8 bpw, ~cpol, ~cpha, 1000000Hz
[ 1862.516614] spi0.0: child node ‘controller-data’ not found
[ 1862.517148] spi-tegra124-slave 810c590000.spi: Tx is not supported in mode 0
[ 1862.517155] spi-tegra124-slave 810c590000.spi: spi can not start transfer, err -22
[ 1862.517169] spi_master spi0: failed to transfer one message from queue
[ 1862.517173] spi_master spi0: noqueue transfer failed

hi:

I obtained this tool from this topic,How to set to spi slave mode - Jetson & Embedded Systems / Jetson Xavier NX - NVIDIA Developer Forums

and Refer to these commands,

echo 55 55 55 55 55 55 55 55 > pattern.txt
3. Run SPI slave
$ sudo ./spidev_test -D /dev/spidev1.0 -s8000000 -g8 -b8 -H -f pattern.txt -n1 -zzz -r

It was found that the test failed.

[ 2157.988893] nvethernet a808d10000.ethernet: [xpcs_lane_bring_up][827][type:0x4][loga-0x0] PCS block lock SUCCESS
[ 2158.046824] spi0: @isr
[ 2158.046835] spi0: CMD[13f01027]: Sl M1 CS0 [HHHH] MSB MSb Rx Pa 8b TRANS[40ff0001]:RDY I:255 B:1
FIFO[80400005]:RxF:0 TxE:64 Err[Cs] RxSTA[E] TxSTA[E]DMA[00000000]: RxTr:0 TxTr:0 B:7
[ 2158.047259] spi_master spi0: transferred[1] != requested[8]
[ 2158.047278] spi_master spi0: CMD[13f01027]: Sl M1 CS0 [HHHH] MSB MSb Rx Pa 8b TRANS[00ff0001]:BSY I:255 B:1
FIFO[00400005]:RxF:0 TxE:64 Err RxSTA[E] TxSTA[E]DMA[00000000]: RxTr:0 TxTr:0 B:7
[ 2158.047306] spi_master spi0: cpu-xfer-err [status:80400005]
[ 2158.047311] spi_master spi0: CMD[13f01027]: Sl M1 CS0 [HHHH] MSB MSb Rx Pa 8b TRANS[00ff0001]:BSY I:255 B:1
FIFO[00400005]:RxF:0 TxE:64 Err RxSTA[E] TxSTA[E]DMA[00000000]: RxTr:0 TxTr:0 B:7
[ 2158.047347] spi_master spi0: failed to transfer one message from queue
[ 2158.047353] spi_master spi0: noqueue transfer failed
[ 2158.980659] nvethernet a808a10000.ethernet: [xpcs_lane_bring_up][827][type:0x4][loga-0x0] PCS block lock SUCCESS

this is my pinmux config,please check it, thanks.

                   spi1_sck_pj7 {
                            nvidia,pins = "spi1_sck_pj7";
                            nvidia,function = "spi1_sck";
                            nvidia,pull = <TEGRA_PIN_PULL_DOWN>;
                            nvidia,tristate = <TEGRA_PIN_ENABLE>;
                            nvidia,enable-input = <TEGRA_PIN_ENABLE>;
                            nvidia,drv-type = <TEGRA_PIN_1X_DRIVER>;
                            nvidia,e-io-od = <TEGRA_PIN_DISABLE>;
                            nvidia,e-lpbk = <TEGRA_PIN_DISABLE>;
                    };
                    spi1_miso_pk0 {
                                nvidia,pins = "spi1_miso_pk0";
                                nvidia,function = "spi1_din";
                                nvidia,pull = <TEGRA_PIN_PULL_DOWN>;
                                nvidia,tristate = <TEGRA_PIN_ENABLE>;
                                nvidia,enable-input = <TEGRA_PIN_ENABLE>;
                                nvidia,drv-type = <TEGRA_PIN_1X_DRIVER>;
                                nvidia,e-io-od = <TEGRA_PIN_DISABLE>;
                                nvidia,e-lpbk = <TEGRA_PIN_DISABLE>;
                        };
                        spi1_mosi_pk1 {
                                nvidia,pins = "spi1_mosi_pk1";
                                nvidia,function = "spi1_dout";
                                nvidia,pull = <TEGRA_PIN_PULL_DOWN>;
                                nvidia,tristate = <TEGRA_PIN_ENABLE>;
                                nvidia,enable-input = <TEGRA_PIN_ENABLE>;
                                nvidia,drv-type = <TEGRA_PIN_1X_DRIVER>;
                                nvidia,e-io-od = <TEGRA_PIN_DISABLE>;
                                nvidia,e-lpbk = <TEGRA_PIN_DISABLE>;
                        };
                        spi1_cs0_pk2 {
                                nvidia,pins = "spi1_cs0_pk2";
                                nvidia,function = "spi1_cs0";
                                nvidia,pull = <TEGRA_PIN_PULL_DOWN>;
                                nvidia,tristate = <TEGRA_PIN_ENABLE>;
                                nvidia,enable-input = <TEGRA_PIN_ENABLE>;
                                nvidia,drv-type = <TEGRA_PIN_1X_DRIVER>;
                                nvidia,e-io-od = <TEGRA_PIN_DISABLE>;
                                nvidia,e-lpbk = <TEGRA_PIN_DISABLE>;
                        };

hi:

Now, the mcu as the master device and thor as the slave device. An error was detected during communication

Could you use another SPI interface as Master with -t option to transfer the data?

hi:

now soc such as master,mcu such as slave,tesk ok

Do you have further question about this?

hi:

There’s nothing left.

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