Khadas Docs

Amazing Khadas, always amazes you!

User Tools

Site Tools


products:sbc:common:applications:gpio:spi

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
products:sbc:common:applications:gpio:spi [2022/12/20 04:13]
nick [Table]
products:sbc:common:applications:gpio:spi [2026/09/15 03:26] (current)
nick
Line 1: Line 1:
-====== SPI ====== 
-===== Introduction ===== 
  
-SPI interface usage examples on [[products:sbc:common:applications:gpio:40pin-header|40-Pin Header]].+===== SPI Reference table =====
  
-===== Reference table ===== +|           ^  SPI    ^ Pin  ^ Pin name     ^  GPIO name  ^  DT overlay node  ^  Device node     ^ 
- +^  VIM3/3L  |  SPI_B  |  15  | SPIB_SS      |  GPIOH_6    |  spi1             |  /dev/spidev2.1  | 
-|           ^  SPI    ^ Pin  ^ Pin name   ^  GPIO name  ^  GPIO num  ^  DT overlay node  ^  Device node     ^ +| :::       | :::     |  16  | SPIB_SCLK    |  GPIOH_7    | :::               | :::              | 
-^  VIM3/3L  |  SPI_B  |  15  | SPIB_SS    |  GPIOH_6    |  433       |  spi1             |  /dev/spidev1.1  | +| :::       | :::     |  35  | SPIB_MISO    |  GPIOH_5    | :::               | :::              | 
-| :::       | :::     |  16  | SPIB_SCLK  |  GPIOH_7    |  434       | :::               | :::              | +| :::       | :::     |  37  | SPIB_MOSI    |  GPIOH_4    | :::               | :::              | 
-| :::       | :::     |  35  | SPIB_MISO  |  GPIOH_5    |  432       | :::               | :::              | +^  VIM4     |  SPI_A  |  25  |  SPI_A_SCLK  |  GPIOT_20   |  spi0             |  /dev/spidev1.0  | 
-| :::       | :::     |  37  | SPIB_MOSI  |  GPIOH_4    |  431       | :::               | :::              | +| :::       | :::     |  26  |  SPI_A_SS0   |  GPIOT_21   | :::               | :::              | 
-^  VIM4     |         |      |            |             |            |                   |                  | +| :::       | :::     |  36  |  SPI_A_MOSI  |  GPIOT_18   | :::               | :::              | 
-^  VIM1S    |  SPI_B  |      |            |             |            |                   |                  | +| :::       | :::     |  37  |  SPI_A_MISO  |  GPIOT_19   | :::               | :::              | 
-| :::       | :::     |      |            |             |            |                   |                  | +^  VIM1S    |  SPI_A  |  29  |  SPI_A_MOSI  |  GPIOZ_1    | :::               | :::              | 
-| :::       | :::     |      |            |             |            |                   |                  | +| :::       | :::     |  31  |  SPI_A_CLK   |  GPIOZ_2    | :::               | :::              | 
-| :::       | :::     |      |            |             |            |                   |                  |+| :::       | :::     |  32  |  SPI_A_MISO  |  GPIOZ_0    | :::               | :::              | 
 +| :::       | :::     |  33  |  SPI_A_SS0   |  GPIOZ_3    | :::               | :::              | 
 +^  VIM-5    |  SPI_C  |  26  |  SPI_C_MOSI  |  GPIOM_0    |  spi1             | /dev/spidev1.0   | 
 +| :::       | :::     |  36  |  SPI_C_SCLK  |  GPIOM_2    | :::               | :::              | 
 +| :::       | :::     |  25  |  SPI_C_MISO  |  GPIOM_1    | :::               | :::              | 
 +| :::       | :::     |  37  |  SPI_C_SS0   |  GPIOM_3    | :::               | :::              |
  
 ===== Enable SPI ===== ===== Enable SPI =====
Line 41: Line 44:
 $ ls /dev/spidev1.1 $ ls /dev/spidev1.1
 /dev/spidev1.1 /dev/spidev1.1
 +```
 +
 +<tabbox VIM3 with 5.15 kernel>
 +
 +Edit ''/boot/dtb/amlogic/kvim3.dtb.overlay.env'' to add spi node to ''fdt_overlays'' node if it doesn't exist.
 +
 +
 +e.g. Enable ''SPI_B'', you need to add ''spi1'' to node ''fdt_overlays'' if it doesn't exist.
 +
 +```shell
 +fdt_overlays=spi1
 +```
 +
 +After reboot, you will see the SPI device node.
 +
 +```shell
 +$ ls /dev/spidev2.1 
 +/dev/spidev2.1
 +```
 +
 +<tabbox VIM3L with 5.15 kernel>
 +
 +Edit ''/boot/dtb/amlogic/kvim3l.dtb.overlay.env'' to add spi node to ''fdt_overlays'' node if it doesn't exist.
 +
 +
 +e.g. Enable ''SPI_B'', you need to add ''spi1'' to node ''fdt_overlays'' if it doesn't exist.
 +
 +```shell
 +fdt_overlays=spi1
 +
 +```
 +
 +After reboot, you will see the SPI device node.
 +
 +```shell
 +$ ls /dev/spidev2.1 
 +/dev/spidev2.1
 ``` ```
  
 <tabbox VIM4> <tabbox VIM4>
  
-TODO.+Edit ''/boot/dtb/amlogic/kvim4.dtb.overlay.env'' to add spi node to ''fdt_overlays'' node if it doesn't exist.
  
 +
 +e.g. Enable ''SPI_A'', you need to add ''spi0'' to node ''fdt_overlays'' if it doesn't exist.
 +
 +```shell
 +fdt_overlays=spi0
 +
 +```
 +
 +After reboot, you will see the SPI device node.
 +
 +```shell
 +$ ls /dev/spidev1.0 
 +/dev/spidev1.0
 +```
 +<tabbox VIM1S>
 +
 +Edit ''/boot/dtb/amlogic/kvim1s.dtb.overlay.env'' to add spi node to ''fdt_overlays'' node if it doesn't exist.
 +
 +
 +e.g. Enable ''SPI_A'', you need to add ''spi0'' to node ''fdt_overlays'' if it doesn't exist.
 +
 +```shell
 +fdt_overlays=spi0
 +
 +```
 +
 +After reboot, you will see the SPI device node.
 +
 +```shell
 +$ ls /dev/spidev1.0 
 +/dev/spidev1.0
 +```
 +
 +<tabbox VIM-5>
 +
 +Edit ''/boot/dtb/amlogic/kvim-5.dtb.overlay.env'' to add spi node to ''fdt_overlays'' node if it doesn't exist.
 +
 +
 +e.g. Enable ''SPI_C'', you need to add ''spi1'' to node ''fdt_overlays'' if it doesn't exist.
 +
 +```shell
 +fdt_overlays=spi1
 +
 +```
 +
 +After reboot, you will see the SPI device node.
 +
 +```shell
 +$ ls /dev/spidev1.0 
 +/dev/spidev1.0
 +```
  
 </tabbox> </tabbox>
Line 90: Line 181:
 } }
  
-static const char *device = "/dev/spidev1.1";+static const char *device = "/dev/spidev1.0";
 static uint32_t mode; static uint32_t mode;
 static uint8_t bits = 8; static uint8_t bits = 8;
Line 553: Line 644:
 ``` ```
  
-Run ''spidev_test'':+Connect PIN36(MOSI), PIN37(MISO) then run ''spidev_test'': 
 + 
  
 ```shell ```shell
-$ ./spidev_test -i spi_in.txt -o ./spi_out.txt+$ ./spidev_test -D /dev/spidev1.1 -i spi_in.txt -o ./spi_out.txt
 spi mode: 0x0 spi mode: 0x0
 bits per word: 8 bits per word: 8
 max speed: 500000 Hz (500 KHz) max speed: 500000 Hz (500 KHz)
 ``` ```
 +
 +<WRAP important >
 +Please choose the correct spi device node.
 +</WRAP>
 +
  
 Check output data: Check output data:
Last modified: 2022/12/20 04:13 by nick