SPI1 read issue

When using spidev_test to read from SPI1, I found that there’s a high probability of data errors (some bits get skipped), but the oscilloscope shows that the waveform is correct every time. write is ok.spidev_test was compiled using the kernel source code. It seems related to spi controller driver or spidev driver(r38.2.1)

root@tegra-ubuntu:/home/tj_software/test# ./spidev_test -D /dev/spidev0.0 -s 100000 -p "\x03\x02\x00\x00" -v
spi mode: 0x0
bits per word: 8
max speed: 100000 Hz (100 kHz)
TX | 03 02 00 00 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  |....|
RX | 00 00 00 25 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  |...%|
root@tegra-ubuntu:/home/tj_software/test# ./spidev_test -D /dev/spidev0.0 -s 100000 -p "\x03\x02\x00\x00" -v
spi mode: 0x0
bits per word: 8
max speed: 100000 Hz (100 kHz)
TX | 03 02 00 00 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  |....|
RX | 00 00 00 25 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  |...%|
root@tegra-ubuntu:/home/tj_software/test# ./spidev_test -D /dev/spidev0.0 -s 100000 -p "\x03\x02\x00\x00" -v
spi mode: 0x0
bits per word: 8
max speed: 100000 Hz (100 kHz)
TX | 03 02 00 00 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  |....|
RX | 00 00 00 25 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  |...%|
root@tegra-ubuntu:/home/tj_software/test# ./spidev_test -D /dev/spidev0.0 -s 100000 -p "\x03\x02\x00\x00" -v
spi mode: 0x0
bits per word: 8
max speed: 100000 Hz (100 kHz)
TX | 03 02 00 00 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  |....|
RX | 00 00 00 25 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  |...%|
root@tegra-ubuntu:/home/tj_software/test# ./spidev_test -D /dev/spidev0.0 -s 100000 -p "\x03\x02\x00\x00" -v
spi mode: 0x0
bits per word: 8
max speed: 100000 Hz (100 kHz)
TX | 03 02 00 00 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  |....|
RX | 00 00 00 6D __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  |...m|
root@tegra-ubuntu:/home/tj_software/test# ./spidev_test -D /dev/spidev0.0 -s 100000 -p "\x03\x02\x00\x00" -v
spi mode: 0x0
bits per word: 8
max speed: 100000 Hz (100 kHz)
TX | 03 02 00 00 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  |....|
RX | 00 00 00 25 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  |...%|
root@tegra-ubuntu:/home/tj_software/test#
root@tegra-ubuntu:/home/tj_software/test# ./spidev_test -D /dev/spidev0.0 -s 100000 -p "\x03\x02\x00\x00" -v
spi mode: 0x0
bits per word: 8
max speed: 100000 Hz (100 kHz)
TX | 03 02 00 00 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  |....|
RX | 00 00 00 05 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  |....|
root@tegra-ubuntu:/home/tj_software/test# ./spidev_test -D /dev/spidev0.0 -s 100000 -p "\x03\x02\x00\x00" -v
spi mode: 0x0
bits per word: 8
max speed: 100000 Hz (100 kHz)
TX | 03 02 00 00 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  |....|
RX | 00 00 00 25 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  |...%|
root@tegra-ubuntu:/home/tj_software/test# ./spidev_test -D /dev/spidev0.0 -s 100000 -p "\x03\x02\x00\x00" -v
spi mode: 0x0
bits per word: 8
max speed: 100000 Hz (100 kHz)
TX | 03 02 00 00 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  |....|
RX | 00 00 00 65 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  |...e|
root@tegra-ubuntu:/home/tj_software/test# ./spidev_test -D /dev/spidev0.0 -s 100000 -p "\x03\x02\x00\x00" -v
spi mode: 0x0
bits per word: 8
max speed: 100000 Hz (100 kHz)
TX | 03 02 00 00 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  |....|
RX | 00 00 00 25 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  |...%|
root@tegra-ubuntu:/home/tj_software/test# ./spidev_test -D /dev/spidev0.0 -s 100000 -p "\x03\x02\x00\x00" -v
spi mode: 0x0
bits per word: 8
max speed: 100000 Hz (100 kHz)
TX | 03 02 00 00 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  |....|
RX | 00 00 00 21 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  |...!|
root@tegra-ubuntu:/home/tj_software/test# ./spidev_test -D /dev/spidev0.0 -s 100000 -p "\x03\x02\x00\x00" -v
spi mode: 0x0
bits per word: 8
max speed: 100000 Hz (100 kHz)
TX | 03 02 00 00 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  |....|
RX | 00 00 00 21 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  |...!|
root@tegra-ubuntu:/home/tj_software/test# ./spidev_test -D /dev/spidev0.0 -s 100000 -p "\x03\x02\x00\x00" -v
spi mode: 0x0
bits per word: 8
max speed: 100000 Hz (100 kHz)
TX | 03 02 00 00 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  |....|
RX | 00 00 00 2D __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  |...-|
root@tegra-ubuntu:/home/tj_software/test# ./spidev_test -D /dev/spidev0.0 -s 100000 -p "\x03\x02\x00\x00" -v
spi mode: 0x0
bits per word: 8
max speed: 100000 Hz (100 kHz)
TX | 03 02 00 00 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  |....|
RX | 00 00 00 25 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  |...%|

Hi wpceswpces,

How do you confirm this?
Do you mean the TX/RX line reported from spidev_test is different?

Where do you get the source for spidev_test?

Do you confirm the voltage level is correct and the data is the same as you sent? (i.e. 0x3 0x2 0x0 0x0)

Hi,KevinFFF

Yes, we checked the MISO, and the waveform level is the same every time.

root@tegra-ubuntu:/home/tj_software# dmesg |grep spi
[   12.438722] spi-tegra114 c6c0000.spi: Adding to iommu group 46
[   12.451548] spi-tegra114 810c590000.spi: Adding to iommu group 47
[   12.480899] spi-tegra114 810c440000.spi: Adding to iommu group 49
[   12.513484] spi-tegra114 810c450000.spi: Adding to iommu group 52
[   15.855850] Modules linked in: qrtr bridge stp llc usb_f_ncm nvidia(O+) usb_f_mass_storage usb_f_acm u_serial governor_pod_scaling(O) usb_f_rndis u_ether libcomposite snd_soc_tegra210_admaif snd_soc_tegra210_mixer snd_soc_tegra186_arad(O) snd_soc_tegra186_asrc snd_soc_tegra210_mvc snd_soc_tegra_pcm snd_soc_tegra210_ope snd_soc_tegra210_sfc snd_soc_tegra210_adx snd_soc_tegra210_amx snd_soc_tegra210_i2s snd_soc_tegra210_ahub tegra210_adma spidev nvadsp(O) nvvrs_pseq_rtc(O) tegra_capture_coe(O) ina238 cfg80211 ina3221 ngbe(OE) tegra23x_psc(O) rfkill tegra_cactmon_mc_all(O) tegra_aconnect tegra_aocluster(O) snd_hda_codec_hdmi at24 snd_hda_tegra snd_hda_codec snd_soc_rt5640 snd_hda_core snd_soc_rl6231 mttcan(O) host1x_fence(O) can_dev pwm_tegra_tachometer(O) spi_tegra114 mc_t26x(O) tegra264_mc_hwpm(O) nvmap(O) nvidia_vrs_pseq(O) lm90 nvethernet(O) crct10dif_ce coresight_trbe nvsciipc(O) sm3_ce coresight nvpps(O) ivc_cdev(O) sm3 sha3_ce sha512_ce arm_spe_pmu sha512_arm64 nvidia_cspmu snd_soc_tegra_audio_graph_card
root@tegra-ubuntu:/home/tj_software#

Hi,KevinFFF

Any progress on this issue?

[   12.255897] spi_master spi0: cannot find modalias for /bus@0/spi@810c590000/controller-data
[   12.255929] spi_master spi0: Failed to create SPI device for /bus@0/spi@810c590000/controller-data

Do you have any customization in SPI causing above errors? They are unexpected result to me.

Could you use the following spidev_test binary instead?
spidev_test (107.3 KB)
You can simply run the following command to verify.

$ sudo ./spidev_test -D /dev/spidev0.0 -v -p "HelloWorld123456789abcdef"

Hi,KevinFFF

That’s strange, I haven’t encountered this error. Everything looks normal in my dmesg, I only modified the pinmux for spi1.

root@tegra-ubuntu:/home/tj_software# dmesg |grep spi
[   11.883059] spi-tegra114 c6c0000.spi: Adding to iommu group 45
[   11.925432] spi-tegra114 810c590000.spi: Adding to iommu group 46
[   11.935820] spi-tegra114 810c440000.spi: Adding to iommu group 48
[   11.946088] spi-tegra114 810c450000.spi: Adding to iommu group 49
[   15.356276] Modules linked in: qrtr bridge stp llc usb_f_ncm usb_f_mass_storage nvidia(O+) governor_pod_scaling(O) usb_f_acm u_serial usb_f_rndis u_ether libcomposite snd_soc_tegra186_asrc snd_soc_tegra210_mixer snd_soc_tegra186_arad(O) snd_soc_tegra210_mvc snd_soc_tegra210_ope snd_soc_tegra210_sfc snd_soc_tegra210_admaif snd_soc_tegra210_i2s snd_soc_tegra_pcm snd_soc_tegra210_adx snd_soc_tegra210_amx cfg80211 snd_soc_tegra210_ahub rfkill tegra210_adma tegra_capture_coe(O) spidev nvvrs_pseq_rtc(O) crct10dif_ce sm3_ce sm3 sha3_ce sha512_ce sha512_arm64 nvmap(O) coresight_trbe ina3221 ina238 coresight snd_soc_tegra_audio_graph_card nvsciipc(O) ivc_cdev(O) snd_soc_audio_graph_card arm_spe_pmu snd_soc_simple_card_utils tegra234_oc_event(O) nvpmodel_clk_cap(O) tegra_cactmon_mc_all(O) tegra_aconnect nvethernet(O) ngbe(OE) tegra23x_psc(O) thermal_trip_event(O) snd_hda_codec_hdmi snd_soc_rt5640 snd_soc_rl6231 at24 lm90 snd_hda_tegra nvidia_vrs_pseq(O) snd_hda_codec snd_hda_core mttcan(O) host1x_fence(O) nvpps(O) nvidia_cspmu
[   15.356320]  can_dev pwm_tegra_tachometer(O) spi_tegra114 ramoops reed_solomon tegra_dce(O) arm_cspmu_module nvhost_nvcsi(O) tegra_se(O) nvhost_vi5(O) tegra_se_kds(O) nvhost_pva(O) nvhost_capture(O) crypto_engine tpm_ftpm_tee camera_diagnostics(O) nvhost_isp5(O) tegra_capture_isp(O) tegra_camera(O) v4l2_dv_timings host1x_nvhost(O) tegra_drm(O) tegra_wmark(O) nvhwpm(O) drm_display_helper drm_dp_aux_bus cec drm_kms_helper host1x(O) tegra_camera_platform(O) mc_utils(O) capture_ivc(O) v4l2_fwnode v4l2_async videobuf2_dma_contig videobuf2_memops videobuf2_v4l2 videodev videobuf2_common mc camchar(O) rtcpu_debug(O) tegra_camera_rtcpu(O) ivc_bus(O) hsp_mailbox_client(O) nvme_fabrics fuse drm nfnetlink ip_tables x_tables ipv6 pwm_fan pwm_tegra tegra_bpmp_thermal tegra_xudc uas ucsi_ccg typec_ucsi typec nvme nvme_core phy_tegra194_p2u pcie_tegra194 ufs_tegra(O) pcie_tegra264(O)
root@tegra-ubuntu:/home/tj_software#

The spidev_test you provided has an error, it report “Transaction length not specified”

root@tegra-ubuntu:/home/tj_software/nv# sudo ./spidev_test -D /dev/spidev0.0 -v -p "HelloWorld123456789abcdef"
Transaction length not specified
Usage: ./spidev_test [options]
 version 21
  -D --device   device to use (default /dev/spidev0.0)
  -s --speed    max speed (Hz)
  -g --length   transaction length in bytes. Multiple lengths can be comma separated.
  -z --debug    enable debug mode. Specifying more than once to increase the verboisty.
  -p --pattern  choose pattern type. Available patterns are:
                0: sequential bytes
                1: even bytes
                2: odd bytes
                3: reverse sequential bytes
                4: random bytes with crc
  -F prefix     Dump rx/tx buffer as raw to file. With no prefix specified, current pid will be used
  -f --file     Pattern file. User defined pattern. Not allowed with -p option.
                Pattern file must be in space seperated bytes in hex without
                "0x" prefix. Sample data: 01 AA 23 5F 3C 12
  -d --delay    delay (usec). For SPI master this will be the minimum delay
                the driver waits before initiating each transfer. For slave
                this indicates the max delay that the slave waits before it times out.
  -E --expect   Expected transaction length in bytes.
                To test variable length data transfer feature.
                Without this option, spidev_test will assume it as normal transfer
                and will validate the actual transferred length with requested transaction length.
                Value should be less than or equal to the transaction length.
  -b --bpw      bits per word
  -H --cpha     clock phase
  -O --cpol     clock polarity
  -L --lsb      least significant bit first
  -C --cs-high  chip select active high
  -c --cnt      continuous pause mode 1: start or 2:stop controller.
  -n --nruns    Number of times to repeat the test. -1 is infinite.
  -u --udelay   delay b/w initiating each transfer (usec). Multiple delays can be comma separated
  -r --receive  only receive data
  -t --transmit only transmit data
  -v --minsize  variable length packet start
  -V --maxsize  variable length packet end
  -W --waitb4   wait for a keystroke before the first transfer
  -w --stoperr  stop on all errors
  -P --packet   packet mode

Examples:
To transfer 100 messages of 30 bytes each with random bytes,
  spidev_test -D/dev/spidev0.0 -s18000000 -n100 -g30 -p4

To transfer 100 messages of sizes 8 and 3986 with delay of 2ms and 8ms respectively,
  spidev_test -D/dev/spidev0.0 -s18000000 -n100 -g8,3968 -u2000,8000

To transfer all bytes from user defined pattern file,
  spidev_test -D/dev/spidev0.0 -s18000000 -f/path/to/patternfile

To test variable length feature,
  spidev_test -D/dev/spidev0.0 -s18000000 -g 30 -E 20

Return codes:
 0   successfull transfer. This would mean that what was
     transferred was actually received. Note that a success
     would make sense only when the spi is run in a loopback
     type configuration, i.e., a miso-mosi loopback or a
     master-slave loopback
 1   Invalid argument
 5   I/O error
 6   Data mismatch error. The transfer happened but there is
     mismatch in tx and rx pattern. Again this makes sense only
     for loopback as explained above
 22  Invalid argument
root@tegra-ubuntu:/home/t

I tried it on my side, and I can receive data without the short circuit, though there are many errors. But now, after the hardware is wired for the short circuit(MISO MOSI), I am not receiving anything.

root@tegra-ubuntu:/home/tj_software# sudo ./spidev_test -D /dev/spidev0.0 -v -p "HelloWorld123456789abcdef"
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 kHz)
TX | 48 65 6C 6C 6F 57 6F 72 6C 64 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66 __ __ __ __ __ __ __  |HelloWorld123456789abcdef|
RX | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 __ __ __ __ __ __ __  |.........................|
root@tegra-ubuntu:/home/tj_software# sudo ./spidev_test -D /dev/spidev0.0 -v -p "HelloWorld123456789abcdef"
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 kHz)
TX | 48 65 6C 6C 6F 57 6F 72 6C 64 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66 __ __ __ __ __ __ __  |HelloWorld123456789abcdef|
RX | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 __ __ __ __ __ __ __  |.........................|
root@tegra-ubuntu:/home/tj_software# sudo ./spidev_test -D /dev/spidev0.0 -v -p "HelloWorld123456789abcdef"
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 kHz)
TX | 48 65 6C 6C 6F 57 6F 72 6C 64 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66 __ __ __ __ __ __ __  |HelloWorld123456789abcdef|
RX | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 __ __ __ __ __ __ __  |.........................|
root@tegra-ubuntu:/home/tj_software# sudo ./spidev_test -D /dev/spidev0.0 -v -p "HelloWorld123456789abcdef"
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 kHz)
TX | 48 65 6C 6C 6F 57 6F 72 6C 64 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66 __ __ __ __ __ __ __  |HelloWorld123456789abcdef|
RX | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 __ __ __ __ __ __ __  |.........................|

Are you using the devkit or custom board for Thor?

Have you configured the pinmux for SPI before use?
Please share the full dmesg and device tree as files here for further check.

Hi,KevinFFF

dts.tar.gz (97.5 KB)

dmesg.txt (130.3 KB)

I am using the custom boart , I checked that SPI1 is not exposed on the devkit. I have already configured the pin multiplexing.This is my device tree, please help me take a look, thank you very much.

Hi,KevinFFF

I suspect that the reason why I can’t receive data after the loopback of MISO and MOSI is because the previous slave device hasn’t been disconnected. It is controlling the MISO pin. Now the loopback works, but why does reading the slave register result in unstable and fluctuating values? it may related to the slave ….

root@tegra-ubuntu:~# spidev_test -D /dev/spidev0.0 -v -p "HelloWorld123456789abcdef"
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 kHz)
TX | 48 65 6C 6C 6F 57 6F 72 6C 64 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66 __ __ __ __ __ __ __  |HelloWorld123456789abcdef|
RX | 48 65 6C 6C 6F 57 6F 72 6C 64 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66 __ __ __ __ __ __ __  |HelloWorld123456789abcdef|
root@tegra-ubuntu:~#
root@tegra-ubuntu:~#
root@tegra-ubuntu:~# spidev_test -D /dev/spidev0.0 -v -p "HelloWorld123456789abcdef"
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 kHz)
TX | 48 65 6C 6C 6F 57 6F 72 6C 64 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66 __ __ __ __ __ __ __  |HelloWorld123456789abcdef|
RX | 48 65 6C 6C 6F 57 6F 72 6C 64 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66 __ __ __ __ __ __ __  |HelloWorld123456789abcdef|
root@tegra-ubuntu:~# spidev_test -D /dev/spidev0.0 -v -p "HelloWorld123456789abcdef"
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 kHz)
TX | 48 65 6C 6C 6F 57 6F 72 6C 64 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66 __ __ __ __ __ __ __  |HelloWorld123456789abcdef|
RX | 48 65 6C 6C 6F 57 6F 72 6C 64 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66 __ __ __ __ __ __ __  |HelloWorld123456789abcdef|
root@tegra-ubuntu:~# spidev_test -D /dev/spidev0.0 -v -p "HelloWorld123456789abcdef"
spi mode: 0x0
bits per word: 8
max speed: 500000 Hz (500 kHz)
TX | 48 65 6C 6C 6F 57 6F 72 6C 64 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66 __ __ __ __ __ __ __  |HelloWorld123456789abcdef|
RX | 48 65 6C 6C 6F 57 6F 72 6C 64 31 32 33 34 35 36 37 38 39 61 62 63 64 65 66 __ __ __ __ __ __ __  |HelloWorld123456789abcdef|

SPI transaction depends on the CS toggle.
When the CS is asserted, then the SPI master will send/receive data from MISO and MOSI.
It is not expected to connect other SPI slave device when you were performing the SPI loopback test.