【官方发布】CH9344 USB转四串口芯片Linux驱动

你好,我在kernel4.4上运行这个ch9344.ko时(1.16版本,makefile没有修改),提示:

insmod: can't insert '/system/lib/modules/ch934x.ko': invalid module format


同样的编译器编译其他的驱动,就没问题,急,求帮助


谢谢


如果修改makefile

把KERNELDIR := /lib/modules/$(shell uname -r)/build


改成:KERNELDIR ?=$(KERNEL_DIR)


则编译报错:

build driver module: ch9344

rm -rf *.mk .tmp_versions Module.symvers *.mod.c *.o *.ko .*.cmd Module.markers modules.order

make -C /home/vm/rk/project/firefly-sdk/rk3328_drv/../kernel  M=/home/vm/rk/project/firefly-sdk/rk3328_drv/ch9344  

make[1]: Entering directory '/home/vm/rk/project/firefly-sdk/kernel'

  LD      /home/vm/rk/project/firefly-sdk/rk3328_drv/ch9344/built-in.o

  CC [M]  /home/vm/rk/project/firefly-sdk/rk3328_drv/ch9344/ch934x.o

/home/vm/rk/project/firefly-sdk/rk3328_drv/ch9344/ch934x.c: In function 'ch934x_tty_ioctl':

/home/vm/rk/project/firefly-sdk/rk3328_drv/ch9344/ch934x.c:1395:16: warning: unused variable 'flags' [-Wunused-variable]

error, forbidden warning:ch934x.c:1395

  unsigned long flags;

                ^~~~~

At top level:

/home/vm/rk/project/firefly-sdk/rk3328_drv/ch9344/ch934x.c:2202:12: warning: 'ch934x_reset_resume' defined but not used [-Wunused-function]

error, forbidden warning:ch934x.c:2202

 static int ch934x_reset_resume(struct usb_interface *intf)

            ^~~~~~~~~~~~~~~~~~~

/home/vm/rk/project/firefly-sdk/rk3328_drv/ch9344/ch934x.c:2142:12: warning: 'ch934x_suspend' defined but not used [-Wunused-function]

error, forbidden warning:ch934x.c:2142

 static int ch934x_suspend(struct usb_interface *intf, pm_message_t message)

            ^~~~~~~~~~~~~~

/home/vm/rk/project/firefly-sdk/rk3328_drv/ch9344/ch934x.c:1158:13: warning: 'ch934x_tty_unthrottle' defined but not used [-Wunused-function]

error, forbidden warning:ch934x.c:1158

 static void ch934x_tty_unthrottle(struct tty_struct *tty)

             ^~~~~~~~~~~~~~~~~~~~~

/home/vm/rk/project/firefly-sdk/rk3328_drv/ch9344/ch934x.c:1148:13: warning: 'ch934x_tty_throttle' defined but not used [-Wunused-function]

error, forbidden warning:ch934x.c:1148

 static void ch934x_tty_throttle(struct tty_struct *tty)

             ^~~~~~~~~~~~~~~~~~~

/home/vm/rk/project/firefly-sdk/rk3328_drv/ch9344/ch934x.c:219:12: warning: 'ch934x_cmd_in' defined but not used [-Wunused-function]

error, forbidden warning:ch934x.c:219

 static int ch934x_cmd_in(struct ch934x *ch934x,

            ^~~~~~~~~~~~~

/home/vm/rk/project/firefly-sdk/rk3328_drv/ch9344/ch934x.c:154:12: warning: 'ch934x_control_out' defined but not used [-Wunused-function]

error, forbidden warning:ch934x.c:154

 static int ch934x_control_out(struct ch934x *ch934x, u8 request,

            ^~~~~~~~~~~~~~~~~~

scripts/Makefile.build:283: recipe for target '/home/vm/rk/project/firefly-sdk/rk3328_drv/ch9344/ch934x.o' failed

make[2]: *** [/home/vm/rk/project/firefly-sdk/rk3328_drv/ch9344/ch934x.o] Error 1

Makefile:1479: recipe for target '_module_/home/vm/rk/project/firefly-sdk/rk3328_drv/ch9344' failed

make[1]: *** [_module_/home/vm/rk/project/firefly-sdk/rk3328_drv/ch9344] Error 2

make[1]: Leaving directory '/home/vm/rk/project/firefly-sdk/kernel'

Makefile:5: recipe for target 'default' failed

make: *** [default] Error 2



您好,建议先明确下编译其他驱动所引用的Kernel Src是否和CH9344引用的相同。常规情况若一样不会提示格式不兼容,也可以使用file或module相关命令检查下ko文件兼容性。另,不排除你的系统存在多个版本的kernel-headers。


这个是另一个驱动的makefile


ifneq ($(KERNELRELEASE), )

obj-m := common.o 

else

KERNELDIR ?=$(KERNEL_DIR)

PWD       := $(shell pwd)




default:

$(MAKE) -C $(KERNEL_DIR) M=$(PWD) modules

endif


clean:

rm -rf *.d *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions modules.order Module.symvers


depend .depend dep:

$(CC) $(CFLAGS) -M *.c > .depend


ifeq (.depend,$(wildcard .depend))

include .depend

endif



感觉还是ch934x的makefile导致的问题,但是我如果改了makefile又编译出错,如上38楼


您好,对于默认makefile编译出错问题,应该是编译驱动kernel src没有对应到默认makefile指定的路径。改用你第二种方式理论上可行,出错是因为你系统默认makefile规则要求,强制将warning当成错误。可尝试:

1、修改kernel src的makefile,取消将警告当作错误的问题;

2、修改ch934x.c其中的warning的未使用函数进行注释,重新编译;


你好,编译出错的问题,我已经改好了,把未使用的函数注释了就好,但是加载驱动的时候,没有提示错误,/dev/目录下也没有生成对应的设备节点,这个是为什么?


以下是加载驱动的log:

 insmod /system/lib/modules/ch934x.ko 

usbcore: registered new interface driver usb_wch

ch934x: USB driver for USB to serial chip ch9344.

ch934x: V1.16 On 2020.12.05



如上问题,是由于系统未能正常识别到CH9344设备导致。关于驱动加载成功但节点未产生时,建议先通过“lsusb”或"dmesg"命令查看usb设备的识别和工作情况。


您好,上述的问题现在都解决了,现在想把9344串口信号转成485信号,这个是否支持呢,我在使用gpio时,发现不能控制,一直是低电平


tty device test ok.

press s to set modem, z to clear modem, g to get modem, b to send break, w to write, r to read, G to test gpio, q for quit.

G

press e to enable gpio, d to disable gpio, press o to set gpio output, i on input, d to disable gpio, h to output high, l on low, g to get gpio, q for quit.

e

press e to enable gpio, d to disable gpio, press o to set gpio output, i on input, d to disable gpio, h to output high, l on low, g to get gpio, q for quit.

o

press e to enable gpio, d to disable gpio, press o to set gpio output, i on input, d to disable gpio, h to output high, l on low, g to get gpio, q for quit.

h

press e to enable gpio, d to disable gpio, press o to set gpio output, i on input, d to disable gpio, h to output high, l on low, g to get gpio, q for quit.


以上操作无效果



比较着急,请问有了解gpio使用方式的吗


您好,如上驱动和应用是支持芯片GPIO操作的,且CH9344芯片的RS485控制信号串口发送时自动控制无需通过软件开启。若测试遇到无法正常进行,先通过系统命令lsusb或sysfs查看当前ch9344的usb revision版本号(v36.00及以上可支持),有疑问可按照下方联系方式与我沟通。


你好,谢谢回复

我这边用的是嵌入式linux,lsusb只能看到这些信息,


[root@rk3328:/]# lsusb

Bus 004 Device 002: ID 1a86:e018

Bus 001 Device 001: ID 1d6b:0002

Bus 002 Device 001: ID 1d6b:0002

Bus 003 Device 001: ID 1d6b:0001

Bus 004 Device 001: ID 1d6b:0002

Bus 005 Device 001: ID 1d6b:0003


我需要如何确定9344的内部版本呢


usb设备插入后输入dmesg信息 ,查看usb枚举的详细信息即可。


你好,我扫了一遍没找到相关信息哦,9344已经加载进来了




uevent path:/sys/bus/usb/devices/./uevent 

uevent path:/sys/bus/usb/devices/../uevent 

uevent path:/sys/bus/usb/devices/4-1/uevent 

line: MAJOR=189

, prefix: PRODUCT=.

line: MINOR=385

, prefix: PRODUCT=.

line: DEVNAME=bus/usb/004/002

, prefix: PRODUCT=.

line: DEVTYPE=usb_device

, prefix: PRODUCT=.

line: DRIVER=usb

, prefix: PRODUCT=.

line: PRODUCT=1a86/e018/3500

, prefix: PRODUCT=.

pid:vid : 1a86:e018 

line: TYPE=255/128/55

, prefix: PRODUCT=.

line: BUSNUM=004

, prefix: PRODUCT=.

line: DEVNUM=002

, prefix: PRODUCT=.

uevent path:/sys/bus/usb/devices/usb1/uevent 

line: MAJOR=189

, prefix: PRODUCT=.

line: MINOR=0

, prefix: PRODUCT=.

line: DEVNAME=bus/usb/001/001

, prefix: PRODUCT=.

line: DEVTYPE=usb_device

, prefix: PRODUCT=.

line: DRIVER=usb

, prefix: PRODUCT=.

line: PRODUCT=1d6b/2/404

, prefix: PRODUCT=.

pid:vid : 1d6b:0002 

line: TYPE=9/0/1

, prefix: PRODUCT=.

line: BUSNUM=001

, prefix: PRODUCT=.

line: DEVNUM=001

, prefix: PRODUCT=.

uevent path:/sys/bus/usb/devices/usb2/uevent 

line: MAJOR=189

, prefix: PRODUCT=.

line: MINOR=128

, prefix: PRODUCT=.

line: DEVNAME=bus/usb/002/001

, prefix: PRODUCT=.

line: DEVTYPE=usb_device

, prefix: PRODUCT=.

line: DRIVER=usb

, prefix: PRODUCT=.

line: PRODUCT=1d6b/2/404

, prefix: PRODUCT=.

pid:vid : 1d6b:0002 

line: TYPE=9/0/0

, prefix: PRODUCT=.

line: BUSNUM=002

, prefix: PRODUCT=.

line: DEVNUM=001

, prefix: PRODUCT=.

uevent path:/sys/bus/usb/devices/usb3/uevent 

line: MAJOR=189

, prefix: PRODUCT=.

line: MINOR=256

, prefix: PRODUCT=.

line: DEVNAME=bus/usb/003/001

, prefix: PRODUCT=.

line: DEVTYPE=usb_device

, prefix: PRODUCT=.

line: DRIVER=usb

, prefix: PRODUCT=.

line: PRODUCT=1d6b/1/404

, prefix: PRODUCT=.

pid:vid : 1d6b:0001 

line: TYPE=9/0/0

, prefix: PRODUCT=.

line: BUSNUM=003

, prefix: PRODUCT=.

line: DEVNUM=001

, prefix: PRODUCT=.

uevent path:/sys/bus/usb/devices/usb4/uevent 

line: MAJOR=189

, prefix: PRODUCT=.

line: MINOR=384

, prefix: PRODUCT=.

line: DEVNAME=bus/usb/004/001

, prefix: PRODUCT=.

line: DEVTYPE=usb_device

, prefix: PRODUCT=.

line: DRIVER=usb

, prefix: PRODUCT=.

line: PRODUCT=1d6b/2/404

, prefix: PRODUCT=.

pid:vid : 1d6b:0002 

line: TYPE=9/0/1

, prefix: PRODUCT=.

line: BUSNUM=004

, prefix: PRODUCT=.

line: DEVNUM=001

, prefix: PRODUCT=.

uevent path:/sys/bus/usb/devices/usb5/uevent 

line: MAJOR=189

, prefix: PRODUCT=.

line: MINOR=512

, prefix: PRODUCT=.

line: DEVNAME=bus/usb/005/001

, prefix: PRODUCT=.

line: DEVTYPE=usb_device

, prefix: PRODUCT=.

line: DRIVER=usb

, prefix: PRODUCT=.

line: PRODUCT=1d6b/3/404

, prefix: PRODUCT=.

pid:vid : 1d6b:0003 

line: TYPE=9/0/3

, prefix: PRODUCT=.

line: BUSNUM=005

, prefix: PRODUCT=.

line: DEVNUM=001

, prefix: PRODUCT=.

uevent path:/sys/bus/usb/devices/3-0:1.0/uevent 

line: DEVTYPE=usb_interface

, prefix: PRODUCT=.

line: DRIVER=hub

, prefix: PRODUCT=.

line: PRODUCT=1d6b/1/404

, prefix: PRODUCT=.

pid:vid : 1d6b:0001 

line: TYPE=9/0/0

, prefix: PRODUCT=.

line: INTERFACE=9/0/0

, prefix: PRODUCT=.

line: MODALIAS=usb:v1D6Bp0001d0404dc09dsc00dp00ic09isc00ip00in00

, prefix: PRODUCT=.

uevent path:/sys/bus/usb/devices/4-0:1.0/uevent 

line: DEVTYPE=usb_interface

, prefix: PRODUCT=.

line: DRIVER=hub

, prefix: PRODUCT=.

line: PRODUCT=1d6b/2/404

, prefix: PRODUCT=.

pid:vid : 1d6b:0002 

line: TYPE=9/0/1

, prefix: PRODUCT=.

line: INTERFACE=9/0/0

, prefix: PRODUCT=.

line: MODALIAS=usb:v1D6Bp0002d0404dc09dsc00dp01ic09isc00ip00in00

, prefix: PRODUCT=.

uevent path:/sys/bus/usb/devices/4-1:1.0/uevent 

line: DEVTYPE=usb_interface

, prefix: PRODUCT=.

line: PRODUCT=1a86/e018/3500

, prefix: PRODUCT=.

pid:vid : 1a86:e018 

line: TYPE=255/128/55

, prefix: PRODUCT=.

line: INTERFACE=255/128/55

, prefix: PRODUCT=.

line: MODALIAS=usb:v1A86pE018d3500dcFFdsc80dp37icFFisc80ip37in00

, prefix: PRODUCT=.

uevent path:/sys/bus/usb/devices/5-0:1.0/uevent 

line: DEVTYPE=usb_interface

, prefix: PRODUCT=.

line: DRIVER=hub

, prefix: PRODUCT=.

line: PRODUCT=1d6b/3/404

, prefix: PRODUCT=.

pid:vid : 1d6b:0003 

line: TYPE=9/0/3

, prefix: PRODUCT=.

line: INTERFACE=9/0/0

, prefix: PRODUCT=.

line: MODALIAS=usb:v1D6Bp0003d0404dc09dsc00dp03ic09isc00ip00in00

, prefix: PRODUCT=.

uevent path:/sys/bus/usb/devices/1-0:1.0/uevent 

line: DEVTYPE=usb_interface

, prefix: PRODUCT=.

line: DRIVER=hub

, prefix: PRODUCT=.

line: PRODUCT=1d6b/2/404

, prefix: PRODUCT=.

pid:vid : 1d6b:0002 

line: TYPE=9/0/1

, prefix: PRODUCT=.

line: INTERFACE=9/0/0

, prefix: PRODUCT=.

line: MODALIAS=usb:v1D6Bp0002d0404dc09dsc00dp01ic09isc00ip00in00

, prefix: PRODUCT=.

uevent path:/sys/bus/usb/devices/2-0:1.0/uevent 

line: DEVTYPE=usb_interface

, prefix: PRODUCT=.

line: DRIVER=hub

, prefix: PRODUCT=.

line: PRODUCT=1d6b/2/404

, prefix: PRODUCT=.

pid:vid : 1d6b:0002 

line: TYPE=9/0/0

, prefix: PRODUCT=.

line: INTERFACE=9/0/0

, prefix: PRODUCT=.

line: MODALIAS=usb:v1D6Bp0002d0404dc09dsc00dp00ic09isc00ip00in00

, prefix: PRODUCT=.



只有登录才能回复,可以选择微信账号登录