CH343 Linux串口驱动 ch343ser_linux 支持USB转串口芯片 ch342/ch343/ch344/ch347/ch9101/ch9102/ch9103/ch9104等 ,同时该驱动配合ch343_lib库还提供了芯片GPIO接口的读写功能,内部EEPROM的信息配置和读取功能等。
芯片型号 | 串口数量 | GPIO数量 |
CH342F/K | 2 | CH342F:12 |
CH343G/P/K | 1 | — |
CH344Q/L | 4 | CH344Q:16 CH344L:12 |
CH347F/T | 2 | CH347F/T:8 |
CH9101U/H/R/Y/N | 1 | CH9101U/H:6 CH9101R/Y:4 |
CH9102F/X | 1 | CH9102F:5 CH9102X:6 |
CH9103M | 2 | CH9103M:12 |
CH9104L | 4 | CH9104L:24 |
1、下载驱动
https://github.com/WCHSoftGroup/ch343ser_linuxhttps://github.com/WCHSoftGroup/ch343ser_linux可以使用git clone下载该驱动,也可以点击网页下载压缩包文件。
2、拷贝驱动
将步骤一下载的驱动拷贝到本地路径下,如下所示:
3、安装驱动
实行指令如下:
1、进入驱动所在文件夹
cd driver
2、编译驱动并自动安装
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".
4、使用VCP驱动,非CDC-ACM驱动
驱动的自动安装服务已经做了开机优先使用VCP驱动,该操作默认支持Ubuntu等操作系统。
当此方式无效时,可使用shell命令:
sudo rmmod cdc_acm
sudo rmmod ch343
sudo modprobe ch343
可以将此命令做成开机脚本自动执行,也可以使用service服务实现,具体参考以下链接: https://github.com/WCHSoftGroup/ch343ser_linux_installhttps://github.com/WCHSoftGroup/ch343ser_linux_install该方式的实现原理也是先解绑cdc-acm驱动,然后加载ch343的vcp驱动。
此外,当系统确认不使用cdc-acm驱动的情况下,也可以移除cdc-acm驱动。
5、ch343ser_linux驱动包提供的安装服务是针对于本地编译,非宿主机交叉编译。如果需要交叉编译,则可参考以下步骤:
1、拷贝驱动文件ch343.c和ch343.h到系统的源码路径下:driver/usb/serial
2、修改源码目录同级的Kconfig和Makefile文件,增加ch343驱动相关信息
3、Kconfig文件修改
config USB_SERIAL_CH343
tristate "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的使用,请移步其他博客。