1. 解压驱动文件CH38XDRV.tar,并进入驱动目录 cd CH38XDRV/DRV_28S/LINUX/driver$
2. 编译 sudo make
edge@edge-PC:~/CH38XDRV/DRV_28S/LINUX/driver$ sudo make
请输入密码:
验证成功
make -C /lib/modules/4.19.0-arm64-desktop/build M=/home/edge/CH38XDRV/DRV_28S/LINUX/driver modules
make[1]: 进入目录“/usr/src/linux-headers-4.19.0-arm64-desktop”
LD [M] /home/edge/CH38XDRV/DRV_28S/LINUX/driver/wch.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/edge/CH38XDRV/DRV_28S/LINUX/driver/wch.mod.o
LD [M] /home/edge/CH38XDRV/DRV_28S/LINUX/driver/wch.ko
make[1]: 离开目录“/usr/src/linux-headers-4.19.0-arm64-desktop”
顺利的话,生成wch.o文件
3. 加载驱动 sudo insmod wch,ko
并通过ls /dev/ttyWCH*查看相关串口
edge@edge-PC:/scu$ sudo insmod wch.ko
edge@edge-PC:/scu$ ls /dev/ttyWCH*
/dev/ttyWCH0 /dev/ttyWCH10 /dev/ttyWCH12 /dev/ttyWCH14 /dev/ttyWCH16 /dev/ttyWCH18 /dev/ttyWCH2 /dev/ttyWCH4 /dev/ttyWCH6 /dev/ttyWCH8
/dev/ttyWCH1 /dev/ttyWCH11 /dev/ttyWCH13 /dev/ttyWCH15 /dev/ttyWCH17 /dev/ttyWCH19 /dev/ttyWCH3 /dev/ttyWCH5 /dev/ttyWCH7 /dev/ttyWCH9
edge@edge-PC:/scu$
可以看到如下20个串口,则加载成功
4. 添加自启动,我这里是通过添加服务完成系统启动自动加载串口驱动。相关文件放到/scu目录,并在主服务中添加scud.service,名字自定义,这个文件放在/etcsystemd/system目录下绿色。在scud.service运行startup.sh,在startup.sh执行硬件需要加载的所有东西,包括加载串口驱动。
5. scud.service内容
edge@edge-PC:/scu$ cat scud.service
[Unit]
Description=SCU server
[Service]
ExecStart=/scu/startup.sh
[Install]
WantedBy=default.target
6. startup.sh内容
edge@edge-PC:/scu$ cat startup.sh
sh /scu/uartmap.sh
insmod /scu/wch.ko
#sh /scu/com_test.sh
7. uartmap.sh用于串口映射到外部的硬件接口,以便名称一致。(注:需根据不同的硬件,指定不同的映射,也可以不映射,在APP端映射亦可)
edge@edge-PC:/scu$ cat uartmap.sh
ln -s /dev/ttyS0 /dev/ttyCOM9
ln -s /dev/ttyS1 /dev/ttyCOM10
ln -s /dev/ttyWCH0 /dev/ttyCOM11
ln -s /dev/ttyWCH1 /dev/ttyCOM12
ln -s /dev/ttyWCH2 /dev/ttyCOM13
ln -s /dev/ttyWCH3 /dev/ttyCOM14
ln -s /dev/ttyWCH4 /dev/ttyCOM15
ln -s /dev/ttyWCH5 /dev/ttyCOM16
ln -s /dev/ttyWCH6 /dev/ttyCOM1
ln -s /dev/ttyWCH7 /dev/ttyCOM2
ln -s /dev/ttyWCH8 /dev/ttyCOM3
ln -s /dev/ttyWCH9 /dev/ttyCOM4
ln -s /dev/ttyWCH10 /dev/ttyCOM5
ln -s /dev/ttyWCH11 /dev/ttyCOM6
ln -s /dev/ttyWCH12 /dev/ttyCOM7
ln -s /dev/ttyWCH13 /dev/ttyCOM8
ln -s /dev/ttyWCH14 /dev/ttyCOM17
ln -s /dev/ttyWCH15 /dev/ttyCOM18
ln -s /dev/ttyWCH16 /dev/ttyCOM19
ln -s /dev/ttyWCH17 /dev/ttyCOM20
ln -s /dev/ttyWCH18 /dev/ttyCOM21
ln -s /dev/ttyWCH19 /dev/ttyCOM22
8、 完成结果
1)黄色部分,主板自带串口,2个
2)绿色部分,串口卡扩展串口,20个
3)映射到外部的串口,22个
完成
2024/9/18
注意:仅适用4.xx及以下内核,在5.15以上内核发现抱错。待更新驱动源码