ubuntu安装ch34x驱动,并安装串口调试助手

1、查看系统自带的ch34x驱动

kangxubo@kangxubo-HKNS:/lib/modules/5.19.0-38-generic/kernel/drivers/usb/serial$ ls
aircable.ko         ftdi_sio.ko     kobil_sct.ko  pl2303.ko            usb_debug.ko
ark3116.ko          garmin_gps.ko   mct_u232.ko   qcaux.ko             usbserial.ko
belkin_sa.ko        io_edgeport.ko  metro-usb.ko  qcserial.ko          usb-serial-simple.ko
ch341.ko            io_ti.ko        mos7720.ko    quatech2.ko          usb_wwan.ko
cp210x.ko           ipaq.ko         mos7840.ko    safe_serial.ko       visor.ko
cyberjack.ko        ipw.ko          mxuport.ko    sierra.ko            whiteheat.ko
cypress_m8.ko       ir-usb.ko       navman.ko     spcp8x5.ko           wishbone-serial.ko
digi_acceleport.ko  iuu_phoenix.ko  omninet.ko    ssu100.ko            xr_serial.ko
empeg.ko            keyspan.ko      opticon.ko    symbolserial.ko      xsens_mt.ko
f81232.ko           keyspan_pda.ko  option.ko     ti_usb_3410_5052.ko
f81534.ko           kl5kusb105.ko   oti6858.ko    upd78f0730.ko
kangxubo@kangxubo-HKNS:/lib/modules/5.19.0-38-generic/kernel/drivers/usb/serial$ 

2、删除系统中带的比较老的版本

kangxubo@kangxubo-HKNS:/lib/modules/5.19.0-38-generic/kernel/drivers/usb/serial$ sudo rm -rf ch341.ko 
kangxubo@kangxubo-HKNS:/lib/modules/5.19.0-38-generic/kernel/drivers/usb/serial$ ls
aircable.ko         garmin_gps.ko   mct_u232.ko   qcaux.ko             usbserial.ko
ark3116.ko          io_edgeport.ko  metro-usb.ko  qcserial.ko          usb-serial-simple.ko
belkin_sa.ko        io_ti.ko        mos7720.ko    quatech2.ko          usb_wwan.ko
cp210x.ko           ipaq.ko         mos7840.ko    safe_serial.ko       visor.ko
cyberjack.ko        ipw.ko          mxuport.ko    sierra.ko            whiteheat.ko
cypress_m8.ko       ir-usb.ko       navman.ko     spcp8x5.ko           wishbone-serial.ko
digi_acceleport.ko  iuu_phoenix.ko  omninet.ko    ssu100.ko            xr_serial.ko
empeg.ko            keyspan.ko      opticon.ko    symbolserial.ko      xsens_mt.ko
f81232.ko           keyspan_pda.ko  option.ko     ti_usb_3410_5052.ko
f81534.ko           kl5kusb105.ko   oti6858.ko    upd78f0730.ko
ftdi_sio.ko         kobil_sct.ko    pl2303.ko     usb_debug.ko
kangxubo@kangxubo-HKNS:/lib/modules/5.19.0-38-generic/kernel/drivers/usb/serial$ 

3、下载ch34x驱动 https://www.wch.cn/download/CH341SER_LINUX_ZIP.html

解压后得到如下三个文件

kangxubo@kangxubo-HKNS:~/下载/CH341SER_LINUX$ ls
driver  README.md
kangxubo@kangxubo-HKNS:~/下载/CH341SER_LINUX$ cd driver/
kangxubo@kangxubo-HKNS:~/下载/CH341SER_LINUX/driver$ ls
ch341.c  ch341.h  Makefile
kangxubo@kangxubo-HKNS:~/下载/CH341SER_LINUX/driver$ 

4、查看系统版本号

kangxubo@kangxubo-HKNS:/$ uname -r
5.19.0-38-generic
kangxubo@kangxubo-HKNS:/$ 

5、根据自己的系统版本查找对应的ch341.c文件 https://elixir.bootlin.com/linux/v5.19/source/drivers/usb/serial/ch341.c

将文件内容拷贝复制到上边下载的驱动文件中惊醒替换

6、编译文件

kangxubo@kangxubo-HKNS:~/下载/CH341SER_LINUX/driver$ make
make -C /lib/modules/5.19.0-38-generic/build  M=/home/kangxubo/下载/CH341SER_LINUX/driver  
make[1]: 进入目录“/usr/src/linux-headers-5.19.0-38-generic”
warning: the compiler differs from the one used to build the kernel
  The kernel was built by: x86_64-linux-gnu-gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
  You are using:           gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
  CC [M]  /home/kangxubo/下载/CH341SER_LINUX/driver/ch341.o
  MODPOST /home/kangxubo/下载/CH341SER_LINUX/driver/Module.symvers
  CC [M]  /home/kangxubo/下载/CH341SER_LINUX/driver/ch341.mod.o
  LD [M]  /home/kangxubo/下载/CH341SER_LINUX/driver/ch341.ko
  BTF [M] /home/kangxubo/下载/CH341SER_LINUX/driver/ch341.ko
Skipping BTF generation for /home/kangxubo/下载/CH341SER_LINUX/driver/ch341.ko due to unavailability of vmlinux
make[1]: 离开目录“/usr/src/linux-headers-5.19.0-38-generic”
kangxubo@kangxubo-HKNS:~/下载/CH341SER_LINUX/driver$ ls
ch341.c  ch341.ko   ch341.mod.c  ch341.o   modules.order
ch341.h  ch341.mod  ch341.mod.o  Makefile  Module.symvers
kangxubo@kangxubo-HKNS:~/下载/CH341SER_LINUX/driver$

7、拷贝文件到系统目录下

kangxubo@kangxubo-HKNS:~/下载/CH341SER_LINUX/driver$ sudo cp ch341.ko /lib/modules/5.19.0-38-generic/kernel/drivers/usb/serial
[sudo] kangxubo 的密码: 
kangxubo@kangxubo-HKNS:~/下载/CH341SER_LINUX/driver$ ls
ch341.c  ch341.ko   ch341.mod.c  ch341.o   modules.order
ch341.h  ch341.mod  ch341.mod.o  Makefile  Module.symvers
kangxubo@kangxubo-HKNS:~/下载/CH341SER_LINUX/driver$ cd lib/modules/5.19.0-38-generic/kernel/drivers/usb/serial
bash: cd: lib/modules/5.19.0-38-generic/kernel/drivers/usb/serial: 没有那个文件或目录
kangxubo@kangxubo-HKNS:~/下载/CH341SER_LINUX/driver$ cd lib/modules/5.19.0-38-generic/kernel/drivers/usb/serial/
bash: cd: lib/modules/5.19.0-38-generic/kernel/drivers/usb/serial/: 没有那个文件或目录
kangxubo@kangxubo-HKNS:~/下载/CH341SER_LINUX/driver$ cd /lib/modules/5.19.0-38-generic/kernel/drivers/usb/serial
kangxubo@kangxubo-HKNS:/lib/modules/5.19.0-38-generic/kernel/drivers/usb/serial$ ls
aircable.ko         io_ti.ko        navman.ko        ti_usb_3410_5052.ko
ark3116.ko          ipaq.ko         omninet.ko       upd78f0730.ko
belkin_sa.ko        ipw.ko          opticon.ko       usb_debug.ko
ch341.ko            ir-usb.ko       option.ko        usbserial.ko
cp210x.ko           iuu_phoenix.ko  oti6858.ko       usb-serial-simple.ko
cyberjack.ko        keyspan.ko      pl2303.ko        usb_wwan.ko
cypress_m8.ko       keyspan_pda.ko  qcaux.ko         visor.ko
digi_acceleport.ko  kl5kusb105.ko   qcserial.ko      whiteheat.ko
empeg.ko            kobil_sct.ko    quatech2.ko      wishbone-serial.ko
f81232.ko           mct_u232.ko     safe_serial.ko   xr_serial.ko
f81534.ko           metro-usb.ko    sierra.ko        xsens_mt.ko
ftdi_sio.ko         mos7720.ko      spcp8x5.ko
garmin_gps.ko       mos7840.ko      ssu100.ko
io_edgeport.ko      mxuport.ko      symbolserial.ko
kangxubo@kangxubo-HKNS:/lib/modules/5.19.0-38-generic/kernel/drivers/usb/serial$ 

8、查看驱动是否安装完成

kangxubo@kangxubo-HKNS:/lib/modules/5.19.0-38-generic/kernel/drivers/usb/serial$ lsmod
Module                  Size  Used by
pcspkr                 16384  0
ch341                  24576  0
usbserial              57344  1 ch341
rfcomm                 86016  4
ccm                    20480  6
snd_soc_avs           131072  0

9、重启电脑

sudo depmod -a

 9、安装cutecom

kangxubo@kangxubo-HKNS:~$ sudo apt install cutecom
[sudo] kangxubo 的密码: 
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成                 
下列软件包是自动安装的并且现在不需要了:
  chromium-codecs-ffmpeg-extra gstreamer1.0-vaapi i965-va-driver ibus-data
  ibus-gtk4 intel-media-va-driver libaacs0 libaom3 libass9 libavcodec58
  libavformat58 libavutil56 libbdplus0 libblas3 libbluray2 libbs2b0
  libchromaprint1 libcodec2-1.0 libdav1d5 libflashrom1 libflite1 libftdi1-2
  libgme0 libgsm1 libgstreamer-plugins-bad1.0-0 libigdgmm12 liblilv-0-0
  libllvm13 libmarisa0 libmfx1 libmysofa1 libnorm1 libopencc-data libopencc1.1
  libopenmpt0 libpgm-5.3-0 libpinyin-data libpinyin13 libpostproc55
  librabbitmq4 librubberband2 libserd-0-0 libshine3 libsnappy1v5 libsord-0-0
  libsratom-0-0 libsrt1.4-gnutls libssh-gcrypt-4 libswresample3 libswscale5
  libudfread0 libva-drm2 libva-wayland2 libva-x11-2 libva2 libvdpau1
  libvidstab1.1 libx265-199 libxvidcore4 libzimg2 libzmq5 libzvbi-common
  libzvbi0 mesa-va-drivers mesa-vdpau-drivers pocketsphinx-en-us
  python3-ibus-1.0 va-driver-all vdpau-driver-all
使用'sudo apt autoremove'来卸载它(它们)。
将会同时安装下列软件:
  libqt5serialport5
建议安装:
  lrzsz
下列【新】软件包将被安装:
  cutecom libqt5serialport5
升级了 0 个软件包,新安装了 2 个软件包,要卸载 0 个软件包,有 7 个软件包未被升级。
需要下载 136 kB 的归档。
解压缩后会消耗 499 kB 的额外空间。
您希望继续执行吗? [Y/n] y
获取:1 http://cn.archive.ubuntu.com/ubuntu jammy/universe amd64 libqt5serialport5 amd64 5.15.3-1 [34.6 kB]
获取:2 http://cn.archive.ubuntu.com/ubuntu jammy/universe amd64 cutecom amd64 0.30.3-1build1 [101 kB]
已下载 136 kB,耗时 2秒 (76.3 kB/s)
正在选中未选择的软件包 libqt5serialport5:amd64。
(正在读取数据库 ... 系统当前共安装有 216853 个文件和目录。)
准备解压 .../libqt5serialport5_5.15.3-1_amd64.deb  ...
正在解压 libqt5serialport5:amd64 (5.15.3-1) ...
正在选中未选择的软件包 cutecom。
准备解压 .../cutecom_0.30.3-1build1_amd64.deb  ...
正在解压 cutecom (0.30.3-1build1) ...
正在设置 libqt5serialport5:amd64 (5.15.3-1) ...
正在设置 cutecom (0.30.3-1build1) ...
正在处理用于 desktop-file-utils (0.26-1ubuntu3) 的触发器 ...
正在处理用于 gnome-menus (3.36.0-1ubuntu3) 的触发器 ...
正在处理用于 libc-bin (2.35-0ubuntu3.1) 的触发器 ...
正在处理用于 man-db (2.10.2-1) 的触发器 ...
正在处理用于 mailcap (3.70+nmu1ubuntu1) 的触发器 ...
kangxubo@kangxubo-HKNS:~$ 

10、安装完成之后还是无法使用串口助手,因为识别不到串口,是因为brltty导致的的,处理方式可以参考 https://blog.csdn.net/qq_39851127/article/details/125988455,也可以直接卸载 brltty

kangxubo@kangxubo-HKNS:~$ sudo apt remove brltty
[sudo] kangxubo 的密码: 
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成                 
下列软件包是自动安装的并且现在不需要了:
  chromium-codecs-ffmpeg-extra gstreamer1.0-vaapi i965-va-driver ibus-data ibus-gtk4
  intel-media-va-driver libaacs0 libaom3 libass9 libavcodec58 libavformat58 libavutil56 libbdplus0
  libblas3 libbluray2 libbs2b0 libchromaprint1 libcodec2-1.0 libdav1d5 libflashrom1 libflite1
  libftdi1-2 libgme0 libgsm1 libgstreamer-plugins-bad1.0-0 libigdgmm12 liblilv-0-0 libllvm13
  libmarisa0 libmfx1 libmysofa1 libnorm1 libopencc-data libopencc1.1 libopenmpt0 libpcre2-32-0
  libpgm-5.3-0 libpinyin-data libpinyin13 libpostproc55 librabbitmq4 librubberband2 libserd-0-0
  libshine3 libsnappy1v5 libsord-0-0 libsratom-0-0 libsrt1.4-gnutls libssh-gcrypt-4 libswresample3
  libswscale5 libudfread0 libva-drm2 libva-wayland2 libva-x11-2 libva2 libvdpau1 libvidstab1.1
  libx265-199 libxvidcore4 libzimg2 libzmq5 libzvbi-common libzvbi0 mesa-va-drivers
  mesa-vdpau-drivers pocketsphinx-en-us python3-ibus-1.0 va-driver-all vdpau-driver-all
使用'sudo apt autoremove'来卸载它(它们)。
下列软件包将被【卸载】:
  brltty
升级了 0 个软件包,新安装了 0 个软件包,要卸载 1 个软件包,有 7 个软件包未被升级。
解压缩后将会空出 8,294 kB 的空间。
您希望继续执行吗? [Y/n] y
(正在读取数据库 ... 系统当前共安装有 216869 个文件和目录。)
正在卸载 brltty (6.4-4ubuntu3) ...
正在处理用于 man-db (2.10.2-1) 的触发器 ...
kangxubo@kangxubo-HKNS:~$ 

11、至此串口驱动安装完成但是在运行的时候是不能有数据输出的,是因为串口模块的权限问题,在串口插上的时候可以执行如下操作

kangxubo@kangxubo-HKNS:/dev$ sudo chmod 777  ttyUSB0 
[sudo] kangxubo 的密码: 
kangxubo@kangxubo-HKNS:/dev$ 

12、打开串口助手就可以接收到数据了,但是上边的操作是一次性的,如果串口重新插拔或者系统重启则串口还是不能正常使用,下边是普通用户可以一直使用的操作步骤

kangxubo@kangxubo-HKNS:~$ sudo gedit /etc/udev/rules.d/70-ttyusb.rules
[sudo] kangxubo 的密码: 
kangxubo@kangxubo-HKNS:~$ 

13、在打开的文件中加入如下命令

KERNEL=="ttyUSB[0-9]*", MODE="0666"
KERNEL=="ttyS[0-9]*", MODE="0666"

14、给文件添加权限

kangxubo@kangxubo-HKNS:/etc/udev/rules.d$ sudo chmod -R 777 70-ttyusb.rules 
kangxubo@kangxubo-HKNS:/etc/udev/rules.d$ 

15、至此串口可以正常插拔不用每次都设置权限了。

 

posted @ 2023-04-01 22:13  梦想之每天进步一点点  阅读(1558)  评论(0编辑  收藏  举报