s5pv210-Linux驱动之ME3760

  • Post author:
  • Post category:linux

一、开发环境

硬件平台:我用的是TQ210核心板,板载S5PV210芯片
软件平台:开发板移植的是Linux3.10.46内核,UBOOT移植的是2014.12版本

二、资源简介

    ME3760 是一款Mini PCI-E接口的LTE 模块,支持LTE TDD band38(2.6GHz),band39(1.9GHz),band40(2.3GHz); LTE FDD band7(2.6GHz),向下兼容TD-SCDMA A频段(2.1GHz)和F频段(1.9GHz)以及GSM900MHz,GSM1800MHz. 支持最大100M/50Mbps的理论上下行数据传输速率.

    ME3760 模块的官方驱动可以在网上找,我也会上传到资源里。

三、移植步骤

(一)添加usb转串口驱动

1、配置内核

/linux-3.10.46$ make menuconfig
<*>   USB driver for GSM and CDMA modems 
Symbol: USB_SERIAL_OPTION [=y]
Type  : tristate
Prompt: USB driver for GSM and CDMA modems
  Location:
    -> Device Drivers
      -> USB support (USB_SUPPORT [=y])
        -> USB Serial Converter support (USB_SERIAL [=y])

2、添加设备信息

修改linux-3.10.46\drivers\usb\serial\option.c,在option_ids中添加一行,如下:

static const struct usb_device_id option_ids[] = {
	{ USB_DEVICE(0x19d2, 0x0199) },				/* add by wzs */
	{ USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_COLT) },
	{ USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_RICOLA) },

3、usb串口驱动过滤EMC接口

修改\linux-3.10.46\drivers\usb\serial\usb-serial.c文件,在usb_serial_probe函数中添加如下几行:

	int num_ports = 0;
	int max_endpoints;

	mutex_lock(&table_lock);
	
	/* add by wzs start */
	if ((le16_to_cpu(dev->descriptor.idVendor)== 0x19d2)&&
        (le16_to_cpu(dev->descriptor.idProduct)== 0x0199)){
        if(1 ==interface->cur_altsetting->desc.bInterfaceNumber){
               return -ENODEV;
        }
	}
	/* add by wzs end */
	
	type = search_serial_device(interface);
	if (!type) {
		mutex_unlock(&table_lock);
		dev_dbg(ddev, "none matched\n");
		return -ENODEV;
	}

(二)添加Ndis驱动

1、配置内核

/linux-3.10.46$ make menuconfig
<M> Multi-purpose USB Networking Framework
Symbol: USB_USBNET [=m]
Type  : tristate
Prompt: Multi-purpose USB Networking Framework
  Location:
    -> Device Drivers
      -> Network device support (NETDEVICES [=y])
        -> USB Network Adapters

2、复制源码

把官方驱动包里的cdc_ether.c cdc_encap_ok.c cdc_encap_ok.h三个文件复制到内核\linux-3.10.46\drivers\net\usb目录下

3、修改\linux-3.10.46\drivers\net\usb\Makefile文件,添加一行:

obj-m   += cdc_encap.o

3、修改cdc_ether.c 文件

461行:
netif_info(dev,  "link speeds: %u kbps up, %u kbps down",
改成
netif_info(dev, timer, dev->net, "link speeds: %u kbps up, %u kbps down",

483行:
devdbg(dev, "CDC: carrier %s",
改成
netif_dbg(dev, timer, dev->net, "CDC: carrier %s",

492行:
devdbg(dev, "CDC: speed change (len %d)",
改成
netif_dbg(dev, timer, dev->net, "CDC: speed change (len %d)",

518行:
deverr(dev, "CDC: unexpected notification %02x!",
改成
netdev_err(dev->net, "CDC: unexpected notification %02x!",

717行:
devdbg (dev, "no rx skb");
改成
netif_dbg(dev, timer, dev->net, "no rx skb");

4、修改cdc_encap_ok.c文件

添加头文件

#include <linux/slab.h>

238行:
.ioctl =           cdc_encap_ioctl,
改成
.compat_ioctl  =           cdc_encap_ioctl,

263行:
init_MUTEX(&encap->sem);
改成
sema_init(&encap->sem, 1);

5、编译内核和模块

/linux-3.10.46$ make uImage
/linux-3.10.46$ make modules

6、加载模块

把drivers/net/usb/usbnet.ko cdc_encap.ko cdc_ether.ko三个模块复制到开发板上,然后按顺序加载,如下:

[root@$zjh: 35th_4g]# insmod usbnet.ko 
[root@$zjh: 35th_4g]# insmod cdc_encap.ko 
[root@$zjh: 35th_4g]# insmod cdc_ether.ko 

注:卸载时要按照相反的顺序

如果ME3760模块已经插在开发板上了,则会打印如下信息:

cdc_ether 1-1.3:1.1: ZTE Ethernet Device: claiming interface 1
usb 1-1.3: bad CDC descriptors
cdc_ether 1-1.3:1.1 eth1: register 'cdc_ether' at usb-s5p-ohci-1.3, ZTE Ethernet Device, c6:8e:08:92:10:a9
usbcore: registered new interface driver cdc_ether

7、检查驱动

把ME3760模块插入开发板,执行如下命令:

[root@$zjh: 35th_4g]# lsusb 
Bus 001 Device 002: ID 1a40:0101
Bus 001 Device 001: ID 1d6b:0001
Bus 001 Device 005: ID 19d2:0199
[root@$zjh: 35th_4g]# ll /dev/ttyUSB*
crw-rw----    1 root     root      188,   0 Jan  1 05:47 /dev/ttyUSB0
crw-rw----    1 root     root      188,   1 Jan  1 05:48 /dev/ttyUSB1
crw-rw----    1 root     root      188,   2 Jan  1 01:33 /dev/ttyUSB2
[root@$zjh: 35th_4g]# ifconfig -a
eth0      Link encap:Ethernet  HWaddr 00:09:C0:FF:EC:48  
          inet addr:192.168.1.4  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:10881 errors:0 dropped:133 overruns:0 frame:0
          TX packets:758 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:2123172 (2.0 MiB)  TX bytes:72340 (70.6 KiB)
          Interrupt:42 Base address:0x8000 

eth1      Link encap:Ethernet  HWaddr C6:8E:08:92:10:A9  
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback  
          LOOPBACK  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

[root@$zjh: 35th_4g]# 

如果命令返回信息是以上这样,表示ME3760模块已经驱动成功了

其中,eth1是ME3760模块的网络名


(三)测试

microcom是在制作根文件系统时busybox里自带命令。s指定波特率为115200,也可以在前面加 -t  7000(表示监听的时间为7000ms), 通过ctrl+x可以退出监听

使用串口工具向ME3760模块发送AT命令:

[root@$zjh: 35th_4g]# microcom -s 115200 /dev/ttyUSB0

发送AT,返回OK

发送AT+CSCS=?,返回+CSCS: (“GSM”,”HEX”,”UCS2″)

则表示ME3760模块已经可以正常工作了。

(四)ME3760联网应用

1、获取IP地址

[root@$zjh: 35th_4g]# microcom -s 115200 /dev/ttyUSB0

发送AT,返回OK

发送AT+CFUN=1,返回

+CREG: 2
^MODE: 0
+CEREG: 2
+CEREG: 1
^MODE: 17,9
+CREG: 1

发送
AT+CEREG=1,返回OK

发送AT+CGREG? ,返回

+CGREG: 1,2

OK

发送AT+CEREG?,返回

+CEREG: 1,1
OK

发送,返回OK

发送AT+CGPADDR=1,返回

+CGPADDR: 1,”10.190.250.228″
OK

2、设置IP地址

[root@$zjh: 35th_4g]# ifconfig eth1 up
[root@$zjh: 35th_4g]# ifconfig eth1 10.190.250.228

3、设置网关

[root@$zjh: 35th_4g]# route add default gw 10.0.0.1

4、设置DNS

把文件/etc/resolv.conf内容改成如下:

nameserver 8.8.8.8

5、PING外网

[root@$zjh: 35th_4g]# ping 61.135.169.121
PING 61.135.169.121 (61.135.169.121): 56 data bytes
64 bytes from 61.135.169.121: seq=0 ttl=50 time=836.940 ms
64 bytes from 61.135.169.121: seq=1 ttl=50 time=35.580 ms
64 bytes from 61.135.169.121: seq=2 ttl=50 time=69.405 ms
^C
--- 61.135.169.121 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 35.580/313.975/836.940 ms
[root@$zjh: 35th_4g]# 
[root@$zjh: 35th_4g]# 
[root@$zjh: 35th_4g]# ping www.baidu.com
PING www.baidu.com (14.215.177.39): 56 data bytes
64 bytes from 14.215.177.39: seq=0 ttl=48 time=98.806 ms
64 bytes from 14.215.177.39: seq=1 ttl=48 time=98.513 ms
64 bytes from 14.215.177.39: seq=2 ttl=48 time=96.318 ms
^C
--- www.baidu.com ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 96.318/97.879/98.806 ms

四、小结

    官方提供的驱动包比较老,是Linux2.6内核的,如果你使用的内核版本比较新,可能还需要做其它修改。

官方驱动下载:http://download.csdn.net/download/wzs250969969/10155482



版权声明:本文为wzs250969969原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。