好的,我终于找到了一种方法来运行spi-loopback-test 模块。
这里的诀窍是使用anyspi Device-Tree overlay,以避免依赖spidev module。
我的灵感来自this commit。
- 首先,必须重新编译内核以包含测试功能“spi-loopback-test”。
我关注了this guide,从 Ubuntu 虚拟机进行交叉编译。
- 编译前通过“menuconfig”启用SPI环回模块:
CONFIG_SPI_DEBUG=y和CONFIG_SPI_LOOPBACK_TEST=m
- 将内核映像及其设备树加载到目标系统 (RPi4)。
- 在 RPi4 上运行以下命令:
$ sudo dmesg -n 8
$ lsmod | grep spi
$ sudo dtoverlay anyspi spi0-1 dev="linux,spi-loopback-test" speed=125000000
$ lsmod | grep spi
spi_loopback_test 28672 0
spidev 20480 0
spi_bcm2835 24576 0
$ dmesg | grep spi > spi-loopback-test.log
$ $ head spi-loopback-test.log -n 15
[ 48.170758] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /soc/spi@7e204000/spidev@1/status
[ 48.170785] OF: overlay: WARNING: memory leak will occur if overlay removed, property: /soc/spi@7e204000/status
[ 48.182921] spi-bcm2835 fe204000.spi: registered master spi0
[ 48.183056] spi spi0.1: setup: forcing CS_HIGH (use_gpio_descriptors)
[ 48.183075] spi spi0.1: setup mode 0, cs_high, 8 bits/w, 125000000 Hz max --> 0
[ 48.183187] spi-bcm2835 fe204000.spi: registered child spi0.1
[ 48.183217] spi spi0.0: setup: forcing CS_HIGH (use_gpio_descriptors)
[ 48.183232] spi spi0.0: setup mode 0, cs_high, 8 bits/w, 125000000 Hz max --> 0
[ 48.183327] spi-bcm2835 fe204000.spi: registered child spi0.0
[ 48.269732] spi-loopback-test spi0.1: Executing spi-loopback-tests
[ 48.269946] spi-loopback-test spi0.1: Running test tx/rx-transfer - start of page
[ 48.270204] spi-loopback-test spi0.1: with iteration values: len = 0, tx_off = 0, rx_off = 1
[ 48.270431] spi-loopback-test spi0.1: with iteration values: len = 0, tx_off = 0, rx_off = 2
[ 48.270657] spi-loopback-test spi0.1: with iteration values: len = 0, tx_off = 0, rx_off = 3
[ 48.270883] spi-loopback-test spi0.1: with iteration values: len = 0, tx_off = 1, rx_off = 0
$ tail spi-loopback-test.log
[ 51.878516] spi-loopback-test spi0.1: with iteration values: len = 1024, tx_off = 0, rx_off = 0
[ 51.881159] spi-loopback-test spi0.1: with iteration values: len = 1031, tx_off = 0, rx_off = 0
[ 51.883826] spi-loopback-test spi0.1: with iteration values: len = 4093, tx_off = 0, rx_off = 0
[ 51.886892] spi-loopback-test spi0.1: with iteration values: len = 4096, tx_off = 0, rx_off = 0
[ 51.889950] spi-loopback-test spi0.1: with iteration values: len = 4099, tx_off = 0, rx_off = 0
[ 51.893862] spi-loopback-test spi0.1: with iteration values: len = 65536, tx_off = 0, rx_off = 0
[ 51.905280] spi-loopback-test spi0.1: with iteration values: len = 65537, tx_off = 0, rx_off = 0
[ 51.916708] spi-loopback-test spi0.1: with iteration values: len = 131071, tx_off = 0, rx_off = 0
[ 51.937417] spi-loopback-test spi0.1: with iteration values: len = 131072, tx_off = 0, rx_off = 0
[ 52.057851] spi-loopback-test spi0.1: Finished spi-loopback-tests with return: 0
所以看起来 SPI 测试成功了,正如预期的那样。现在我知道如何将内核模块连接到硬件了。
我希望这对其他人也有用。
但是,我想知道是否有更简单的解决方案来加载和运行这个内核模块??
是否可以不依赖anyspi DT覆盖,只设置spi-loopback-mode模块的compatible参数?