背景
- 由于T113-S3的两个SPI接口都已经被占用,所以考虑使用GPIO模拟SPI方式
- 使用spidev,会在/dev下产生spidevB.C节点,通过此节点可以操作挂载在SPI总线上的设备,用户层可以通过该节点访问内核空间
配置SPIDEV
1.修改设备树
SDK下device目录中根据不同启动方式进入对应配置文件目录打开board.dts
有关GPIO模拟SPI配置,在kernel目录:Documentation/devicetree/bindings/spi/spi-gpio.yaml中有相关描述
spi_gpio {
compatible = "spi-gpio";
ranges;
pinctrl-names = "default";
status = "okay";
#address-cells = <0x1>;
#size-cells = <0x0>;
sck-gpios = <&pio PB 2 GPIO_ACTIVE_LOW>;
miso-gpios = <&pio PB 4 GPIO_ACTIVE_LOW>;
mosi-gpios = <&pio PB 5 GPIO_ACTIVE_LOW>;
cs-gpios = <&pio PB 3 GPIO_ACTIVE_LOW>;
num-chipselects = <1>;
spidev@0x00 {
compatible = "spidev";
spi-max-frequency = <1000000>;
reg = <0>;
};
};
2.使能内核模块
在SDK根目录下,执行./build.sh menuconfig (官方SDK按此执行,其它请根据实际情况执行)
路径如下:
> Device Drivers > SPI support
退出保存,编译kernel 打包固件,烧录测试…
3.查看结果
不过在内核启动时,会打印以下问题:
如何解决呢:
在kernel/linux-5.4/drivers/spi/spidev.c文件,找到spidev_dt_ids,添加你想要的
然后修改设备树中刚刚添加的节点
重新编打包译烧录测试。