This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
products:sbc:common:applications:gpio:spi [2022/07/04 06:09] frank add SPI |
products:sbc:common:applications:gpio:spi [2025/02/17 21:40] (current) nick [Enable SPI] |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== SPI ====== | ||
| - | ===== Introduction | + | ===== SPI Reference table ===== |
| - | This document mainly introduces | + | | |
| + | ^ VIM3/ | ||
| + | | ::: | ::: | ||
| + | | ::: | ::: | ||
| + | | ::: | ::: | ||
| + | ^ VIM4 | ||
| + | | ::: | ::: | ||
| + | | ::: | ::: | ||
| + | | ::: | ::: | ||
| + | ^ VIM1S | SPI_A | 29 | SPI_A_MOSI | ||
| + | | ::: | ::: | ||
| + | | ::: | ::: | ||
| + | | ::: | ::: | ||
| - | ===== Hardware Connection | + | ===== Enable SPI ===== |
| - | Connect | + | In order to use the SPI, you need to enable the SPI function via [[products: |
| - | ===== System Configuration ===== | + | <tabbox VIM3/ |
| - | The default SPI is disabled. If you need to use SPI, you can enable it through the overlays function. | + | Edit '' |
| - | ```sh | + | |
| - | $ sudo vim / | + | |
| - | ``` | + | |
| - | Modify | + | |
| - | ```sh | + | Take VIM3 as an example to enable '' |
| - | $ overlays=uart3 pwm_f i2c3 os08a10 --> | + | |
| + | ```shell | ||
| + | overlays=spi1 | ||
| ``` | ``` | ||
| - | Reboot to effect. | + | < |
| - | + | As SPI pins are also used for other function, e.g. UART_C, PWM_F, so that you also need to remove node '' | |
| - | < | + | |
| - | For Overlays documentation, please refer to [[/ | + | |
| </ | </ | ||
| - | SPI configures a loopback test device by default. | ||
| - | ```sh spidev_test.c | + | After reboot, you will see the spi device node. |
| + | |||
| + | ```shell | ||
| $ ls / | $ ls / | ||
| / | / | ||
| ``` | ``` | ||
| - | ===== Demo Source Code ===== | + | <tabbox VIM3 with 5.15 kernel> |
| - | Get test code | + | Edit ''/ |
| + | |||
| + | |||
| + | e.g. Enable '' | ||
| + | |||
| + | ```shell | ||
| + | fdt_overlays=spi1 | ||
| + | ``` | ||
| + | |||
| + | After reboot, you will see the SPI device node. | ||
| + | |||
| + | ```shell | ||
| + | $ ls / | ||
| + | / | ||
| + | ``` | ||
| + | |||
| + | <tabbox VIM3L with 5.15 kernel> | ||
| + | |||
| + | Edit ''/ | ||
| + | |||
| + | |||
| + | e.g. Enable '' | ||
| + | |||
| + | ```shell | ||
| + | fdt_overlays=spi1 | ||
| + | |||
| + | ``` | ||
| + | |||
| + | After reboot, you will see the SPI device node. | ||
| + | |||
| + | ```shell | ||
| + | $ ls / | ||
| + | / | ||
| + | ``` | ||
| + | |||
| + | <tabbox VIM4> | ||
| + | |||
| + | Edit ''/ | ||
| + | |||
| + | |||
| + | e.g. Enable '' | ||
| + | |||
| + | ```shell | ||
| + | fdt_overlays=spi0 | ||
| + | |||
| + | ``` | ||
| + | |||
| + | After reboot, you will see the SPI device node. | ||
| + | |||
| + | ```shell | ||
| + | $ ls / | ||
| + | / | ||
| + | ``` | ||
| + | <tabbox VIM1S> | ||
| + | |||
| + | Edit ''/ | ||
| + | |||
| + | |||
| + | e.g. Enable '' | ||
| + | |||
| + | ```shell | ||
| + | fdt_overlays=spi0 | ||
| + | |||
| + | ``` | ||
| + | |||
| + | After reboot, you will see the SPI device node. | ||
| + | |||
| + | ```shell | ||
| + | $ ls / | ||
| + | / | ||
| + | ``` | ||
| + | |||
| + | </ | ||
| + | |||
| + | ===== Disable SPI ===== | ||
| + | |||
| + | If you want to use normal GPIO instead of SPI, you can remove the SPI node in [[products: | ||
| + | |||
| + | |||
| + | ===== Demo Source Code ===== | ||
| - | ```c | + | ```c spidev_test.c |
| // SPDX-License-Identifier: | // SPDX-License-Identifier: | ||
| /* | /* | ||
| Line 71: | Line 158: | ||
| } | } | ||
| - | static const char *device = "/ | + | static const char *device = "/ |
| static uint32_t mode; | static uint32_t mode; | ||
| static uint8_t bits = 8; | static uint8_t bits = 8; | ||
| Line 520: | Line 607: | ||
| ``` | ``` | ||
| - | Compile test code | + | Compile test code: |
| - | ```sh | + | ```shell |
| $ gcc -o spidev_test spidev_test.c | $ gcc -o spidev_test spidev_test.c | ||
| ``` | ``` | ||
| - | ===== Demonstrate | + | ===== Test demonstration |
| + | Prepare input text file: | ||
| - | Prepare a TST text file. | + | ```shell |
| - | + | ||
| - | ```sh | + | |
| $ echo " | $ echo " | ||
| ``` | ``` | ||
| - | Run '' | + | Connect PIN36(MOSI), |
| - | ```sh | + | |
| - | $ ./ | + | |
| + | ```shell | ||
| + | $ ./ | ||
| spi mode: 0x0 | spi mode: 0x0 | ||
| bits per word: 8 | bits per word: 8 | ||
| Line 544: | Line 632: | ||
| ``` | ``` | ||
| - | Check output data. | + | <WRAP important > |
| - | ```sh | + | Please choose the correct spi device node. |
| + | </ | ||
| + | |||
| + | |||
| + | Check output data: | ||
| + | |||
| + | ```shell | ||
| $ cat ./ | $ cat ./ | ||
| Amazing Khadas! | Amazing Khadas! | ||
| ``` | ``` | ||