Ubuntu 20.04安装绿联PL2303串口驱动

Posted gsls200808

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ubuntu 20.04安装绿联PL2303串口驱动相关的知识,希望对你有一定的参考价值。

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

绿联PL2303串口驱动下载

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

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

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

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

cd 5.4.89_ok/
make all

编译报错

root@hello-ThinkServer-TS80X:~/PL2303芯片驱动3.7/PL2303芯片驱动3.7/Linux/PL2303G_Linux_Driver_v1.0.6/5.4.89_ok# make all
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
make[1]: 进入目录“/usr/src/linux-headers-5.13.0-30-generic”
  CC [M]  /root/PL2303芯片驱动3.7/PL2303芯片驱动3.7/Linux/PL2303G_Linux_Driver_v1.0.6/5.4.89_ok/pl2303.o
/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]
 1109 |  .get_serial =  pl2303_get_serial,
      |                 ^~~~~~~~~~~~~~~~~
/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’)
/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]
 1122 |  .port_remove =  pl2303_port_remove,
      |                  ^~~~~~~~~~~~~~~~~~
/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’)
/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]
  622 | static bool pl2303_enable_xonxoff(struct tty_struct *tty, const struct pl2303_type_data *type)
      |             ^~~~~~~~~~~~~~~~~~~~~
/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]
  258 | static int pl2303_update_reg(struct usb_serial *serial, u8 reg, u8 mask, u8 val)
      |            ^~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors
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
make[1]: *** [Makefile:1879:/root/PL2303芯片驱动3.7/PL2303芯片驱动3.7/Linux/PL2303G_Linux_Driver_v1.0.6/5.4.89_ok] 错误 2
make[1]: 离开目录“/usr/src/linux-headers-5.13.0-30-generic”
make: *** [Makefile:4:all] 错误 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的报错

pl2303.c:439:9: error: ‘return’ with a value, in function returning void [-Werror=return-type]
  439 |  return 0;
pl2303.c:923:9: error: ‘return’ with a value, in function returning void [-Werror=return-type]
  923 |  return 0;

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

重新用make all编译成功

拷贝编译模块

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

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

sudo nano /etc/modules
#添加内容
pl2303
#保存

最后重启

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程序测试收发 这个能作为判断标准

以上是关于Ubuntu 20.04安装绿联PL2303串口驱动的主要内容,如果未能解决你的问题,请参考以下文章

Centos 7.5 1804安装绿联PL2303串口驱动

4418开发板Win8.1下PL2303USB转串口驱动安装

PL2303 USB转串口 com

cp2102.pl2303.ch340.ft232哪个串口转usb芯片好

VirtualBox虚拟机 UBUNTU 10.04系统怎么用USB转串口设备?

VirtualBox虚拟机 UBUNTU 10.04系统怎么用USB转串口设备?