• Ubuntu 20.04安装绿联PL2303串口驱动


    之前安过CentOS的驱动,这篇是ubuntu的

    绿联PL2303串口驱动下载

    绿联USB转DB9,RS232串口线,Windows驱动下载地址

    下载后解压有个linux目录,驱动需要根据内核进目录自行编译

    1. hello@hello-ThinkServer-TS80X:/root$ uname -r
    2. 5.15.0-46-generic

    可以看到ubuntu的版本是5.15,但是目前文件夹最大版本是5.4.89,所以死马当活马医,用这个试试

    1. cd 5.4.89_ok/
    2. make all

    编译报错

    1. root@hello-ThinkServer-TS80X:~/PL2303芯片驱动3.7/PL2303芯片驱动3.7/Linux/PL2303G_Linux_Driver_v1.0.6/5.4.89_ok# make all
    2. make -C /lib/modules/5.13.0-30-generic/build M=/root/PL2303芯片驱动3.7/PL2303芯片驱动3.7/Linux/PL2303G_Linux_Driver_v1.0.6/5.4.89_ok modules
    3. make[1]: 进入目录“/usr/src/linux-headers-5.13.0-30-generic”
    4. CC [M] /root/PL2303芯片驱动3.7/PL2303芯片驱动3.7/Linux/PL2303G_Linux_Driver_v1.0.6/5.4.89_ok/pl2303.o
    5. /root/PL2303芯片驱动3.7/PL2303芯片驱动3.7/Linux/PL2303G_Linux_Driver_v1.0.6/5.4.89_ok/pl2303.c:1109:17: error: initialization of ‘void (*)(struct tty_struct *, struct serial_struct *)’ from incompatible pointer type ‘int (*)(struct tty_struct *, struct serial_struct *)’ [-Werror=incompatible-pointer-types]
    6. 1109 | .get_serial = pl2303_get_serial,
    7. | ^~~~~~~~~~~~~~~~~
    8. /root/PL2303芯片驱动3.7/PL2303芯片驱动3.7/Linux/PL2303G_Linux_Driver_v1.0.6/5.4.89_ok/pl2303.c:1109:17: note: (near initialization for ‘pl2303_device.get_serial’)
    9. /root/PL2303芯片驱动3.7/PL2303芯片驱动3.7/Linux/PL2303G_Linux_Driver_v1.0.6/5.4.89_ok/pl2303.c:1122:18: error: initialization of ‘void (*)(struct usb_serial_port *)’ from incompatible pointer type ‘int (*)(struct usb_serial_port *)’ [-Werror=incompatible-pointer-types]
    10. 1122 | .port_remove = pl2303_port_remove,
    11. | ^~~~~~~~~~~~~~~~~~
    12. /root/PL2303芯片驱动3.7/PL2303芯片驱动3.7/Linux/PL2303G_Linux_Driver_v1.0.6/5.4.89_ok/pl2303.c:1122:18: note: (near initialization for ‘pl2303_device.port_remove’)
    13. /root/PL2303芯片驱动3.7/PL2303芯片驱动3.7/Linux/PL2303G_Linux_Driver_v1.0.6/5.4.89_ok/pl2303.c:622:13: warning: ‘pl2303_enable_xonxoff’ defined but not used [-Wunused-function]
    14. 622 | static bool pl2303_enable_xonxoff(struct tty_struct *tty, const struct pl2303_type_data *type)
    15. | ^~~~~~~~~~~~~~~~~~~~~
    16. /root/PL2303芯片驱动3.7/PL2303芯片驱动3.7/Linux/PL2303G_Linux_Driver_v1.0.6/5.4.89_ok/pl2303.c:258:12: warning: ‘pl2303_update_reg’ defined but not used [-Wunused-function]
    17. 258 | static int pl2303_update_reg(struct usb_serial *serial, u8 reg, u8 mask, u8 val)
    18. | ^~~~~~~~~~~~~~~~~
    19. cc1: some warnings being treated as errors
    20. make[2]: *** [scripts/Makefile.build:281/root/PL2303芯片驱动3.7/PL2303芯片驱动3.7/Linux/PL2303G_Linux_Driver_v1.0.6/5.4.89_ok/pl2303.o] 错误 1
    21. make[1]: *** [Makefile:1879/root/PL2303芯片驱动3.7/PL2303芯片驱动3.7/Linux/PL2303G_Linux_Driver_v1.0.6/5.4.89_ok] 错误 2
    22. make[1]: 离开目录“/usr/src/linux-headers-5.13.0-30-generic”
    23. make: *** [Makefile:4all] 错误 2

    报错主要有两处,是类型不匹配

    第一个报错

    pl2303.c:1109:17: error: initialization of ‘void (*)(struct tty_struct *, struct serial_struct *)’ from incompatible pointer type ‘int (*)(struct tty_struct *, struct serial_struct *)’ [-Werror=incompatible-pointer-types]

    类型不兼容,改类型

    修改914行 

    static int pl2303_get_serial(struct tty_struct *tty,  

    改成

    static void pl2303_get_serial(struct tty_struct *tty,

    第二个报错同理

    pl2303.c:1122:18: error: initialization of ‘void (*)(struct usb_serial_port *)’ from incompatible pointer type ‘int (*)(struct usb_serial_port *)’ [-Werror=incompatible-pointer-types]


    也是类型不兼容

    修改433行

    static int pl2303_port_remove(struct usb_serial_port *port) 

    改成

     static void pl2303_port_remove(struct usb_serial_port *port)

    重新用make all编译

    有两个 return 0的报错

    1. pl2303.c:439:9: error: ‘returnwith a value, in function returning void [-Werror=return-type]
    2. 439 | return 0;
    3. pl2303.c:923:9: error: ‘returnwith a value, in function returning void [-Werror=return-type]
    4. 923 | return 0;

    将两个return 0;改成return;即可

    重新用make all编译成功

    拷贝编译模块

    sudo cp pl2303.ko /lib/modules/$(uname -r)/kernel/drivers/usb/serial

    编辑/etc/modules文件添加驱动名pl2303

    1. sudo nano /etc/modules
    2. #添加内容
    3. pl2303
    4. #保存

    最后重启

    reboot

    重启之后可以使用了

    那么怎么判断usb串口驱动是否正常呢?

    1.判断是否有/dev/ttyUSB* 设备 这个不能作为判断标准,接入usb设备后就能查到这个设备

    2.判断dmesg | grep tty 是否输出usb 1-1: FTDI USB Serial Device converter now attached to ttyUSB0 这个也不能作为判断标准,接入usb后也会有这个

    3.stty -F 测试收发 这个能作为判断标准

    4.minicom程序测试收发 这个能作为判断标准

  • 相关阅读:
    uniapp 跨端兼容 条件编译
    如何解决if...else,9条锦囊妙计,助你写出更优雅的代码(荣耀典藏版)
    MySQL 多表查询
    OpenCV图像处理学习十四,图像阈值处理操作threshold()以及全局阈值和自适应阈值处理应用
    面试官:关于网络IO模型的原理如何理解,说说你的分析
    下载安装 VMware &虚拟机
    Thinking for Doing:让LLMs能推断他人心理状态来做出适当的行动。
    软件项目管理 6.2.功能点估算法
    MuseScore编译成 移动端的app 02
    leetcode1221. 分割平衡字符串
  • 原文地址:https://blog.csdn.net/gsls200808/article/details/126466867