项目上须要用到蓝莓派CM4,驱动XR2121VV14141414芯片,蓝莓派版本是2021-05-07-raspios-buster-armhf-full,XR2121VV14141414是USB转4路并口芯片。

当将XR2121VV14141414联接蓝莓派的USB口后,会手动辨识成ttyACM0、ttyACM1、ttyACM2、ttyACM3,此时打开任意并口linux usb 转串口驱动,并进行读写操作linux usb 转串口驱动,可以成功,但当发送到几十次后才会卡主,再也没法读写。并且经过检测发觉实际数据并没有发出来,TX,RX上均没有电平变化。出现这个问题的缘由是猕猴桃派外置的驱动是cdc-acm,实际未能驱动XR2121VV14141414芯片,须要更新驱动。

从官方网站上找到驱动linux vi ,按照自己板子的内核版本来选择驱动版本,可以用uname-a来查看内核版本号,例如我自己的板子

usb转串口驱动linux_linux usb 转串口驱动_linux串口驱动程序

可以看见我的是5.10版本,须要驱动支持3.6以上版本即可

也就是这一条,下载然后放在板子上,直接解压,并步入板子,用make指令编译,即可得到驱动包xr_usb_serial_common.ko。此时还不能直接加载驱动,由于系统本身还有cdc-acm驱动,须要卸载掉以后才行,因而须要先执行卸载,再加载

sudormmodcdc-acm

sudoinsmod./xr_usb_serial_common.ko

usb转串口驱动linux_linux串口驱动程序_linux usb 转串口驱动

此时,查看dev下设备,即可见到ttyXRUSB0、ttyXRUSB1、ttyXRUSB2、ttyXRUSB3这4个设备,这时就可以进行正常收发操作。

事情到旁边又发生了变化,由于覆盆子派更新了系统,在21年11月以后,发布的2021-10-30-raspios-bullseye-armhf-full版本,内核弄成了5.15,此时再重复以上操作,还会出错,首先是步入驱动文件进行make操作时,会提示找不到build文件

pi@raspberrypi:/mnt/Work/driver_64/xr_usb_serial_common_lnx-3.6-and-newer-pak $ make
make -C /lib/modules/5.15.32-v8+/build M=/mnt/Work/driver_64/xr_usb_serial_common_lnx-3.6-and-newer-pak
make[1]: *** /lib/modules/5.15.32-v8+/build: No such file or directory.  Stop.
make: *** [Makefile:9: all] Error 2

linux usb 转串口驱动_linux串口驱动程序_usb转串口驱动linux

此时须要加载kernel的build文件,使用以下

sudoaptinstallraspberrypi-kernel-headers

pi@raspberrypi:/mnt/Work/driver_64/xr_usb_serial_common_lnx-3.6-and-newer-pak $ sudo apt install raspberrypi-kernel-headers
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  raspberrypi-kernel-headers
0 upgraded, 1 newly installed, 0 to remove and 14 not upgraded.
Need to get 9675 kB of archives.
After this operation, 60.6 MB of additional disk space will be used.
Get:1 //archive.raspberrypi.org/debian bullseye/main arm64 raspberrypi-kernel-headers arm64 1:1.20220331-1 [9675 kB]
Fetched 9675 kB in 6s (1602 kB/s)                                                        
apt-listchanges: Can't set locale; make sure $LC_* and $LANG are correct!
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = "en_US.UTF-8",
	LC_ALL = "en_US.UTF-8",
	LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
Selecting previously unselected package raspberrypi-kernel-headers.
(Reading database ... 99103 files and directories currently installed.)
Preparing to unpack .../raspberrypi-kernel-headers_1%3a1.20220331-1_arm64.deb ...
Unpacking raspberrypi-kernel-headers (1:1.20220331-1) ...
Setting up raspberrypi-kernel-headers (1:1.20220331-1) ...
pi@raspberrypi:/mnt/Work/driver_64/xr_usb_serial_common_lnx-3.6-and-newer-pak $ 

usb转串口驱动linux_linux串口驱动程序_linux usb 转串口驱动

执行完成后,/lib/modules/5.15.32-v8+/路径下即可见到build文件夹,此时重新make编译驱动,会发觉编译报错

pi@raspberrypi:/mnt/Work/driver_64/xr_usb_serial_common_lnx-3.6-and-newer-pak $ sudo make
make -C /lib/modules/5.15.32-v8+/build M=/mnt/Work/driver_64/xr_usb_serial_common_lnx-3.6-and-newer-pak
make[1]: Entering directory '/usr/src/linux-headers-5.15.32-v8+'
  CC [M]  /mnt/Work/driver_64/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.o
/mnt/Work/driver_64/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.c:2019:17: error: initialization of 'unsigned int (*)(struct tty_struct *)' from incompatible pointer type 'int (*)(struct tty_struct *)' [-Werror=incompatible-pointer-types]
 2019 |  .write_room =  xr_usb_serial_tty_write_room,
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/mnt/Work/driver_64/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.c:2019:17: note: (near initialization for 'xr_usb_serial_ops.write_room')
/mnt/Work/driver_64/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.c:2026:21: error: initialization of 'unsigned int (*)(struct tty_struct *)' from incompatible pointer type 'int (*)(struct tty_struct *)' [-Werror=incompatible-pointer-types]
 2026 |  .chars_in_buffer = xr_usb_serial_tty_chars_in_buffer,
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/mnt/Work/driver_64/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.c:2026:21: note: (near initialization for 'xr_usb_serial_ops.chars_in_buffer')
/mnt/Work/driver_64/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.c: In function 'xr_usb_serial_init':
/mnt/Work/driver_64/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.c:2040:29: error: implicit declaration of function 'alloc_tty_driver' [-Werror=implicit-function-declaration]
 2040 |  xr_usb_serial_tty_driver = alloc_tty_driver(XR_USB_SERIAL_TTY_MINORS);
      |                             ^~~~~~~~~~~~~~~~
/mnt/Work/driver_64/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.c:2040:27: warning: assignment to 'struct tty_driver *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
 2040 |  xr_usb_serial_tty_driver = alloc_tty_driver(XR_USB_SERIAL_TTY_MINORS);
      |                           ^
/mnt/Work/driver_64/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.c:2057:3: error: implicit declaration of function 'put_tty_driver' [-Werror=implicit-function-declaration]
 2057 |   put_tty_driver(xr_usb_serial_tty_driver);
      |   ^~~~~~~~~~~~~~
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:277: /mnt/Work/driver_64/xr_usb_serial_common_lnx-3.6-and-newer-pak/xr_usb_serial_common.o] Error 1
make[1]: *** [Makefile:1868: /mnt/Work/driver_64/xr_usb_serial_common_lnx-3.6-and-newer-pak] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.15.32-v8+'
make: *** [Makefile:9: all] Error 2
pi@raspberrypi:/mnt/Work/driver_64/xr_usb_serial_common_lnx-3.6-and-newer-pak $ 

这个报错是由于系统内核变化了,5.15版本之后不支持put_tty_driver和alloc_tty_driver,早已更换成tty_driver_kref_put和tty_alloc_driver,所以要步入代码文件进行更改,另外xr_usb_serial_tty_write_room函数和xr_usb_serial_tty_chars_in_buffer函数也须要更改,把定义函数时的int改为unsignedint,更改完成后(xr2121vv14141414驱动,支持3.6-5.15版本)即可正常编译linux开发培训,得到ko文件,前面的操作就跟上面一样了。

本文原创地址://gulass.cn/smpcqdxxpwtj.html编辑:刘遄,审核员:暂无