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
Last revision Both sides next revision
products:sbc:common:applications:gpio:spi [2022/07/13 05:09]
nick
products:sbc:common:applications:gpio:spi [2023/11/07 05:07]
nick [Enable SPI]
Line 1: Line 1:
-====== SPI ====== 
  
-===== Introduction =====+===== SPI Reference table =====
  
-This document mainly introduces the usage of SPI on [[products:sbc:common:applications:gpio:40pin-header|40-Pin Header]].+|           ^  SPI    ^ Pin  ^ Pin name      GPIO name  ^  DT overlay node  ^  Device node     ^ 
 +^  VIM3/3L  |  SPI_B  |  15  | SPIB_SS      |  GPIOH_6    |  spi1              /dev/spidev1.1 
 +:::       | :::      16  | SPIB_SCLK    |  GPIOH_7    | :::               | :::              | 
 +| :::       | :::      35  | SPIB_MISO    |  GPIOH_5    | :::               | :::              | 
 +| :::       | :::      37  | SPIB_MOSI    |  GPIOH_4    | :::               | :::              | 
 +^  VIM4      SPI_A  |  25  |  SPI_A_SCLK  |  GPIOT_20    spi0              /dev/spidev1.0  | 
 +| :::       | :::      26  |  SPI_A_SS0    GPIOT_21   | :::               | :::              | 
 +| :::       | :::      36  |  SPI_A_MOSI  |  GPIOT_18   | :::               | :::              | 
 +| :::       | :::      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    | :::               | :::              |
  
-===== I2C Information =====+===== Enable SPI =====
  
-|            I2C    ^  PIN & GPIO(#number)                                        DT Overlays Node  ^  Bus Number  ^  Device Node  ^ +In order to use the SPI, you need to enable the SPI function via [[products:sbc:common:configurations:device-tree-overlay|Device Tree Overlay]].
-^  VIM1/  | I2C A    SCL(22) - GPIODV_25 (#474)\\ SDA (23) - GPIODV_24 (#473)  |  i2c0              |  0            /dev/i2c-0   | +
-^  :::      | I2C B    SCL(25) - GPIODV_27 (#476)\\ SDA(26) - GPIODV_26 (#475)    -                  1            /dev/i2c-1   | +
-^  VIM3/3L  | I2CM 3  |  SCL(22) - GPIOA_15 (#475)\\ SDA(23) - GPIOA_14 (#474)      i2c3              |  3            /dev/i2c-3   | +
-^  :::      | I2C AO  |  SCL(25) GPIOAO_2 (#498)\\ SDA(26) GPIOAO_3 (#499)      -                  4            /dev/i2c-4   | +
-^  VIM4     | I2CM F  |  SCL(22) - GPIOY_17 (#501)\\ SDA (23) - GPIOY_18 (#502)    |  i2cm_f            |  5            /dev/i2c-5   | +
-^  :::      | I2CM A  |  SCL(25) - GPIOT_20 (#466)\\ SDA(26) - GPIOT_21 (#467)      i2cm_a            |  0            /dev/i2c-0   |+
  
 +<tabbox VIM3/3L/Edge1>
  
-===== System Configuration =====+Edit ''/boot/env.txt'' to add the SPI node to ''overlays'' node if it doesn't exist. 
 + 
 +Take VIM3 as an example to enable ''SPI_B'', you need to add ''spi1'' node to ''overlays'' node if it doesn't exist.
  
-The default SPI is disabled. If you need to use SPI, you can enable it through the overlays function. 
 ```shell ```shell
-$ sudo vim /boot/env.txt+overlays=spi1
 ``` ```
-Modify the overlays part, remove ''pwm_f'' and ''uart3'', and open SPI. 
  
-```diff +<WRAP important 
-- overlays=uart3 pwm_f i2c3 os08a10 +As SPI pins are also used for other functione.g. UART_C, PWM_F, so that you also need to remove node ''uart3'' and ''pwm_f''.
-+ overlays=i2c3 os08a10 spi1 +
-``` +
- +
-Reboot to effect. +
- +
-<WRAP info +
-For Overlays documentationplease refer to [[products:sbc:vim4:configurations:device-tree-overlay|Device Tree Overlay]].+
 </WRAP> </WRAP>
  
-SPI configures a loopback test device by default.+ 
 +After reboot, you will see the spi device node.
  
 ```shell ```shell
Line 42: Line 42:
 ``` ```
  
-===== Demo Source Code =====+<tabbox VIM3 with 5.15 kernel>
  
-Get test code+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_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. 
 + 
 +<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_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. 
 + 
 +<tabbox VIM4> 
 + 
 +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> 
 + 
 +===== Disable SPI ===== 
 + 
 +If you want to use normal GPIO instead of SPI, you can remove the SPI node in [[products:sbc:common:configurations:device-tree-overlay|Device Tree Overlay]].  
 + 
 + 
 +===== Demo Source Code =====
  
 ```c spidev_test.c ```c spidev_test.c
Line 79: Line 149:
 } }
  
-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 528: Line 598:
 ``` ```
  
-Compile test code+Compile test code:
  
 ```shell ```shell
Line 534: Line 604:
 ``` ```
  
-===== Demonstrate =====+===== Test demonstration =====
  
- +Prepare input text file:
-Prepare a TST text file.+
  
 ```shell ```shell
Line 543: Line 612:
 ``` ```
  
-Run ''spidev_test''.+Connect PIN36(MOSI), PIN37(MISO) then run ''spidev_test'':
  
 ```shell ```shell
Line 552: Line 621:
 ``` ```
  
-Check output data.+Check output data
 ```shell ```shell
 $ cat ./spi_out.txt $ cat ./spi_out.txt
 Amazing Khadas! Amazing Khadas!
 ``` ```
Last modified: 2023/11/07 05:07 by nick