T31开发笔记:EC200T-CN 4G模块调试

若该文为原创文章,转载请注明原文出处 

一、硬件和开发环境

1、硬件:T31X+SC5235 + EC200T-CN

2、开发环境: ubuntu16.04-64bit

3、编译器:mips-gcc540-glibc222-32bit-r3.3.0.tar.gz

注:板子和4G模块某淘上淘的,uboot和内核是自己裁剪移植的,没有移植wifi,所以USB接口未使用; EC200T-CN使用的是USB接口,电源外供5V,注意4G模块电源。

二、内核文件修改、配置及编译

1、内核中需要修改的代码

主要修改下面四个文件的代码:

drivers/net/usb/qmi_wwan.c

drivers/usb/serial/option.c

drivers/usb/serial/qcserial.c

drivers/usb/serial/usb_wwan.c

A、  修改drivers/net/usb/qmi_wwan.c代码:

diff --git a/drivers/net/usb/qmi_wwan.c b/drivers/net/usb/qmi_wwan.c
index 5645921..f8f0020 100644
--- a/drivers/net/usb/qmi_wwan.c
+++ b/drivers/net/usb/qmi_wwan.c
@@ -614,7 +614,7 @@ static const struct usb_device_id products[] = {
{QMI_GOBI_DEVICE(0x05c6, 0x9225)}, /* Sony Gobi 2000 Modemdevice (N0279, VU730) */
{QMI_GOBI_DEVICE(0x05c6, 0x9245)}, /* Samsung Gobi 2000 Modemdevice (VL176) */
{QMI_GOBI_DEVICE(0x03f0, 0x251d)}, /* HP Gobi 2000 Modemdevice (VP412) */
- {QMI_GOBI_DEVICE(0x05c6, 0x9215)}, /* Acer Gobi 2000 Modemdevice (VP413) */
+// {QMI_GOBI_DEVICE(0x05c6, 0x9215)}, /* Acer Gobi 2000 Modemdevice (VP413) */
{QMI_GOBI_DEVICE(0x05c6, 0x9265)}, /* Asus Gobi 2000 Modemdevice (VR305) */
{QMI_GOBI_DEVICE(0x05c6, 0x9235)}, /* Top Global Gobi 2000Modem device (VR306) */
{QMI_GOBI_DEVICE(0x05c6, 0x9275)}, /* iRex Technologies Gobi2000 Modem device (VR307) *}

B、 drivers/usb/serial/option.c

--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -530,6 +530,22 @@ static const struct option_blacklist_info
telit_le920_blacklist = {
};
static const struct usb_device_id option_ids[] = {
+#if 1 //Added by Quectel
+ { USB_DEVICE(0x05C6, 0x9090) }, /* Quectel UC15 */
+ { USB_DEVICE(0x05C6, 0x9003) }, /* Quectel UC20 */
+ { USB_DEVICE(0x2C7C, 0x0125) }, /* Quectel EC25 */
+ { USB_DEVICE(0x2C7C, 0x0121) }, /* Quectel EC21 */
+ { USB_DEVICE(0x05C6, 0x9215) }, /* Quectel EC20 */
+ { USB_DEVICE(0x2C7C, 0x0191) }, /* Quectel EG91 */
+ { USB_DEVICE(0x2C7C, 0x0195) }, /* Quectel EG95 */
+ { USB_DEVICE(0x2C7C, 0x0306) }, /* Quectel EG06/EP06/EM06 */
+ { USB_DEVICE(0x2C7C, 0x0296) }, /* Quectel BG96 */
+ { USB_DEVICE(0x2C7C, 0x0435) }, /* Quectel AG35 */
+ { USB_DEVICE(0x2C7C, 0x0512) }, /* Quectel EG12/EG18 */
+ { USB_DEVICE(0x2C7C, 0x6026) }, /* Quectel EC200 */
+ { USB_DEVICE(0x2C7C, 0x6120) }, /* Quectel UC200 */
+ { USB_DEVICE(0x2C7C, 0x6000) }, /* Quectel EC200/UC200 */
+#endif
{ USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COLT) },
{ USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA) },
{ USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA_LIGHT) },
@@ -1377,6 +1393,9 @@ static struct usb_serial_driver
option_1port_device = {
#ifdef CONFIG_PM
.suspend = usb_wwan_suspend,
.resume = usb_wwan_resume,
+#if 1 //add by Quectel
+ .reset_resume = usb_wwan_resume,
+#endif
#endif
};
@@ -1421,6 +1440,27 @@ static int option_probe(struct usb_serial
*serial,
&serial->interface->cur_altsetting->desc;
struct usb_device_descriptor *dev_desc =
&serial->dev->descriptor;
+#if 1 //Added by Quectel
+ //Quectel UC20's interface 4 can be used as USB Network device
+ 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;
+ //Quectel EC20's interface 4 can be used as USB Network device
+ 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;
+ if (serial->dev->descriptor.idVendor == cpu_to_le16(0x2C7C)) {
+ __u16 idProduct =
le16_to_cpu(serial->dev->descriptor.idProduct);
+
+ //Quectel EC200&UC200's interface 0 can be used as USB
Network device (ecm, rndis)
+ if
(serial->interface->cur_altsetting->desc.bInterfaceClass != 0xFF)
+ return -ENODEV;
+ //Quectel
EC25&EC21&EG91&EG95&EG06&EP06&EM06&BG96&AG35&EG12&EG18's interface 4 can be
used as USB network device (qmi,ecm,mbim)
+ if ((idProduct != 0x6026 && idProduct != 0x6126) &&
serial->interface->cur_altsetting->desc.bInterfaceNumber >= 4)
+ return -ENODEV;
+ }
+#endif
+
/* Never bind to the CD-Rom emulation interface */
if (iface_desc->bInterfaceClass == 0x08)
return -ENODEV;

C、 drivers/usb/serial/qcserial.c 
 

--- a/drivers/usb/serial/qcserial.c
+++ b/drivers/usb/serial/qcserial.c
@@ -53,7 +53,7 @@ static const struct usb_device_id id_table[] = {
{DEVICE_G1K(0x05c6, 0x9202)}, /* Generic Gobi Modem device */
{DEVICE_G1K(0x05c6, 0x9203)}, /* Generic Gobi Modem device */
{DEVICE_G1K(0x05c6, 0x9222)}, /* Generic Gobi Modem device */
- {DEVICE_G1K(0x05c6, 0x9008)}, /* Generic Gobi QDL device */
+// {DEVICE_G1K(0x05c6, 0x9008)}, /* Generic Gobi QDL device */
{DEVICE_G1K(0x05c6, 0x9009)}, /* Generic Gobi Modem device */
{DEVICE_G1K(0x05c6, 0x9201)}, /* Generic Gobi QDL device */
{DEVICE_G1K(0x05c6, 0x9221)}, /* Generic Gobi QDL device */

D、 drivers/usb/serial/usb_wwan.c
 

--- a/drivers/usb/serial/usb_wwan.c
+++ b/drivers/usb/serial/usb_wwan.c
@@ -456,8 +456,22 @@ static struct urb *usb_wwan_setup_urb(struct
usb_serial_port *port,
/* Fill URB using supplied data. */
usb_fill_bulk_urb(urb, serial->dev,
- usb_sndbulkpipe(serial->dev, endpoint) | dir,
- buf, len, callback, ctx);
+ usb_sndbulkpipe(serial->dev, endpoint) | dir,
+ buf, len, callback, ctx);
+
+#if 1 //Added by Quectel for Zero Packet
+ 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))
+ urb->transfer_flags |= URB_ZERO_PACKET;
+ if (desc->idVendor == cpu_to_le16(0x05C6) &&
desc->idProduct == cpu_to_le16(0x9003))
+ urb->transfer_flags |= URB_ZERO_PACKET;
+ if (desc->idVendor == cpu_to_le16(0x05C6) &&
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;
+ }
+#endif
return urb;
}

2、内核配置

在终端执行 make menuconfig, 开始配置内核:

A、 配置 ppp

配置路径如下:
Device Drivers ---> Network device support --->
PPP (point-to-point protocol) support
PPP BSD-Compress compression
PPP Deflate compression PPP filtering
PPP MPPE compression (encryption) PPP multilink support
PPP over Ethernet
PPP support for async serial ports
PPP support for sync tty ports

T31开发笔记:EC200T-CN 4G模块调试_第1张图片

B、配置支持USBNET 

配置路径如下:
Device Drivers ---> Network device support --->
USB Network Adapters --->
Multi-purpose USB Networking Framework

C、使能 USB 串口 GSM、CDMA 驱动

配置路径如下:
Device Drivers ---> USB support --->
USB Serial Converter support --->
USB driver for GSM and CDMA modems

T31开发笔记:EC200T-CN 4G模块调试_第2张图片

 配置完成后,重新编译内核,然后使用新的内核启动开发板。如果配置成功开发板启动后会有如下信息打印:

T31开发笔记:EC200T-CN 4G模块调试_第3张图片

 三、PPP  软件包编译

A、ppp-2.4.4.tar.gz编译

1、拷贝 ppp-2.4.4.tar.gz 到 Ubuntu 下,然后执行下面的命令解压:
tar -xvf ppp-2.4.4.tar.gz
解压完成得到 ppp-2.4.4 目录,进入 ppp-2.4.4 目录如图 所示:

2、使用 configure 进行配置,命令如下:
./configure
结果如图 所示:

T31开发笔记:EC200T-CN 4G模块调试_第4张图片


配置完成后,使用下面的命令进行编译:
make CC=mips-linux-gnu-gcc
“CC=mips-linux-gnu”指定编译器,和开发板内核使用同一个编译器。

编译完成后,分别在 chat、pppd、pppdump、pppstats 四个目录下生成 chat、pppd、pppdump、pppstats可执行文件。

把可执行文件全部拷贝到开发板的bin目录 下。

B、自动ppp拨号

使用文件为linux-ppp-scripts_v1.2.zip,解压后获取的文件如下:

T31开发笔记:EC200T-CN 4G模块调试_第5张图片

在开发板下新建/etc/ppp/peers目录:        

拷贝 quectel-chat-connect、quectel-chat-disconnect、quectel-ppp、quectel-ppp-kill 到 /etc/ppp/peers 目录下。
拷贝ip-up文到/etc/ppp目录下,请确保该文件在你的系统里有可执行权限。

修改串口:

需要修改串口,修改文件 quectel-ppp 里的串口,默认文件是ttyUSB3,修改成ttyUSB2

其他文件未修改,linux-ppp-scripts_v1.2.zip文件是购买EC200T-CN模块厂家给的驱动,网上可自行下载。

C、拨号测试:

启动 ppp 拨号:
quectel-pppd.sh &

输出信息跟方案一输出一样,同样会生成/etc/ppp/resolv.conf文件,并获得IP地址:

T31开发笔记:EC200T-CN 4G模块调试_第6张图片

D、挂断拨号

quectel-ppp-kill 用来挂断拨号的,pppd必须被正常的挂断,否则可能会导致你下次ppp拨号失败。

使用下面方式来调用这个脚本

./quectel-ppp-kill 

注:
在进行拨号之前一定要确保没有默认网关,如果已经设置了其他网卡的默认网关了,则4G模块没法正常上网,需要删除原来的默认网关,现以网卡eth0为例:

route del default
route del -host 255.255.255.255 dev eth0

如果去掉默认网关,可以直接ping www.baidu.com

四、上电自启动ppp拨号上网

在/etc目录下新建ec200t.sh
内容如下:

ls /dev/ |grep ttyUSB
if [ "$?" == "0" ]; then
        echo "4g init ..."
        cd /etc/ppp/peers/
        pppd call quectel-ppp &
fi

修改ec200t.sh权限 

chmod +x ec200t.sh

修改/etc/init.d/rcS,增加上电就自启动ppp拨号上网:

./etc/ec200t.sh

五、结束:

移植过程还算顺利,在测试的时候卡没有放对,插反了,在此感谢模块厂家,也感谢网友。

移植所使用的文件及测试下载地址:君正T31EC200T-CN调试-Linux文档类资源-CSDN下载

主要参考的博文:

Linux下EC20实现ppp拨号_Ahren.zhao的博客-CSDN博客_ppp拨号

如何使用4G模块实现上网功能 - 嵌入式学习小组 - 电子技术论坛 - 广受欢迎的专业电子论坛!

如有侵权,请及时联系博主删除,VX:18750903063

你可能感兴趣的:(君正T31,arm,物联网,嵌入式硬件)