匠芯创 D213ECX Luban SDK 适配移远 EC20 4G 模块完整指南
一、引言
-
内核驱动配置
-
USB 串口驱动修改(解决接口冲突)
-
QMI 网络驱动优化
-
PPP 拨号工具集成
二、硬件准备
-
开发板:D213(Luban SDK)
-
4G 模块:移远 EC20(或 EC20 R2.0 / EC21 / UC20 等)
-
连接方式:EC20 通过 USB 接口连接到开发板(通常使用 USB 端口或 Mini PCIe 转 USB 电路)
-
SIM 卡:已激活且 APN 正确的 4G SIM 卡
-
天线:连接主天线和分集天线(GNSS 可选)
三、软件适配概述
-
内核配置:开启 PPP、USB 网络、USB 串口等必要选项。
-
内核驱动修改:修改 option.c、qcserial.c、qmi_wwan.c 等文件,使内核能正确识别 EC20 的多个接口,并避开冲突。
-
用户空间工具:在 Buildroot 中添加 pppd 拨号工具。
四、详细修改步骤
1. 内核配置修改
make kernel-menuconfig(或者make km)中添加以下配置,启用 PPP 协议、USB 网络及 USB 串口支持:
output/d211_demo128_nand/build/linux-5.10/.config
# PPP 协议支持
CONFIG_PPP=y
CONFIG_PPP_BSDCOMP=y
CONFIG_PPP_DEFLATE=y
CONFIG_PPP_FILTER=y
CONFIG_PPP_MPPE=y
CONFIG_PPP_MULTILINK=y
CONFIG_PPPOE=y
CONFIG_PPP_ASYNC=y
CONFIG_PPP_SYNC_TTY=y
# USB 网络驱动(用于 QMI 接口)
CONFIG_USB_USBNET=y
CONFIG_USB_NET_QMI_WWAN=y
# USB 串口驱动(用于 AT 命令及数据通道)
CONFIG_USB_SERIAL=y
CONFIG_USB_SERIAL_QUALCOMM=y
CONFIG_USB_SERIAL_OPTION=y
CONFIG_USB_ACM=y
2. 驱动代码修改
2.1 option.c:添加模块 ID 并跳过网络接口
{ USB_DEVICE(0x05C6, 0x9090) }, // UC15
{ USB_DEVICE(0x05C6, 0x9003) }, // UC20
{ USB_DEVICE(0x05C6, 0x9215) }, // EC20
{ USB_DEVICE(0x2C7C, 0x0125) }, // EC20 R2.0
// ... 原有条目
};
{
// ... 原有代码
// 跳过 UC20 的网络接口
if (serial->dev->descriptor.idVendor == cpu_to_le16(0x05C6) &&
serial->dev->descriptor.idProduct == cpu_to_le16(0x9003) &&
serial->interface->cur_altsetting->desc.bInterfaceNumber >= 4)
return -ENODEV;
// 跳过 EC20 的网络接口
if (serial->dev->descriptor.idVendor == cpu_to_le16(0x05C6) &&
serial->dev->descriptor.idProduct == cpu_to_le16(0x9215) &&
serial->interface->cur_altsetting->desc.bInterfaceNumber >= 4)
return -ENODEV;
// 跳过 EC20 R2.0 / EC21 / EC25 的网络接口
if (serial->dev->descriptor.idVendor == cpu_to_le16(0x2C7C) &&
serial->interface->cur_altsetting->desc.bInterfaceNumber >= 4)
return -ENODEV;
// ... 原有代码
}
2.2 qcserial.c 与 qmi_wwan.c:解决 ID 冲突
-
在 drivers/net/usb/qmi_wwan.c 中:
// { QMI_GOBI_DEVICE(0x05c6, 0x9215) }, // 注释该行
{ QMI_FIXED_INTF(0x05c6, 0x9215, 4) }, // 保留这一行(用于 QMI 网络)
- 在 drivers/usb/serial/qcserial.c 中:
// { USB_DEVICE(0x05c6, 0x9215) }, // 注释该行
2.3 usb_wwan.c 与 cdc-acm.c:添加零包处理
-
在 drivers/usb/serial/usb_wwan.c 的 usb_wwan_setup_urb 函数中:
if (dir == USB_DIR_OUT) {
struct usb_device_descriptor *desc = &serial->dev->descriptor;
if (desc->idVendor == cpu_to_le16(0x05C6) &&
(desc->idProduct == cpu_to_le16(0x9090) ||
desc->idProduct == cpu_to_le16(0x9003) ||
desc->idProduct == cpu_to_le16(0x9215)))
urb->transfer_flags |= URB_ZERO_PACKET;
if (desc->idVendor == cpu_to_le16(0x2C7C))
urb->transfer_flags |= URB_ZERO_PACKET;
}
-
在 drivers/usb/class/cdc-acm.c 中,为特定设备添加相同标志:
if (usb_dev->descriptor.idVendor == 0x1519 &&
usb_dev->descriptor.idProduct == 0x0020)
snd->urb->transfer_flags |= URB_ZERO_PACKET;
2.4 usb-serial.c:支持复位唤醒
udriver->reset_resume = usb_serial_resume;
3. 用户空间工具配置
在 Buildroot 配置中添加 pppd 拨号工具,用于建立 PPP 连接。
BR2_PACKAGE_PPPD=y
BR2_PACKAGE_PPPD_FILTER=y
BR2_PACKAGE_PPPD_RADIUS=y
五、验证与测试
1. 检查 USB 设备识别
ID 05c6:9215
2. 查看串口设备
ls /dev/ttyUSB*
若只有 ttyUSB0 到 ttyUSB3,但缺少网络接口,属正常——因为网络接口已被 QMI 驱动接管。
3. 查看网络接口
ifconfig -a
4. 使用 PPP 拨号
pppd call wcdma&
ping 8.8.8.8
六、常见问题及解决[td]
| 现象 | 可能原因 | 解决方法 |
| lsusb 看不到设备 | USB 供电不足或硬件连接问题 | 检查 USB 线缆、电源,确保模块供电 3.8V~4.2V |
| 出现 ttyUSB0 但无法 AT 通信 | 串口驱动未正确绑定 | 确认 option 驱动是否加载:lsmod | grep option |
| 没有 wwan0 接口 | QMI 驱动未加载或冲突 | 检查 qmi_wwan 是否加载,并确认 dmesg 有无错误 |
| PPP 拨号失败,日志显示 LCP timeout | APN 或用户名/密码错误 | 核对运营商 APN,如中国联通为 3gnet,中国电信为 ctnet |
| 网络卡顿或断流 | USB 零包未开启 | 确认修改的 URB_ZERO_PACKET 是否生效 |
七、总结
附件:[attach]7548[/attach]
更多推荐
所有评论(0)