NANO EMMC SPI signal seen on the scope is abnormal

Please review my steps.

  1. install sdkmanager_1.7.2-9007_amd64.deb
  2. download sdk by sdkmanager
q@q:~/nvidia/nvidia_sdk/JetPack_4.6_Linux_JETSON_NANO_TARGETS/Linux_for_Tegra$ ls
apply_binaries.sh            jetson-nano-devkit-emmc.conf  kernel                   nv_tools                         p3449-0000+p3448-0000-qspi.conf     p3542.conf             source_sync.sh
bootloader                   jetson-nano-emmc.conf         l4t_generate_soc_bup.sh  p2371.conf                       p3449-0000+p3448-0000-qspi-sd.conf  README_Autoflash.txt   tools
build_l4t_bup.sh             jetson-nano-qspi.conf         nvautoflash.sh           p2597-0000+p2180-1000-24x7.conf  p3449-0000+p3448-0002.conf          README_Massflash.txt   TX1_boot-firmware-redundancy.txt
flash.sh                     jetson-nano-qspi-sd.conf      nvmassflashgen.sh        p2597-0000+p2180-1000.conf       p3450.conf                          README_RAPID_BOOT.txt
jetson-nano-2gb-devkit.conf  jetson-tx1.conf               nvsdkmanager_flash.sh    p3448-0000.conf.common           p3542-0000+p3448-0003-qspi.conf     rootfs
jetson-nano-devkit.conf      jetson-tx1-devkit.conf        nv_tegra                 p3448-0000-max-spi.conf          p3542-0000+p3448-0003-qspi-sd.conf  source
  1. flash nano by sdkmanager

n@n:~$ head -n 1 /etc/nv_tegra_release
# R32 (release), REVISION: 6.1, GCID: 27863751, BOARD: t210ref, EABI: aarch64, DATE: Mon Jul 26 19:20:30 UTC 2021
  1. open the Web page
    Jetson Linux R32.6.1 Release Page | NVIDIA Developer
    download L4T Driver Package (BSP) Sources(L4T 32.6.1)
    download GCC 7.3.1 for 64 bit BSP and Kernel(L4T 32.6.1)
q@q:~/nv$ tar -xjf public_sources.tbz2
q@q:~/nv$ cd Linux_for_Tegra/source/public
q@q:~/nv/Linux_for_Tegra/source/public$ tar -xjf kernel_src.tbz2
q@q:~/nv/Linux_for_Tegra/source/public$ cd ~/nv
q@q:~/nv$ tar -xf gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz

5.modify .dts files and .c files

q@q:~/nv$ diff -bu ./Linux_for_Tegra/source/public/hardware/nvidia/platform/t210/porg/kernel-dts/porg-platforms/tegra210-porg-pinmux-p3448-0002-b00.dtsi.bak ./Linux_for_Tegra/source/public/hardware/nvidia/platform/t210/porg/kernel-dts/porg-platforms/tegra210-porg-pinmux-p3448-0002-b00.dtsi
--- ./Linux_for_Tegra/source/public/hardware/nvidia/platform/t210/porg/kernel-dts/porg-platforms/tegra210-porg-pinmux-p3448-0002-b00.dtsi.bak   2022-02-11 13:40:57.100522614 +0800
+++ ./Linux_for_Tegra/source/public/hardware/nvidia/platform/t210/porg/kernel-dts/porg-platforms/tegra210-porg-pinmux-p3448-0002-b00.dtsi       2022-02-11 13:42:55.000000000 +0800
@@ -721,7 +721,7 @@

                        spi1_mosi_pc0 {
                                nvidia,pins = "spi1_mosi_pc0";
-                               nvidia,function = "rsvd1";
+                               nvidia,function = "spi1";
                                nvidia,pull = <TEGRA_PIN_PULL_DOWN>;
                                nvidia,tristate = <TEGRA_PIN_DISABLE>;
                                nvidia,enable-input = <TEGRA_PIN_ENABLE>;
@@ -729,7 +729,7 @@

                        spi1_miso_pc1 {
                                nvidia,pins = "spi1_miso_pc1";
-                               nvidia,function = "rsvd1";
+                               nvidia,function = "spi1";
                                nvidia,pull = <TEGRA_PIN_PULL_DOWN>;
                                nvidia,tristate = <TEGRA_PIN_DISABLE>;
                                nvidia,enable-input = <TEGRA_PIN_ENABLE>;
@@ -737,7 +737,7 @@

                        spi1_sck_pc2 {
                                nvidia,pins = "spi1_sck_pc2";
-                               nvidia,function = "rsvd1";
+                               nvidia,function = "spi1";
                                nvidia,pull = <TEGRA_PIN_PULL_DOWN>;
                                nvidia,tristate = <TEGRA_PIN_DISABLE>;
                                nvidia,enable-input = <TEGRA_PIN_ENABLE>;
@@ -745,7 +745,7 @@

                        spi1_cs0_pc3 {
                                nvidia,pins = "spi1_cs0_pc3";
-                               nvidia,function = "rsvd1";
+                               nvidia,function = "spi1";
                                nvidia,pull = <TEGRA_PIN_PULL_UP>;
                                nvidia,tristate = <TEGRA_PIN_DISABLE>;
                                nvidia,enable-input = <TEGRA_PIN_ENABLE>;
@@ -753,7 +753,7 @@

                        spi1_cs1_pc4 {
                                nvidia,pins = "spi1_cs1_pc4";
-                               nvidia,function = "rsvd1";
+                               nvidia,function = "spi1";
                                nvidia,pull = <TEGRA_PIN_PULL_UP>;
                                nvidia,tristate = <TEGRA_PIN_DISABLE>;
                                nvidia,enable-input = <TEGRA_PIN_ENABLE>;

q@q:~/nv$ diff -bu ./Linux_for_Tegra/source/public/hardware/nvidia/platform/t210/porg/kernel-dts/porg-platforms/tegra210-porg-gpio-p3448-0002-b00.dtsi.bak ./Linux_for_Tegra/source/public/hardware/nvidia/platform/t210/porg/kernel-dts/porg-platforms/tegra210-porg-gpio-p3448-0002-b00.dtsi
--- ./Linux_for_Tegra/source/public/hardware/nvidia/platform/t210/porg/kernel-dts/porg-platforms/tegra210-porg-gpio-p3448-0002-b00.dtsi.bak     2022-02-11 13:30:26.133110410 +0800
+++ ./Linux_for_Tegra/source/public/hardware/nvidia/platform/t210/porg/kernel-dts/porg-platforms/tegra210-porg-gpio-p3448-0002-b00.dtsi 2022-02-11 13:31:36.624164309 +0800
@@ -25,6 +25,9 @@
                gpio-init-0 = <&gpio_default>;

                gpio_default: default {
+                       gpio-hog;
+                       function;
+                       gpios = <TEGRA_GPIO(C, 0) 0 TEGRA_GPIO(C, 1) 0 TEGRA_GPIO(C, 2) 0 TEGRA_GPIO(C, 3) 0 TEGRA_GPIO(C,4) 0>;
                        gpio-input = <
                                TEGRA_GPIO(BB, 0)
                                TEGRA_GPIO(B, 4)
@@ -50,11 +53,11 @@
                                TEGRA_GPIO(J, 7)
                                TEGRA_GPIO(G, 2)
                                TEGRA_GPIO(G, 3)
-                               TEGRA_GPIO(C, 0)
-                               TEGRA_GPIO(C, 1)
-                               TEGRA_GPIO(C, 2)
-                               TEGRA_GPIO(C, 3)
-                               TEGRA_GPIO(C, 4)
+                               //TEGRA_GPIO(C, 0)
+                               //TEGRA_GPIO(C, 1)
+                               //TEGRA_GPIO(C, 2)
+                               //TEGRA_GPIO(C, 3)
+                               //TEGRA_GPIO(C, 4)
                                TEGRA_GPIO(H, 2)
                                TEGRA_GPIO(H, 5)
                                TEGRA_GPIO(H, 6)
q@q:~/nv$ diff -bu ./Linux_for_Tegra/source/public/hardware/nvidia/platform/t210/porg/kernel-dts/tegra210-porg-p3448-common.dtsi.bak ./Linux_for_Tegra/source/public/hardware/nvidia/platform/t210/porg/kernel-dts/tegra210-porg-p3448-common.dtsi
--- ./Linux_for_Tegra/source/public/hardware/nvidia/platform/t210/porg/kernel-dts/tegra210-porg-p3448-common.dtsi.bak   2022-02-11 13:47:30.628907051 +0800
+++ ./Linux_for_Tegra/source/public/hardware/nvidia/platform/t210/porg/kernel-dts/tegra210-porg-p3448-common.dtsi       2022-02-11 13:51:36.000000000 +0800
@@ -196,7 +196,8 @@
        hdr40_spi1: spi@7000d400 { /* SPI 1 to 40 pin header */
                status = "okay";
                spi@0 {
-                       compatible = "tegra-spidev";
+            status = "okay";
+                       compatible = "spidev";
                        reg = <0x0>;
                        spi-max-frequency = <33000000>;
                        controller-data {
@@ -205,7 +206,8 @@
                        };
                };
                spi@1 {
-                       compatible = "tegra-spidev";
+            status = "okay";
+                       compatible = "spidev";
                        reg = <0x1>;
                        spi-max-frequency = <33000000>;
                        controller-data {

q@q:~/nv$ diff -bu ./Linux_for_Tegra/source/public/kernel/kernel-4.9/drivers/gpio/gpio-tegra.c.bak ./Linux_for_Tegra/source/public/kernel/kernel-4.9/drivers/gpio/gpio-tegra.c
--- ./Linux_for_Tegra/source/public/kernel/kernel-4.9/drivers/gpio/gpio-tegra.c.bak     2022-02-11 13:12:22.426222612 +0800
+++ ./Linux_for_Tegra/source/public/kernel/kernel-4.9/drivers/gpio/gpio-tegra.c 2022-02-11 13:14:54.000000000 +0800
@@ -217,6 +217,11 @@
        tegra_gpio_mask_write(tgi, GPIO_MSK_CNF(tgi, gpio), gpio, 1);
 }

+static void tegra_gpio_disable(struct tegra_gpio_info *tgi, int gpio)
+{
+       tegra_gpio_mask_write(tgi, GPIO_MSK_CNF(tgi, gpio), gpio, 0);
+}
+
 static int tegra_gpio_request(struct gpio_chip *chip, unsigned offset)
 {
        tegra_gpio_save_gpio_state(offset);
@@ -225,8 +230,11 @@

 static void tegra_gpio_free(struct gpio_chip *chip, unsigned offset)
 {
+    struct tegra_gpio_info *tgi = gpiochip_get_data(chip);
+
        pinctrl_free_gpio(chip->base + offset);
        tegra_gpio_restore_gpio_state(offset);
+    tegra_gpio_disable(tgi, offset);
 }

 static void tegra_gpio_set(struct gpio_chip *chip, unsigned offset, int value)

q@q:~/nv$ diff -bu ./Linux_for_Tegra/source/public/kernel/kernel-4.9/drivers/spi/spi-tegra114.c.bak  ./Linux_for_Tegra/source/public/kernel/kernel-4.9/drivers/spi/spi-tegra114.c
--- ./Linux_for_Tegra/source/public/kernel/kernel-4.9/drivers/spi/spi-tegra114.c.bak    2022-02-11 14:35:47.688454417 +0800
+++ ./Linux_for_Tegra/source/public/kernel/kernel-4.9/drivers/spi/spi-tegra114.c        2022-02-11 16:47:44.000000000 +0800
@@ -908,12 +908,12 @@
        if (!cdata || tspi->prod_list)
                return;
        set_count = min(cdata->cs_setup_clk_count, 16);
-       if (set_count)
-               set_count--;
+       // if (set_count)
+               // set_count--;

        hold_count = min(cdata->cs_hold_clk_count, 16);
-       if (hold_count)
-               hold_count--;
+       // if (hold_count)
+               // hold_count--;

        spi_cs_setup = SPI_SETUP_HOLD(set_count, hold_count);
        spi_cs_timing = SPI_CS_SETUP_HOLD(tspi->spi_cs_timing,
@@ -1490,10 +1490,10 @@
                msg->actual_length += xfer->len;

 complete_xfer:
-               if (prefer_last_used_cs)
+               // if (prefer_last_used_cs)
                        cmd1 = tspi->command1_reg;
-               else
-                       cmd1 = tspi->def_command1_reg;
+               // else
+                       // cmd1 = tspi->def_command1_reg;
                if (ret < 0 || skip) {
                        if (cstate && cstate->cs_gpio_valid)
                                gpio_set_value(spi->cs_gpio, gval);

6.edit bulid script

q@q:~/nv/Linux_for_Tegra/source/public/kernel/kernel-4.9$ cat build.sh
#!/bin/sh
echo "build:" `date`
TEGRA_KERNEL_OUT=/home/q/nv/build
export CROSS_COMPILE=/home/q/nv/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
export LOCALVERSION=-tegra
make ARCH=arm64 O=$TEGRA_KERNEL_OUT tegra_defconfig
make ARCH=arm64 O=$TEGRA_KERNEL_OUT -j4
echo "build finish" `date`

7.ready to build

q@q:~/nv$ mkdir build
q@q:~/nv$ sudo apt install build-essential bc

8.build

q@q:~/nv/Linux_for_Tegra/source/public/kernel/kernel-4.9$ ./build.sh

9.replace Image and other dtb files

cp /home/q/nv/build/arch/arm64/boot/Image /home/q/nvidia/nvidia_sdk/JetPack_4.6_Linux_JETSON_NANO_TARGETS/Linux_for_Tegra/kernel/Image
cp /home/q/nv/build/arch/arm64/boot/dts/*.* /home/q/nvidia/nvidia_sdk/JetPack_4.6_Linux_JETSON_NANO_TARGETS/Linux_for_Tegra/kernel/dtb/

10.reflash nano by flash.sh

q@q:~/nvidia/nvidia_sdk/JetPack_4.6_Linux_JETSON_NANO_TARGETS/Linux_for_Tegra$ sudo ./flash.sh jetson-nano-emmc mmcblk0p1

11.edit main.c(test code )
main.c (10.4 KB)
12.build and loopback test

n@n:~$ gcc -o test.out main.c
n@n:~$ sudo ./test.out
spi mode: 0x0 /dev/spidev0.0
bits per word: 8
max speed: 2000000 Hz (2000 KHz)
delay: 0
cs_change:0 pad:0 mode:0
send:10
TX | 60 00 00 20 00 00 00 00 00 00 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  | `.........
RX | 60 00 00 20 00 00 00 00 00 00 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __  | `.........

13.loopback test OK
14.However view the signal on oscilloscope,the signal is bad.Because of the SPI CLOCK signal is unnecessary in loopback test ,the loopback test can run successfully

Could you try connect SPI0 and SPI1 to do the device loopback test to check the scope too.

Thanks.

Have reference to below relative topic.

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