当前位置:首页 » 《关注互联网》 » 正文

CH342/CH343/CH344/CH347/CH9101/CH9102/CH9103/CH9104 Linux串口驱动使用教程

8 人参与  2024年04月15日 17:35  分类 : 《关注互联网》  评论

点击全文阅读


CH343 Linux串口驱动 ch343ser_linux 支持USB转串口芯片 ch342/ch343/ch344/ch347/ch9101/ch9102/ch9103/ch9104等 ,同时该驱动配合ch343_lib库还提供了芯片GPIO接口的读写功能,内部EEPROM的信息配置和读取功能等。

芯片型号串口数量GPIO数量
CH342F/K2CH342F:12
CH343G/P/K1
CH344Q/L4

CH344Q:16

CH344L:12

CH347F/T2CH347F/T:8
CH9101U/H/R/Y/N1

CH9101U/H:6

CH9101R/Y:4

CH9102F/X1

CH9102F:5

CH9102X:6

CH9103M2CH9103M:12
CH9104L4CH9104L:24

1、下载驱动

https://github.com/WCHSoftGroup/ch343ser_linuxicon-default.png?t=N7T8https://github.com/WCHSoftGroup/ch343ser_linux可以使用git clone下载该驱动,也可以点击网页下载压缩包文件。

2、拷贝驱动

将步骤一下载的驱动拷贝到本地路径下,如下所示:

 3、安装驱动

 实行指令如下:

1、进入驱动所在文件夹cd driver2、编译驱动并自动安装sudo make install

通过日志可以看到驱动的编译以及安装过程 ,成功时会在driver目录下生成 ch343.ko 驱动文件,然后将此驱动文件拷贝到系统默认驱动路径下,自动执行 depmod -a 指令,使其系统启动自动生效。

4、查看串口设备 

当驱动支持的USB串口设备已插入,且驱动安装加载成功的情况下,在系统的 /dev 路径下会自动生成串口节点:/dev/ttyCH343USB*,示例如下:

USB转单串口设备CH343:

 USB转双串口设备CH342:

USB转4串口设备CH344Q:

 5、Linux系统串口操作

请移步至如下博客:

Linux串口调试工具_linux 串口调试工具_PC技术小能手的博客-CSDN博客linux系统下串口调试和应用 minicom/cutecom/picocom/putty/ttyuart_linux 串口调试工具https://blog.csdn.net/WCH_TechGroup/article/details/124244318

6、常见问题汇总

未发现串口节点时,可按照以下步骤进行排查。

1. 通过lsusb指令检查该设备是否已插入并正常工作,正常时,会看到厂商VID是:0x1A86的设备,如下所示:

2、检查驱动是否已加载,成功时如下所示:

3、若步骤1和2通过,仍查找不到串口,则设备插入后使用dmesg指令查看日志信息,成功时如下所示:

若失败,需要确认是否自动匹配到了cdc-acm驱动,如下所示:

该部分说明如下:

USB to UART(s) chip ch342/ch343/ch344/ch347/ch9101/ch9102/ch9103/ch9104 are fully compliant to the Communications Device Class (CDC) standard, they will work with a standard CDC-ACM driver (CDC - Abstract Control Model). Linux operating systems supply a default CDC-ACM driver that can be used with these USB UART devices. In Linux, this driver file name is cdc-acm.

The CDC-ACM driver has limited capabilities to control specific devices. This generic driver does not have any knowledge about specific device protocols. Because of this, device manufacturers can create an alternate, or custom driver that is capable of accessing the device specific function sets, such as hardware flow control or GPIO functions.

If you use this VCP driver, please check that the CDC-ACM driver was not installed for the USB UART devices mentioned above. You can use command "ls /dev/ttyACM*" to confirm that, to remove the CDC-ACM driver, use command "rmmod cdc-acm".

在嵌入式或安卓系统上如需要满足让ch343等串口芯片使用VCP驱动,同时保持cdc-acm驱动给系统的其他设备使用,在可以修改驱动源码的情况下,可以在cdc-acm.c驱动文件的 static const struct usb_device_id acm_ids[] 数组中添加相关ID,将设备加入到黑名单:

    /* Exclude WCH usb to uart devices */{ USB_DEVICE(0x1a86, 0x55d2), .driver_info = IGNORE_DEVICE, }, /* ch342 chip */{ USB_DEVICE(0x1a86, 0x55d3), .driver_info = IGNORE_DEVICE, },       /* ch343 chip */{ USB_DEVICE(0x1a86, 0x55d5), .driver_info = IGNORE_DEVICE, },       /* ch344 chip */{ USB_DEVICE(0x1a86, 0x55d6), .driver_info = IGNORE_DEVICE, },       /* ch9143 chip */{ USB_DEVICE(0x1a86, 0x55da), .driver_info = IGNORE_DEVICE, },       /* ch347t chip mode0*/{ USB_DEVICE_INTERFACE_NUMBER(0x1a86, 0x55db, 0x00), .driver_info = IGNORE_DEVICE, }, /* ch347t chip mode1*/{ USB_DEVICE_INTERFACE_NUMBER(0x1a86, 0x55dd, 0x00), .driver_info = IGNORE_DEVICE, }, /* ch347t chip mode3*/{ USB_DEVICE_INTERFACE_NUMBER(0x1a86, 0x55de, 0x00), .driver_info = IGNORE_DEVICE, }, /* ch347f chip uart0*/{ USB_DEVICE_INTERFACE_NUMBER(0x1a86, 0x55de, 0x02), .driver_info = IGNORE_DEVICE, }, /* ch347f chip uart1*/{ USB_DEVICE(0x1a86, 0x55d8), .driver_info = IGNORE_DEVICE, },       /* ch9101 chip */{ USB_DEVICE(0x1a86, 0x55d4), .driver_info = IGNORE_DEVICE, },       /* ch9102 chip */{ USB_DEVICE(0x1a86, 0x55d7), .driver_info = IGNORE_DEVICE, },       /* ch9103 chip */{ USB_DEVICE(0x1a86, 0x55df), .driver_info = IGNORE_DEVICE, },       /* ch9104 chip */

 4、使用VCP驱动,非CDC-ACM驱动

驱动的自动安装服务已经做了开机优先使用VCP驱动,该操作默认支持Ubuntu等桌面版或服务器版操作系统。安卓或嵌入式Linux可优选如上黑名单操作方式。

当此方式无效时,可使用shell命令:

sudo rmmod cdc_acmsudo rmmod ch343sudo modprobe ch343

可以将此命令做成开机脚本自动执行,也可以使用service服务实现,具体参考以下链接: https://github.com/WCHSoftGroup/ch343ser_linux_installicon-default.png?t=N7T8https://github.com/WCHSoftGroup/ch343ser_linux_install该方式的实现原理也是先解绑cdc-acm驱动,然后加载ch343的vcp驱动。

此外,当系统确认不使用cdc-acm驱动的情况下,也可以移除cdc-acm驱动。

5、ch343ser_linux驱动包提供的安装服务是针对于本地编译,非宿主机交叉编译。如果需要交叉编译,则可参考以下步骤:

1、拷贝驱动文件ch343.c和ch343.h到系统的源码路径下:driver/usb/serial2、修改源码目录同级的Kconfig和Makefile文件,增加ch343驱动相关信息3、Kconfig文件修改  config USB_SERIAL_CH343tristate "CH343 USB Single and Multi Port Serial Driver"help  Say Y here if you want to use a ch342/ch343/ch344/ch347/ch9101/ch9102/ch9103/ch9104  USB to serial adapter.  To compile this driver as a module, choose M here: the  module will be called ch343.4、Makefile文件修改  obj-$(CONFIG_USB_SERIAL_CH343) += ch343.o

按照以上步骤操作后,编译系统的时候选中添加的ch343驱动即可。

关于CH343SER驱动配合动态库完成GPIO的使用,请移步其他博客。


点击全文阅读


本文链接:http://m.zhangshiyu.com/post/95739.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

关于我们 | 我要投稿 | 免责申明

Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1