demo参考
- 登录准备环境所搭建Linux服务器。
- 执行如下命令,切换至root用户。
su - root
- 使用WinSCP工具,将下载软件包获取的源码包“Ascend310B-source.tar.gz”上传至root用户属组目录下,例如“/opt”。详细操作请参见使用WinSCP传输文件。
- 执行如下命令,进入源码包所在目录“/opt”。
cd /opt
- 执行如下命令,解压源码包“Ascend310B-source.tar.gz”。
tar -xzvf Ascend310B-source.tar.gz
- 执行如下命令,进入“Ascend310B-source”目录。
cd Ascend310B-source
- 执行如下命令,编译内核源码。
bash build.sh kernelSource
- 进入到spi内核源码目录“Ascend310B-source/driver/kernel/linux-4.19/tools/spi”。
cd /opt/Ascend310B-source/driver/kernel/linux-4.19/tools/spi
- 使用交叉编译工具编译。
make CROSS_COMPILE=aarch64-target-linux-gnu-
mkdir -p include/linux/spi 2>&1 || true ln -sf /opt/Ascend310B-sdk/Ascend310B-source/driver/kernel/linux-4.19/tools/spi/../../include/uapi/linux/spi/spidev.h include/linux/spi/spidev.h make -f /opt/Ascend310B-sdk/Ascend310B-source/driver/kernel/linux-4.19/tools/build/Makefile.build dir=. obj=spidev_test make[1]: Entering directory '/opt/Ascend310B-sdk/Ascend310B-source/driver/kernel/linux-4.19/tools/spi' CC spidev_test.o LD spidev_test-in.o make[1]: Leaving directory '/opt/Ascend310B-sdk/Ascend310B-source/driver/kernel/linux-4.19/tools/spi' LINK spidev_test make -f /opt/Ascend310B-sdk/Ascend310B-source/driver/kernel/linux-4.19/tools/build/Makefile.build dir=. obj=spidev_fdx make[1]: Entering directory '/opt/Ascend310B-sdk/Ascend310B-source/driver/kernel/linux-4.19/tools/spi' CC spidev_fdx.o LD spidev_fdx-in.o make[1]: Leaving directory '/opt/Ascend310B-sdk/Ascend310B-source/driver/kernel/linux-4.19/tools/spi' LINK spidev_fdx
- 编译成功会在当前目录下生成spidev_test,spidev_fdx二进制工具。可执行ll命令查看,回显信息如下所示。
total 300 drwxr-xr-x 3 root root 4096 Sep 16 14:54 ./ drwxr-xr-x 36 root root 4096 Sep 16 14:50 ../ -rw-r--r-- 1 root root 60 Sep 11 10:16 Build drwxr-xr-x 3 root root 4096 Sep 16 14:54 include/ -rw-r--r-- 1 root root 1745 Sep 11 10:16 Makefile -rwxr-xr-x 1 root root 22568 Sep 16 14:54 spidev_fdx* -rw-r--r-- 1 root root 2798 Sep 11 10:16 spidev_fdx.c -rw-r--r-- 1 root root 22336 Sep 16 14:54 spidev_fdx-in.o -rw-r--r-- 1 root root 88 Sep 16 14:54 .spidev_fdx-in.o.cmd -rw-r--r-- 1 root root 22328 Sep 16 14:54 spidev_fdx.o -rw-r--r-- 1 root root 6816 Sep 16 14:54 .spidev_fdx.o.cmd -rw-r--r-- 1 root root 6479 Sep 16 14:54 .spidev_fdx.o.d -rwxr-xr-x 1 root root 37120 Sep 16 14:54 spidev_test* -rw-r--r-- 1 root root 10529 Sep 11 10:16 spidev_test.c -rw-r--r-- 1 root root 54312 Sep 16 14:54 spidev_test-in.o -rw-r--r-- 1 root root 91 Sep 16 14:54 .spidev_test-in.o.cmd -rw-r--r-- 1 root root 54312 Sep 16 14:54 spidev_test.o -rw-r--r-- 1 root root 7975 Sep 16 14:54 .spidev_test.o.cmd -rw-r--r-- 1 root root 7633 Sep 16 14:54 .spidev_test.o.d
- 将Atlas 200I A2 加速模块SPI的MOSI管脚和MISO管脚环回测试。
- 登录Atlas 200I A2 加速模块的环境。
- 将spidev_test二进制工具上传到Atlas 200I A2 加速模块环境任意目录,执行如下命令增加可执行权限。
chmod +x spidev_test
spidev_test支持的参数可执行./spidev_test --help命令查看,如下所示。
-D --device device to use (default /dev/spidev1.1) -s --speed max speed (Hz) -d --delay delay (usec) -b --bpw bits per word -i --input input data from a file (e.g. "test.bin") -o --output output data to a file (e.g. "results.bin") -l --loop loopback -H --cpha clock phase -O --cpol clock polarity -L --lsb least significant bit first -C --cs-high chip select active high -3 --3wire SI/SO signals shared -v --verbose Verbose (show tx buffer) -p Send data (e.g. "1234\xde\xad") -N --no-cs no chip select -R --ready slave pulls low to pause -2 --dual dual transfer -4 --quad quad transfer -8 --octal octal transfer -S --size transfer size -I --iter iterations
- 执行如下命令,发送数据测试。
./spidev_test -D /dev/spidev0.0 -p "\x04\x05\x20\x01" -v
回显信息如下,表示RX和TX数据和所发数据一致,收发功能正常。
spi mode: 0x0 bits per word: 8 max speed: 500000 Hz (500 kHz) TX | 04 05 20 01 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ |.. .| RX | 04 05 20 01 __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ |.. .
父主题: SPI