ubuntu安裝ch34x驅動,並安裝串列埠偵錯助手

2023-04-02 06:06:13

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、至此串列埠驅動安裝完成