怎么使用spi接口?

我的电路板需要使用spi0(89,91,93,95)来跟从机通信,我修改了设备树和内核后,在/dev/目录下可以找到spidev1.0设备,但是我打开设备跟从机通信时,示波器测量不出波形,我确保我的测试程序是ok的

	spi@c260000 {
		//status = "disabled";
		status = "okay";
		spi@0{
			status = "okay";
			compatible = "spidev";
			reg = <0x0>;
			spi-max-frequency=<2000000>;
			nvidia,enable-hw-based-cs;
			nvidia,cs-setup-clk-count = <0x1e>;
			nvidia,cs-hold-clk-count = <0x1e>;
			nvidia,rx-clk-tap-delay = <0x1f>;
			nvidia,tx-clk-tap-delau = <0x0>;
		};
	};
nvidia@nvidia:~$ ls /dev/spidev
spidev0.0  spidev0.1  spidev1.0  spidev2.0  spidev2.1

Hi liuyuhangpro,

Are you using the devkit or custom board for Xavier NX?
What’s your Jetpack version in use?

Have you configured the pinmux for these SPI pins before use?

I tested on the devkit without configuring the pinmux. When I run jetson-io.py, a window pops up briefly, and I can’t see the configuration interface. I’m using JetPack 4.5.1.

Dec  5 14:55:39 nvidia nm-applet[7561]: gtk_widget_destroy: assertion 'GTK_IS_WIDGET (widget)' failed
Dec  5 14:55:39 nvidia nm-applet[7561]: gtk_widget_destroy: assertion 'GTK_IS_WIDGET (widget)' failed
Dec  5 14:55:39 nvidia nm-applet[7561]: Can't set a parent on widget which has a parent
Dec  5 14:55:40 nvidia nm-applet[7561]: gtk_widget_destroy: assertion 'GTK_IS_WIDGET (widget)' failed
Dec  5 14:55:40 nvidia nm-applet[7561]: gtk_widget_destroy: assertion 'GTK_IS_WIDGET (widget)' failed
Dec  5 14:55:40 nvidia nm-applet[7561]: Can't set a parent on widget which has a parent

Could you verify with the latest JP4.6.4(R32.7.4)?

Are you using Xavier NX with SD or eMMC module?

You should use Jetson-IO or pinmux spreadsheet to configure the pinmux for SPI pins before use.

I haven’t validated it with JP4.6.4, and I’m using the eMMC module. The reason is clear: I didn’t configure the SPI pins. The following log is the error log when I execute jetson-io.py. I’m unable to configure the SPI pins using jetson-io.

Dec  5 14:55:39 nvidia nm-applet[7561]: gtk_widget_destroy: assertion 'GTK_IS_WIDGET (widget)' failed
Dec  5 14:55:39 nvidia nm-applet[7561]: gtk_widget_destroy: assertion 'GTK_IS_WIDGET (widget)' failed
Dec  5 14:55:39 nvidia nm-applet[7561]: Can't set a parent on widget which has a parent
Dec  5 14:55:40 nvidia nm-applet[7561]: gtk_widget_destroy: assertion 'GTK_IS_WIDGET (widget)' failed
Dec  5 14:55:40 nvidia nm-applet[7561]: gtk_widget_destroy: assertion 'GTK_IS_WIDGET (widget)' failed
Dec  5 14:55:40 nvidia nm-applet[7561]: Can't set a parent on widget which has a parent

Could you try using pinmux spreadsheet to configure SPI pins?

How to use pinmux spreadsheet to configure SPI pins?

Please refer to NVIDIA Jetson Linux Developer Guide : Jetson Module Adaptation and Bring-Up - Pinmux Changes for details

After converting the dtsi file to a cfg file, how do I use the cfg file to make pinmux take effect?

What should I do when the following error message appears during conversion?

python pinmux-dts2cfg.py --pinmux addr_info.txt gpio_addr_info.txt por_val.txt --mandatory_pinmux_file mandatory_pinmux.txt tegra19x-jetson_xavier_nx_module-pinmux.dtsi tegra19x-jetson_xavier_nx_module-gpio-default.dtsi 1.0 > jakku.cfg
ERROR: pin dap3_sclk_pt1(0x00000440) field nvidia,enable-input(0x00000040) is not matching, val = 0x01 expected = 0x00
ERROR: pin dap3_fs_pt4(0x00000440) field nvidia,enable-input(0x00000040) is not matching, val = 0x01 expected = 0x00
ERROR: pin eqos_rd3_pf1(0x00022470) field nvidia,lpbk(0x00000020) is not matching, val = 0x01 expected = 0x00
ERROR: pin eqos_sma_mdio_pf4(0x00022440) field nvidia,pull(0x0000000c) is not matching, val = 0x00 expected = 0x02
ERROR: pin sdmmc4_cmd(0x00002440) field nvidia,pull(0x0000000c) is not matching, val = 0x00 expected = 0x02
ERROR: pin soc_gpio10_pg6(0x00000410) field nvidia,tristate(0x00000010) is not matching, val = 0x01 expected = 0x00
ERROR: pin gp_pwm2_px2(0x00000410) field nvidia,tristate(0x00000010) is not matching, val = 0x01 expected = 0x00
ERROR: pin uart2_tx_px4(0x00000400) field nvidia,pull(0x0000000c) is not matching, val = 0x00 expected = 0x02
ERROR: pin uart2_rx_px5(0x00000450) field nvidia,pull(0x0000000c) is not matching, val = 0x00 expected = 0x02
ERROR: pin spi1_sck_pz3(0x00000454) field nvidia,tristate(0x00000010) is not matching, val = 0x01 expected = 0x00
ERROR: pin spi1_sck_pz3(0x00000454) field nvidia,enable-input(0x00000040) is not matching, val = 0x01 expected = 0x00
ERROR: pin spi1_mosi_pz5(0x00000454) field nvidia,tristate(0x00000010) is not matching, val = 0x01 expected = 0x00
ERROR: pin spi1_mosi_pz5(0x00000454) field nvidia,enable-input(0x00000040) is not matching, val = 0x01 expected = 0x00
ERROR: pin spi1_cs0_pz6(0x00000458) field nvidia,tristate(0x00000010) is not matching, val = 0x01 expected = 0x00
ERROR: pin spi1_cs0_pz6(0x00000458) field nvidia,enable-input(0x00000040) is not matching, val = 0x01 expected = 0x00
ERROR: pin can0_dout_paa2(0x0000c400) field nvidia,pull(0x0000000c) is not matching, val = 0x00 expected = 0x02
ERROR: pin can0_din_paa3(0x0000c450) field nvidia,pull(0x0000000c) is not matching, val = 0x00 expected = 0x02
ERROR: pin uart3_tx_pcc5(0x00000400) field nvidia,pull(0x0000000c) is not matching, val = 0x00 expected = 0x02
ERROR: pin uart3_rx_pcc6(0x00000450) field nvidia,pull(0x0000000c) is not matching, val = 0x00 expected = 0x02
ERROR: pin soc_gpio22_pq2(0x00000459) field nvidia,pull(0x0000000c) is not matching, val = 0x02 expected = 0x00
ERROR: pin uart1_tx_pr2(0x00000400) field nvidia,pull(0x0000000c) is not matching, val = 0x00 expected = 0x02
ERROR: pin uart1_rx_pr3(0x00000454) field nvidia,pull(0x0000000c) is not matching, val = 0x01 expected = 0x02

Have you checked <Linux_for_Tegra>/kernel/pinmux/t19x/README?
Please put your .cfg file into <Linux_for_Tegra>/bootloader/t186ref/BCT/ and confirm the PINMUX_CONFIG in p3668.conf.common point to your new cfg.

Are your pinmux and gpio dtsi generated from pinmux spreadsheet?

I am using version JP4.5.1, but I couldn’t find information on how to use the .cfg file in the Readme file. Additionally, in the t186ref/BCT directory, I cannot locate the p3668.conf.common file.

Yes, generated using the file Jetson_Xavier_NX_Pinmux_Configuration_Template_v1.06.xlsm
README.txt (3.7 KB)

Please refer to the following thread to remove --mandatory_pinmux_file mandatory_pinmux.txt in your command.
About Changing pinmux for Xavier nx - #7 by JerryChang

Okay, then use sudo ./flash.sh -r jetson-xavier-nx-devkit-emmc mmcblk0p1 to reflash the system, correct?

sudo ./flash.sh jetson-xavier-nx-devkit-emmc mmcblk0p1

I have completed the flashing. How do I verify that the pins have been configured as SPI pins?

Please run the following command to check pinmux register

$ sudo busybox devmem 0x0243d040 //SPI1_SCK
$ sudo busybox devmem 0x0243d058 //SPI1_MOSI
$ sudo busybox devmem 0x0243d020 //SPI1_MISO
$ sudo busybox devmem 0x0243d010 //SPI1_CS0
$ sudo busybox devmem 0x0243d050 //SPI1_CS1
nvidia@nvidia:~$ sudo busybox devmem 0x0243d040
[sudo] password for nvidia:
0x00000454
nvidia@nvidia:~$ sudo busybox devmem 0x0243d058
0x00000454
nvidia@nvidia:~$ sudo busybox devmem 0x0243d020
0x00000454
nvidia@nvidia:~$ sudo busybox devmem 0x0243d010
0x00000458
nvidia@nvidia:~$ sudo busybox devmem 0x0243d050
0x00000059

What does this mean?

Is there an example of setting up SPI in the pinmux spreadsheet?

You could check Technical Reference Manual for details for the register.
It seems you’ve configure those pins for SPI successfully.

Please refer to the following instruction from Step 4 to verify SPI loopback test.
Jetson Nano SPI Bus Not Working - #10 by KevinFFF