一、串口权限不够
报错信息:
serial.serialutil.SerialException: [Errno 13] could not open port /dev/ttyACM0: [Errno 13] Permission denied: '/dev/ttyACM0'
1. 临时解决方案(快速验证):
# 临时赋予设备读写权限(重启后失效)
sudo chmod 666 /dev/ttyACM0
2. 永久解决方案(推荐):
# 将当前用户加入 dialout 用户组
sudo usermod -aG dialout $USER
# 配置 udev 规则(需要重启生效)
echo 'KERNEL=="ttyACM*", MODE="0666"' | sudo tee /etc/udev/rules.d/50-ttyACM.rules
# 强制刷新 udev 规则
sudo udevadm control --reload-rules
sudo udevadm trigger
二、Ubuntu 22.04中ch34x串口无法使用的问题
1、问题描述:
使用lsusb
命令可以看到有Bus 001 Device 005: ID 1a86:7523 QinHeng Electronics CH340 serial converter
是能识别出ch34x设备
2、解决方案:
step1:WCH官网下载最新的驱动CH341SER_LINUX.ZIP
step2:解压驱动
unzip CH341SER_LINUX_ZIP
得到三个文件ch34x.c
Makefile
readme.txt
step3:编译安装驱动
eadme.txt里面介绍到驱动的加载方式,但注意到第7行写着支持的内核版本从2.6.25 to 3.13.x
隐约感觉问题不妙,敲入make
命令后,果然出现了错误(这年头官网的驱动也不靠谱哇)
make -C /lib/modules/5.15.0-58-generic/build M=/home/$USER/Documents/CH341SER_LINUX
make[1]: Entering directory '/usr/src/linux-headers-5.15.0-58-generic'
CC [M] /home/$USER/Documents/CH341SER_LINUX/ch34x.o
/home/$USER/Documents/CH341SER_LINUX/ch34x.c: In function ‘ch34x_close’:
/home/$USER/Documents/CH341SER_LINUX/ch34x.c:591:9: error: unknown type name ‘wait_queue_t’; did you mean ‘wait_event’?
591 | wait_queue_t wait;
| ^~~~~~~~~~~~
| wait_event
/home/$USER/Documents/CH341SER_LINUX/ch34x.c:591:22: warning: unused variable ‘wait’ [-Wunused-variable]
591 | wait_queue_t wait;
| ^~~~
/home/$USER/Documents/CH341SER_LINUX/ch34x.c:590:14: warning: unused variable ‘timeout’ [-Wunused-variable]
590 | long timeout;
| ^~~~~~~
/home/$USER/Documents/CH341SER_LINUX/ch34x.c:589:13: warning: unused variable ‘bps’ [-Wunused-variable]
589 | int bps;
| ^~~
/home/$USER/Documents/CH341SER_LINUX/ch34x.c: At top level:
/home/$USER/Documents/CH341SER_LINUX/ch34x.c:1297:27: error: initialization of ‘unsigned int (*)(struct tty_struct *)’ from incompatible pointer type ‘int (*)(struct tty_struct *)’ [-Werror=incompatible-pointer-types]
1297 | .write_room = ch34x_write_room,
| ^~~~~~~~~~~~~~~~
/home/$USER/Documents/CH341SER_LINUX/ch34x.c:1297:27: note: (near initialization for ‘ch34x_device.write_room’)
/home/$USER/Documents/CH341SER_LINUX/ch34x.c:1298:28: error: initialization of ‘unsigned int (*)(struct tty_struct *)’ from incompatible pointer type ‘int (*)(struct tty_struct *)’ [-Werror=incompatible-pointer-types]
1298 | .chars_in_buffer = ch34x_chars_in_buffer,
| ^~~~~~~~~~~~~~~~~~~~~
/home/$USER/Documents/CH341SER_LINUX/ch34x.c:1298:28: note: (near initialization for ‘ch34x_device.chars_in_buffer’)
cc1: some warnings being treated as errors
make[2]: *** [scripts/Makefile.build:297: /home/$USER/Documents/CH341SER_LINUX/ch34x.o] Error 1
make[1]: *** [Makefile:1902: /home/$USER/Documents/CH341SER_LINUX] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.15.0-58-generic'
make: *** [Makefile:5: default] Error 2
uname -r
可查看操作系统的发行版号,获得Ubuntu22.04的Linux版本是5.15.0-58-generic
在Linux kernel source code v5.15查看ch341.c的源代码,直接复制到CH341SER_LINUX/ch34x.c
中,重新make
,此次通过。
在目录执行sudo make load
命令,出现以下错误
modprobe usbserial
insmod ch34x.ko
insmod: ERROR: could not insert module ch34x.ko: File exists
make: *** [Makefile:10: load] Error 1
将目录中生成ch34x.ko
文件复制到/lib/modules/$(uname-r)/kernel/drivers/usb/serial
下,使用lsmod
查看模块,发现已识别。
终端输入以下指令,可以直接打开/lib/modules/$(uname-r)/kernel/drivers/usb/serial:
sudo xdg-open /lib/modules/5.15.148-tegra/kernel/drivers/usb/serial
Module Size Used by
ch34x 24576 0
usbserial 57344 1 ch34x
step4测试
正常到达这步就可以与开发板通信了,但是配置完minicom
后minicom: cannot open /dev/ttyUSB0: No such file or directory
这时查看/dev/ttyUSB*
发现没有此文件
zsh: no matches found: /dev/ttyUSB*
使用dmesg
查找原因sudo dmesg | grep tty
[ 0.223411] printk: console [tty0] enabled
[ 44.099146] usb 1-1: ch341-uart converter now attached to ttyUSB0
[ 44.673749] usb 1-1: usbfs: interface 0 claimed by ch34x while 'brltty' sets config #1
[ 44.675063] ch341-uart ttyUSB0: ch341-uart converter now disconnected from ttyUSB0
这里出现了brltty
进程,通过官网得知:
BRLTTY is a background process (daemon) providing access to the Linux/Unix console (when in text mode) for a blind person using a refreshable braille display.
brltty是一个后台进程(守护进程),为盲人提供对Linux/Unix控制台的访问(当处于文本模式时),使用可刷新盲文显示。
直接删除sudo apt remove brltty
重新连接开发板ls /dev/ttyUSB*
这时已经出现了/dev/ttyUSB0
这个设备!!!
此时sudo minicom -c on
可正常使用minicom
与开发板进行通信
报错3:usb权限不足
报错信息: