How do I enable SPI for nanopc T4?

Pin# Assignment Pin# Assignment
1 VCC3V3_SYS 2 VCC5V0_SYS
3 I2C2_SDA(3V) 4 VCC5V0_SYS
5 I2C2_SCL(3V) 6 GND
7 GPIO1_A0(3V) 8 GPIO4_C1/I2C3_SCL(3V)
9 GND 10 GPIO4_C0/I2C3_SDA(3V)
11 GPIO1_A1(3V) 12 GPIO1_C2(3V)
13 GPIO1_A3(3V) 14 GND
15 GPIO1_A4(3V) 16 GPIO1_C6(3V)
17 VCC3V3_SYS 18 GPIO1_C7(3V)
19 SPI1_TXD/UART4_TX(3V) 20 GND
21 SPI1_RXD/UART4_RX(3V) 22 GPIO1_D0(3V)
23 SPI1_CLK(3V) 24 SPI1_CSn0(3V)
25 GND 26 GPIO4_C5/SPDIF_TX(3V)
27 I2C2_SDA(1.8V) 28 I2C2_SCL(1.8V)
29 I2S1_LRCK_RX(1.8V) 30 GND
31 I2S1_LRCK_TX(1.8V) 32 I2S_CLK(1.8V)
33 I2S1_SCLK(1.8V) 34 GND
35 I2S1_SDI0(1.8V) 36 I2S1_SDO0(1.8V)
37 GPIO3_D4(1.8V) 38 GPIO3_D5(1.8V)
39 GND 40 GPIO3_D6(1.8V)

Its wiki describes that this device has SPI.
Basically I found some discussion.

dtc -@ -I dts -O dtb -o rk3399-nanopc-t4-spi.dtbo rk3399-nanopc-t4-spi.dts
This command can compile dtbo.

But it seems to make the device unbootable.

U-Boot 2020.07-1 (Jan 20 2023 - 06:36:19 +0000) Manjaro Linux ARM

SoC: Rockchip rk3399
Reset cause: POR
Model: FriendlyElec NanoPC-T4
DRAM:  3.9 GiB
PMIC:  RK808 
MMC:   mmc@fe310000: 2, mmc@fe320000: 1, sdhci@fe330000: 0
Loading Environment from MMC... *** Warning - bad CRC, using default environment

In:    serial
Out:   serial
Err:   serial
Model: FriendlyElec NanoPC-T4
Net:   
Error: ethernet@fe300000 address not set.
No ethernet found.

Hit any key to stop autoboot:  0 
switch to partitions #0, OK
mmc0(part 0) is current device
** Invalid partition 1 **
Card did not respond to voltage select!

Device 0: Vendor: 0x1cc1 Rev: ZTA10613 Prod: ZTA22T0KA222130ECE  
            Type: Hard Disk
            Capacity: 1953514.3 MB = 1907.7 GB (4000797360 x 512)
... is now current device
Scanning nvme 0:1...
Found /extlinux/extlinux.conf
Retrieving file: /extlinux/extlinux.conf
277 bytes read in 2 ms (134.8 KiB/s)
Ignoring unknown command: FDTOVERLAYS
Ignoring unknown command: APPEND
1:      Manjaro ARM
Retrieving file: /Image
24824320 bytes read in 46 ms (514.7 MiB/s)
Retrieving file: /dtbs/rockchip/rk3399-nanopc-t4.dtb
79600 bytes read in 2 ms (38 MiB/s)
## Flattened Device Tree blob at 01f00000
   Booting using the fdt blob at 0x1f00000
   Loading Device Tree to 00000000f1efd000, end 00000000f1f136ef ... OK

@spikerguy Do you have any idea?

Why does adding spi makes it unbootable?

Share compile log. Add this to boot command in. Extlinux.conf

earlycon loglevel=7

Remove quite from the boot argument also.

DT may have a problem with the DTS provided by the PO, but I am not particularly clear about the syntax of DTS, can you use this DTS test to test DTB coverage on NanoPC-T4.

And it seems that the DTB in the mainline kernel has disabled UART4, and there should be no need for additional UART4 disable in the DTB.

LABEL Manjaro ARM
KERNEL /Image
FDT /dtbs/rockchip/rk3399-nanopc-t4.dtb
FDTOVERLAYS /overlays/rk3399-nanopc-t4-spi.dtbo
APPEND rootflags=subvol=@ initrd=/initramfs-linux.img console=ttyS2,1500000 root=PARTLABEL=RootFS rw rootwait audit=0 splash plymouth.ignore-serial-consoles earlycon loglevel=7
U-Boot TPL 2020.07-1 (Jan 20 2023 - 06:36:19)
Channel 0: LPDDR3, 933MHz
BW=32 Col=10 Bk=8 CS0 Row=15 CS1 Row=15 CS=2 Die BW=16 Size=2048MB
Channel 1: LPDDR3, 933MHz
BW=32 Col=10 Bk=8 CS0 Row=15 CS1 Row=15 CS=2 Die BW=16 Size=2048MB
256B stride
256B stride
Trying to boot from BOOTROM
Returning to boot ROM...

U-Boot SPL 2020.07-1 (Jan 20 2023 - 06:36:19 +0000)
Trying to boot from MMC2


U-Boot 2020.07-1 (Jan 20 2023 - 06:36:19 +0000) Manjaro Linux ARM

SoC: Rockchip rk3399
Reset cause: POR
Model: FriendlyElec NanoPC-T4
DRAM:  3.9 GiB
PMIC:  RK808 
MMC:   mmc@fe310000: 2, mmc@fe320000: 1, sdhci@fe330000: 0
Loading Environment from MMC... *** Warning - bad CRC, using default environment

In:    serial
Out:   serial
Err:   serial
Model: FriendlyElec NanoPC-T4
Net:   
Error: ethernet@fe300000 address not set.
No ethernet found.

Hit any key to stop autoboot:  0 
switch to partitions #0, OK
mmc0(part 0) is current device
** Invalid partition 1 **
Card did not respond to voltage select!

Device 0: Vendor: 0x1cc1 Rev: ZTA10613 Prod: ZTA22T0KA222130ECE  
            Type: Hard Disk
            Capacity: 1953514.3 MB = 1907.7 GB (4000797360 x 512)
... is now current device
Scanning nvme 0:1...
Found /extlinux/extlinux.conf
Retrieving file: /extlinux/extlinux.conf
297 bytes read in 2 ms (144.5 KiB/s)
Ignoring unknown command: FDTOVERLAYS
Ignoring unknown command: APPEND
1:      Manjaro ARM
Retrieving file: /Image
24824320 bytes read in 46 ms (514.7 MiB/s)
Retrieving file: /dtbs/rockchip/rk3399-nanopc-t4.dtb
79600 bytes read in 3 ms (25.3 MiB/s)
## Flattened Device Tree blob at 01f00000
   Booting using the fdt blob at 0x1f00000
   Loading Device Tree to 00000000f1efd000, end 00000000f1f136ef ... OK

Starting kernel ...

But I added the FDTOVERLAYS option in Uboot’s compilation configuration.
Why is this so?

Both are ignored. I don’t really know. Will have to look into it myself to understand better.

Can you test the patch provided by the armbian community by the way? I don’t seem to be able to get USB-C to work in OTG mode using these patches.

This is a very old patch which was working fine for us until it stopped applying or compiling and now that it compiles but creates other issue with the devices.

So we had to drop it completely.

Sound like OTG available on Linux-LTS?

I’ll give it a try.

Even if you use the bsp kernel, you can only use the host mode, not the persistent mode.
It looks terrible.

Do you have any ideas?

Is there any progress in the exploration of enabling SPI in dts?

1 Like

Didn’t really get time to look into it.

This means uboot does not have overlays enabled.

So first need to compile uboot with fdtoverlays enabled then it should allow.

Or just add the spi node to dts and compile it as dtb and use it directly.

SPi node is missing in upstream kernel.

I think you have to patch uboot dts for spi as well as kernel dts. Currently I have too many things in my hand to look into so I doubt I will get to test it anytime soon. Sorry about that.

sudo lsgpio     
GPIO chip: gpiochip4, "gpio4", 32 GPIO lines
        line  0: unnamed unused [input]
        line  1: unnamed unused [input]
        line  2: unnamed unused [input]
        line  3: unnamed unused [input]
        line  4: unnamed unused [input]
        line  5: unnamed unused [input]
        line  6: unnamed unused [input]
        line  7: unnamed unused [input]
        line  8: unnamed unused [input]
        line  9: unnamed unused [input]
        line 10: unnamed unused [input]
        line 11: unnamed unused [input]
        line 12: unnamed unused [input]
        line 13: unnamed unused [input]
        line 14: unnamed unused [input]
        line 15: unnamed unused [input]
        line 16: unnamed unused [input]
        line 17: unnamed unused [input]
        line 18: unnamed unused [input]
        line 19: unnamed unused [input]
        line 20: unnamed unused [input]
        line 21: unnamed unused [input]
        line 22: unnamed unused [input]
        line 23: unnamed unused [input]
        line 24: unnamed unused [input]
        line 25: unnamed unused [input]
        line 26: unnamed "vbus-typec" [used, output]
        line 27: unnamed unused [output]
        line 28: unnamed unused [input]
        line 29: unnamed unused [input]
        line 30: unnamed unused [input]
        line 31: unnamed unused [input]
GPIO chip: gpiochip3, "gpio3", 32 GPIO lines
        line  0: unnamed unused [input]
        line  1: unnamed unused [input]
        line  2: unnamed unused [input]
        line  3: unnamed unused [input]
        line  4: unnamed unused [input]
        line  5: unnamed unused [input]
        line  6: unnamed unused [input]
        line  7: unnamed unused [input]
        line  8: unnamed unused [input]
        line  9: unnamed unused [input]
        line 10: unnamed "interrupt" [used, input]
        line 11: unnamed unused [input]
        line 12: unnamed unused [input]
        line 13: unnamed unused [input]
        line 14: unnamed unused [input]
        line 15: unnamed "PHY reset" [used, output, active-low]
        line 16: unnamed unused [input]
        line 17: unnamed unused [input]
        line 18: unnamed unused [input]
        line 19: unnamed unused [input]
        line 20: unnamed unused [input]
        line 21: unnamed unused [input]
        line 22: unnamed unused [input]
        line 23: unnamed unused [input]
        line 24: unnamed unused [input]
        line 25: unnamed unused [input]
        line 26: unnamed unused [input]
        line 27: unnamed unused [input]
        line 28: unnamed unused [input]
        line 29: unnamed unused [input]
        line 30: unnamed unused [input]
        line 31: unnamed unused [input]
GPIO chip: gpiochip2, "gpio2", 32 GPIO lines
        line  0: unnamed unused [input]
        line  1: unnamed unused [input]
        line  2: unnamed unused [input]
        line  3: unnamed unused [input]
        line  4: unnamed "ep" [used, output]
        line  5: unnamed unused [input]
        line  6: unnamed unused [input]
        line  7: unnamed unused [input]
        line  8: unnamed unused [input]
        line  9: unnamed unused [input]
        line 10: unnamed unused [input]
        line 11: unnamed unused [input]
        line 12: unnamed unused [input]
        line 13: unnamed unused [input]
        line 14: unnamed unused [input]
        line 15: unnamed unused [input]
        line 16: unnamed unused [input]
        line 17: unnamed unused [input]
        line 18: unnamed unused [input]
        line 19: unnamed unused [input]
        line 20: unnamed unused [input]
        line 21: unnamed unused [input]
        line 22: unnamed unused [input]
        line 23: unnamed unused [input]
        line 24: unnamed unused [input]
        line 25: unnamed unused [input]
        line 26: unnamed "device-wakeup" [used, output]
        line 27: unnamed unused [input]
        line 28: unnamed unused [input]
        line 29: unnamed unused [input]
        line 30: unnamed unused [input]
        line 31: unnamed unused [input]
GPIO chip: gpiochip1, "gpio1", 32 GPIO lines
        line  0: unnamed unused [input]
        line  1: unnamed unused [input]
        line  2: unnamed "interrupt" [used, input]
        line  3: unnamed unused [input]
        line  4: unnamed unused [input]
        line  5: unnamed unused [input]
        line  6: unnamed unused [input]
        line  7: unnamed unused [input]
        line  8: unnamed unused [input]
        line  9: unnamed unused [input]
        line 10: unnamed unused [input]
        line 11: unnamed unused [input]
        line 12: unnamed unused [input]
        line 13: unnamed unused [input]
        line 14: unnamed unused [input]
        line 15: unnamed unused [input]
        line 16: unnamed unused [input]
        line 17: unnamed unused [input]
        line 18: unnamed unused [input]
        line 19: unnamed unused [input]
        line 20: unnamed unused [input]
        line 21: unnamed "interrupt" [used, input]
        line 22: unnamed unused [input]
        line 23: unnamed unused [input]
        line 24: unnamed unused [input]
        line 25: unnamed unused [input]
        line 26: unnamed unused [input]
        line 27: unnamed unused [input]
        line 28: unnamed unused [input]
        line 29: unnamed unused [input]
        line 30: unnamed unused [input]
        line 31: unnamed unused [input]
GPIO chip: gpiochip0, "gpio0", 32 GPIO lines
        line  0: unnamed unused [input]
        line  1: unnamed "vcc3v0-sd" [used, output]
        line  2: unnamed unused [input]
        line  3: unnamed unused [input]
        line  4: unnamed "host-wakeup" [used, input]
        line  5: unnamed "GPIO Key Power" [used, input, active-low]
        line  6: unnamed "ir-receiver" [used, input, active-low]
        line  7: unnamed "cd" [used, input, active-low]
        line  8: unnamed unused [input]
        line  9: unnamed "shutdown" [used, output]
        line 10: unnamed "reset" [used, output, active-low]
        line 11: unnamed unused [input]
        line 12: unnamed unused [input]
        line 13: unnamed "status_led" [used, output]
        line 14: unnamed unused [input]
        line 15: unnamed unused [input]
        line 16: unnamed unused [input]
        line 17: unnamed unused [input]
        line 18: unnamed unused [input]
        line 19: unnamed unused [input]
        line 20: unnamed unused [input]
        line 21: unnamed unused [input]
        line 22: unnamed unused [input]
        line 23: unnamed unused [input]
        line 24: unnamed unused [input]
        line 25: unnamed unused [input]
        line 26: unnamed unused [input]
        line 27: unnamed unused [input]
        line 28: unnamed unused [input]
        line 29: unnamed unused [input]
        line 30: unnamed unused [input]
        line 31: unnamed unused [input]

It seems that GPIO has not been initialized.