Khadas Docs

Amazing Khadas, always amazes you!

User Tools

Site Tools


products:sbc:edge-2l: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:edge-2l:applications:gpio:spi [2026/01/13 22:19]
gray fix warning tip pwm number
products:sbc:edge-2l:applications:gpio:spi [2026/05/11 02:08] (current)
nick ↷ Page moved from local:users:gray:products:sbc:edge-2l:applications:gpio:spi to products:sbc:edge-2l:applications:gpio:spi
Line 3: Line 3:
 ====== Edge-2L SPI ====== ====== Edge-2L SPI ======
  
-SPI interface can be founded on [[products:sbc:edge-2l:applications:gpio:40pin-header|Edge-2L 16-pin Header]].+The Serial Peripheral Interface (SPI) is available on the [[products:sbc:edge2:applications:gpio:40pin-header|Edge-2L 16-Pin Header]].
  
-/* WHY this information was there ????  
-<WRAP important > 
-For Edge-2L, in order to use the UART , you need to attach the IO extension board. 
-</WRAP> 
-*/ 
 ===== Reference table ===== ===== Reference table =====
  
Line 20: Line 15:
 ===== Enable SPI ===== ===== Enable SPI =====
  
-In order to use the SPI, you need to enable the SPI function via [[products:sbc:common:configurations:device-tree-overlay|Device Tree Overlay]]+To use the hardware SPI, you must first enable it by applying a [[products:sbc:common:configurations:device-tree-overlay|Device Tree Overlay]].
  
-Edit ''/boot/dtb/rockchip/rk3576-khadas-edge-2l.dtb.overlay.env'' to add the SPI node to ''overlays'' node if it doesn't exist.+Edit the file ''/boot/dtb/rockchip/rk3576-khadas-edge-2l.dtb.overlay.env'' and add the overlay ''edge-2l-io-spi'' to the ''fdt_overlays'' parameter if it is not already present:
  
 To enable ''SPI1'', you need to add ''edge-2l-io-spi'' node to ''overlays'' node if it doesn't exist. To enable ''SPI1'', you need to add ''edge-2l-io-spi'' node to ''overlays'' node if it doesn't exist.
Line 29: Line 24:
 fdt_overlays=edge-2l-io-spi fdt_overlays=edge-2l-io-spi
 ``` ```
-<WRAP important > + 
-As SPI pins are also can used for other function, e.g. ''PWM1'', so that you also need to remove node ''pwm1''.+<WRAP important >  
 +The SPI pins are multiplexed and can also be used for other functions (e.g., ''PWM1''). If you have previously enabled ''PWM1'', you must remove the ''pwm1'' overlay from the ''fdt_overlays'' parameter to avoid conflicts
 </WRAP> </WRAP>
  
  
-After rebootyou will see the spi device node.+Reboot the system for the change to take effect. After rebootingverify that the SPI device node exists:
 ```shell ```shell
 $ ls /dev/spidev1.0 $ ls /dev/spidev1.0
Line 42: Line 38:
 ===== Disable SPI ===== ===== 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]] +If you wish to use the SPI pins as standard GPIOs, remove the ''edge-2l-io-spi'' entry from the ''fdt_overlays'' parameter in the Device Tree Overlay configuration file and reboot.
- +
- +
-===== Demo Source Code =====+
  
 +===== Demo source code =====
 +Below is a standard Linux spidev test program for SPI communication:
 ```c spidev_test.c ```c spidev_test.c
 // SPDX-License-Identifier: GPL-2.0-only // SPDX-License-Identifier: GPL-2.0-only
Line 529: Line 524:
 ``` ```
  
-Compile test code:+Compile the test program:
  
 ```shell ```shell
Line 537: Line 532:
 ===== Test demonstration ===== ===== Test demonstration =====
  
-Prepare input text file:+1. Prepare a test input file:
  
 ```shell ```shell
Line 543: Line 538:
 ``` ```
  
-Connect PIN11PIN12 then run ''spidev_test'':+2. Connect the SPI pins in loopback: 
 +Short PIN11 (MOSI) to PIN12 (MISO) to create a loopback for testing. 
 + 
 +3. Run the SPI test program:
  
 ```shell ```shell
 $ ./spidev_test -i spi_in.txt -o ./spi_out.txt $ ./spidev_test -i spi_in.txt -o ./spi_out.txt
 +```
 +Example output:
 +```shell
 spi mode: 0x0 spi mode: 0x0
 bits per word: 8 bits per word: 8
Line 552: Line 553:
 ``` ```
  
-Check output data:+4. Verify the received data:
  
 ```shell ```shell
 $ cat ./spi_out.txt $ cat ./spi_out.txt
 +```
 +Output should be:
 +```
 Amazing Khadas! Amazing Khadas!
 ``` ```
Last modified: 2026/01/13 22:19 by gray