使用overlays无法激活主线linux的SPI设备(Can not use overlays to setup spi in mainline linux 5.17)

使用VIM3做机器人相关,需要使用spi总线连接两个从机传感器接收数据
Control the robot using the VIM3 and connect two slave sensors using the spi bus to receive data

按照文档激活spi设备
flow steps to setup spi1

https://docs.khadas.com/linux/zh-cn/vim3/SPIUsage.html
编辑env.txt.内容如下:
edit env.txt like:

# Device Tree Overlays
#   uart3           -- Enable UART3 (uart_C, GPIO Header PIN15 & PIN16)
#   pwm_f           -- Enable PWM_F (GPIO Header PIN35)
#   i2c3            -- Enable i2c3 (GPIO Header PIN22 & PIN23)
#   spi1            -- Enable SPI1 (GPIO Header PIN15 & PIN16 & PIN35 & PIN37), pwm_f need to be removed
#   i2s             -- Enable I2S (GPIO Header PIN29 & PIN30 & PIN31 & PIN32 & PIN33)
#   os08a10         -- Enable OS08A10 Camera
#   onewire         -- Enable onewire bus (GPIO Header PIN15)
#   disable-ts050   -- Disable TS050 LCD
#   m2x-eth         -- Enable M2X 100M ethernet. Note: 1G ethernet will be disabled.
#   otg-device      -- Enable USB OTG Device
#   watchdog        -- Enable watchdog
#   can             -- Enable mcp2515 (GPIO Header PIN15 && PIN16 && PIN22 && PIN35 && PIN37), pwm_f/i2c3/uart3 need to be removed
#   mpu6050-i2c     -- Enable mpu6050 (GPIO Header PIN22 & PIN23 & PIN37), pwm_f need to be removed
#   ext_board       -- Enable for Khadas EXT Board
#   spdifin         -- Enable SPDIFIN (GPIO Header PIN35), pwm_f need to be removed
overlays=spi1 i2c3 os08a10 watchdog
custom_ethmac=c8:63:14:71:00:24
rootfstype=ext4

overlays里面也添加了spi1,去除了pwm_f和uart3,但是保存重启后找不到spi设备
In overlays,I remove pwm_f ,uart3 and add spi1,but i can’t find spi dev after reboot.

dmesg | grep spi也没有反应
dmesg | grep spi also no response

使用的是fenix编译的实时固件,主线linux,server版ubuntu 20.04

system info(ubuntu server 20.04):
Linux Khadas 5.17.0-rt17 #1.0.11 SMP Mon May 2 23:40:32 PDT 2022 aarch64 aarch64 aarch64 GNU/Linux

由于需要使用实时内核,而4.9版本打实时补丁有问题,只能使用主线版本
only mainline linux can patch RT,So I can’t use kernel 4.9.

在论坛查查了相关问题,又尝试使用dts来开启spi
overlays does’t work ,try to edit DTS

在/fenix/build/linux-mainline-5.17/arch/arm64/boot/dts/amlogic里修改了 meson-khadas-vim3.dtsi
文件

同时也把里面的PWM_EF设置为disabled
set PWM_EF to disabled

image

然后编译出来镜像重新烧录到SD卡里面启动,结果还是没有spi设备,是不是我修改的dts文件不对?还是有其他问题?
make images via fenix,burn into SD card,and power on. Still can’t find spi dev. Is I edit wrong DTS file or just another problem?

Pin 35 is multiplexed so you can only use it for one function at a time.

fred@vim3a:~$ sudo ls /sys/class/spi*
/sys/class/spidev:

/sys/class/spi_master:

In addition to PWM-EF, are there other features that use Pin35 that prevent SPI from appearing?

I suspect that I modified dts incorrectly, but I really don’t know which file to change, and the steps I modified earlier were based on this post,It seems 4.9 kernel instead of mainline.

after running your cmd,it comes out like that
image

that shows that spi0 is active.

Can spi0 be used by users? I want to use the spi in the 40-Pin GPIO, and it seems to be spi1

Try using spi0 instead of spi1, it might have been a error. Pretty sure that spi0 is active since it did create a file. We don’t use spi so I don’t have any sample code to try it, sorry.

How are you opening the spi file?

{
	
	int fd;
	
			
			fd = open(TTYdevice, O_RDWR | O_NOCTTY| O_NDELAY ); 
				if (fd ==-1 ) {
				perror(TTYdevice); 
			}

This may or may not be correct for spi it does work for tty

Thanks for your suggestion, I haven’t opened this spi0 file yet

1 Like