第二篇 4G模块-USB串口驱动测试
linux-dash
A beautiful web dashboard for Linux
项目地址:https://gitcode.com/gh_mirrors/li/linux-dash
免费下载资源
·
一、编译内核
在linux内核里边修改了对华为ME909S-821的支持,使用make uImage编译,然后下载到开发板上:上电开机,在系统启动过程会打印相关usb串口驱动的信息,但是,我们也可以使用dmesg随时查看,相关信息如下:
usb 1-1: new full-speed USB device number 2 using s3c2410-ohci
cdc_ether 1-1:2.0: usb0: register 'cdc_ether' at usb-s3c24xx-1, CDC Ethernet Device, 02:1e:10:1f:00:00
option 1-1:2.2: GSM modem (1-port) converter detected
usb 1-1: GSM modem (1-port) converter now attached to ttyUSB0
option 1-1:2.3: GSM modem (1-port) converter detected
usb 1-1: GSM modem (1-port) converter now attached to ttyUSB1
option 1-1:2.4: GSM modem (1-port) converter detected
usb 1-1: GSM modem (1-port) converter now attached to ttyUSB2
option 1-1:2.5: GSM modem (1-port) converter detected
usb 1-1: GSM modem (1-port) converter now attached to ttyUSB3
option 1-1:2.6: GSM modem (1-port) converter detected
usb 1-1: GSM modem (1-port) converter now attached to ttyUSB4
option: option_instat_callback: error -2
最后出现错误: option_instat_callback error -2,尽管这个错误,目前还无法判断具体原因,开始测试在嵌入式开发板上打电话的功能(也就这个功能尤为吸引我)。
在这里我们要使用一个软件在ubuntu上,查看这个4G模块的信息,比如配置描述符、接口描述符、还有端点描述符等等,拥有这种功能的USB软件肯定有,幸运的是在内核大牛的网站看到这个
usbview软件,下载网址:
点击打开链接(
感谢Greg K-H大牛)
下载代码,解压,可参考
INSTALL文件编译安装usbview软件。
最后查看这个4G模块的信息如下:
Config Number: 1
Number of Interfaces: 6
Attributes: a0
MaxPower Needed: 2mA
Interface Number: 0
Name:
Alternate Number: 0
Class: ff(vend.)
Sub Class: 06
Protocol: 10
Number of Endpoints: 3
Endpoint Address: 82
Direction: in
Attribute: 3
Type: Int.
Max Packet Size: 10
Interval: 32ms
Endpoint Address: 81
Direction: in
Attribute: 2
Type: Bulk
Max Packet Size: 512
Interval: 0ms
Endpoint Address: 01
Direction: out
Attribute: 2
Type: Bulk
Max Packet Size: 512
Interval: 0ms
Interface Number: 1
Name:
Alternate Number: 0
Class: ff(vend.)
Sub Class: 06
Protocol: 13
Number of Endpoints: 2
Endpoint Address: 83
Direction: in
Attribute: 2
Type: Bulk
Max Packet Size: 512
Interval: 0ms
Endpoint Address: 02
Direction: out
Attribute: 2
Type: Bulk
Max Packet Size: 512
Interval: 0ms
Interface Number: 2
Name:
Alternate Number: 0
Class: ff(vend.)
Sub Class: 06
Protocol: 12
Number of Endpoints: 2
Endpoint Address: 84
Direction: in
Attribute: 2
Type: Bulk
Max Packet Size: 512
Interval: 0ms
Endpoint Address: 03
Direction: out
Attribute: 2
Type: Bulk
Max Packet Size: 512
Interval: 0ms
Interface Number: 3
Name:
Alternate Number: 0
Class: ff(vend.)
Sub Class: 06
Protocol: 16
Number of Endpoints: 1
Endpoint Address: 86
Direction: in
Attribute: 3
Type: Int.
Max Packet Size: 16
Interval: 2ms
Interface Number: 3
Name:
Alternate Number: 1
Class: ff(vend.)
Sub Class: 06
Protocol: 16
Number of Endpoints: 3
Endpoint Address: 86
Direction: in
Attribute: 3
Type: Int.
Max Packet Size: 16
Interval: 2ms
Endpoint Address: 85
Direction: in
Attribute: 2
Type: Bulk
Max Packet Size: 512
Interval: 0ms
Endpoint Address: 04
Direction: out
Attribute: 2
Type: Bulk
Max Packet Size: 512
Interval: 0ms
Interface Number: 4
Name:
Alternate Number: 0
Class: ff(vend.)
Sub Class: 06
Protocol: 06
Number of Endpoints: 2
Endpoint Address: 87
Direction: in
Attribute: 2
Type: Bulk
Max Packet Size: 512
Interval: 0ms
Endpoint Address: 05
Direction: out
Attribute: 2
Type: Bulk
Max Packet Size: 512
Interval: 0ms
Interface Number: 5
Name:
Alternate Number: 0
Class: ff(vend.)
Sub Class: 06
Protocol: 1b
Number of Endpoints: 2
Endpoint Address: 88
Direction: in
Attribute: 2
Type: Bulk
Max Packet Size: 512
Interval: 0ms
Endpoint Address: 06
Direction: out
Attribute: 2
Type: Bulk
Max Packet Size: 512
Interval: 0ms
Config Number: 2 //实际使用的配置
Number of Interfaces: 7
Attributes: a0
MaxPower Needed: 2mA
Interface Number: 0
Name:cdc_ether
Alternate Number: 0
Class: 02(comm.)
Sub Class: 06
Protocol: 00
Number of Endpoints: 1
Endpoint Address: 82
Direction: in
Attribute: 3
Type: Int.
Max Packet Size: 16
Interval: 2ms
Interface Number: 1
Name: cdc_ether
Alternate Number: 0
Class: 0a(data )
Sub Class: 06
Protocol: 00
Number of Endpoints: 2
Endpoint Address: 81
Direction: in
Attribute: 2
Type: Bulk
Max Packet Size: 512
Interval: 0ms
Endpoint Address: 01
Direction: out
Attribute: 2
Type: Bulk
Max Packet Size: 512
Interval: 0ms
Interface Number: 2
Name: option
Alternate Number: 0
Class: ff(vend.)
Sub Class: 06
Protocol: 10
Number of Endpoints: 3
Endpoint Address: 84
Direction: in
Attribute: 3
Type: Int.
Max Packet Size: 10
Interval: 32ms
Endpoint Address: 83
Direction: in
Attribute: 2
Type: Bulk
Max Packet Size: 512
Interval: 0ms
Endpoint Address: 02
Direction: out
Attribute: 2
Type: Bulk
Max Packet Size: 512
Interval: 0ms
Interface Number: 3
Name: option
Alternate Number: 0
Class: ff(vend.)
Sub Class: 06
Protocol: 13
Number of Endpoints: 2
Endpoint Address: 85
Direction: in
Attribute: 2
Type: Bulk
Max Packet Size: 512
Interval: 0ms
Endpoint Address: 03
Direction: out
Attribute: 2
Type: Bulk
Max Packet Size: 512
Interval: 0ms
Interface Number: 4
Name: option
Alternate Number: 0
Class: ff(vend.)
Sub Class: 06
Protocol: 12
Number of Endpoints: 2
Endpoint Address: 86
Direction: in
Attribute: 2
Type: Bulk
Max Packet Size: 512
Interval: 0ms
Endpoint Address: 04
Direction: out
Attribute: 2
Type: Bulk
Max Packet Size: 512
Interval: 0ms
Interface Number: 5
Name: option
Alternate Number: 0
Class: ff(vend.)
Sub Class: 06
Protocol: 06
Number of Endpoints: 2
Endpoint Address: 87
Direction: in
Attribute: 2
Type: Bulk
Max Packet Size: 512
Interval: 0ms
Endpoint Address: 05
Direction: out
Attribute: 2
Type: Bulk
Max Packet Size: 512
Interval: 0ms
Interface Number: 6
Name: option
Alternate Number: 0
Class: ff(vend.)
Sub Class: 06
Protocol: 1b
Number of Endpoints: 2
Endpoint Address: 88
Direction: in
Attribute: 2
Type: Bulk
Max Packet Size: 512
Interval: 0ms
Endpoint Address: 06
Direction: out
Attribute: 2
Type: Bulk
Max Packet Size: 512
Interval: 0ms
Config Number: 3
Number of Interfaces: 2
Attributes: a0
MaxPower Needed: 2mA
Interface Number: 0
Name:
Alternate Number: 0
Class: 02(comm.)
Sub Class: 0e
Protocol: 00
Number of Endpoints: 1
Endpoint Address: 82
Direction: in
Attribute: 3
Type: Int.
Max Packet Size: 16
Interval: 2ms
Interface Number: 1
Name:
Alternate Number: 0
Class: 0a(data )
Sub Class: 00
Protocol: 02
Number of Endpoints: 0
Interface Number: 1
Name:
Alternate Number: 1
Class: 0a(data )
Sub Class: 00
Protocol: 02
Number of Endpoints: 2
Endpoint Address: 81
Direction: in
Attribute: 2
Type: Bulk
Max Packet Size: 512
Interval: 0ms
Endpoint Address: 01
Direction: out
Attribute: 2
Type: Bulk
Max Packet Size: 512
Interval: 0ms
以上就是使用usbview软件查看的USB设备信息,这里对应这个ttyUSB0-ttyUSB4理解:
cdc_ether 1-1:2.0: usb0: register 'cdc_ether' at usb-s3c24xx-1, CDC Ethernet Device, 02:1e:10:1f:00:00
option 1-1:2.2: GSM modem (1-port) converter detected
usb 1-1: GSM modem (1-port) converter now attached to ttyUSB0
option 1-1:2.3: GSM modem (1-port) converter detected
usb 1-1: GSM modem (1-port) converter now attached to ttyUSB1
option 1-1:2.4: GSM modem (1-port) converter detected
usb 1-1: GSM modem (1-port) converter now attached to ttyUSB2
option 1-1:2.5: GSM modem (1-port) converter detected
usb 1-1: GSM modem (1-port) converter now attached to ttyUSB3
option 1-1:2.6: GSM modem (1-port) converter detected
usb 1-1: GSM modem (1-port) converter now attached to ttyUSB4
目前还没有拿到证据,但在观看这里的1-1.2.0到最后的1-1.2.6,估计2代表使用的配置2,就是上面的Config Number为2的配置描述符,后边的数字从0、2、3、4、5、6代表了上边的接口描述符,可以从接口描述符名字观察到,其中配置描述符2的接口描述符1没有使用上。
二、关于option_instat_callback error -2的原因
【1】函数内容:
static void option_instat_callback(struct urb *urb)
{
int err;
int status = urb->status;
struct usb_serial_port *port = urb->context;
struct option_port_private *portdata = usb_get_serial_port_data(port);
dbg("%s", __func__);
dbg("%s: urb %p port %p has data %p", __func__, urb, port, portdata);
if (status == 0) {
struct usb_ctrlrequest *req_pkt =
(struct usb_ctrlrequest *)urb->transfer_buffer;
if (!req_pkt) {
dbg("%s: NULL req_pkt", __func__);
return;
}
if ((req_pkt->bRequestType == 0xA1) &&
(req_pkt->bRequest == 0x20)) {
int old_dcd_state;
unsigned char signals = *((unsigned char *)
urb->transfer_buffer +
sizeof(struct usb_ctrlrequest));
dbg("%s: signal x%x", __func__, signals);
old_dcd_state = portdata->dcd_state;
portdata->cts_state = 1;
portdata->dcd_state = ((signals & 0x01) ? 1 : 0);
portdata->dsr_state = ((signals & 0x02) ? 1 : 0);
portdata->ri_state = ((signals & 0x08) ? 1 : 0);
if (old_dcd_state && !portdata->dcd_state) {
struct tty_struct *tty =
tty_port_tty_get(&port->port);
if (tty && !C_CLOCAL(tty))
tty_hangup(tty);
tty_kref_put(tty);
}
} else {
dbg("%s: type %x req %x", __func__,
req_pkt->bRequestType, req_pkt->bRequest);
}
++++++ }else if(status ==-ENOENT || status == -ESHUTDOWN) {
++++++ dbg("%s: urb stopped: %d\n", __func__, status);
}else
err("%s: error %d", __func__, status);
/* Resubmit urb so we continue receiving IRQ data */
if (status != -ESHUTDOWN && status != -ENOENT) {
err = usb_submit_urb(urb, GFP_ATOMIC);
if (err)
dbg("%s: resubmit intr urb failed. (%d)",
__func__, err);
}
}
找了好久,在linux-usb的邮件里边找到了一个人提交的patch,里边描述的问题正好就是option: option_instat_callback: error -2,综合了他的修改,同时在option.c文件前边加上dbg函数:
#ifdef CONFIG_USB_DEBUG
static int mydebug = 5;
#else
static int mydebug = 1;
#endif
/* Use our own dbg macro */
#undef dbg
#define dbg(format, arg...) \
do { \
if(mydebug > 3) \
printk(KERN_DEBUG "%s: " format "\n", __FILE__, ##arg); \
} while (0)
GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e
added ecosystem file for PM2 4 年前
5def40a3
Add host customization support for the NodeJS version 4 年前
更多推荐
已为社区贡献2条内容
所有评论(0)