自制板件调试记录\内核裁剪\usb驱动开发

1.Boot 状态的引脚 被DI\DO 定义管教占用
2.裁剪内核:内核地址映射(/jerbek-3.2/System.map)
1. 内核中去掉rtx-8010.o 驱动 (rtc)
Makefile 中/drivers/real time clock/epson RX-8010 中去掉rtx-8010 驱动
2. 去掉TI81XX onward 驱动 (usb)
make menuconfig 中 device driver /usb support ti81xx onward
3. 去掉 spi .
/device drviers/spi support
4. 去掉声卡支持
/device/sound card support
5. 去掉usb支持
/device/usb support
6. 去掉can 支持
/networking support/CAN bus subsystem support
7. 去掉PWM
/device/PWM support
8. 去掉watchdog timer
/device/watchdog timer support
9. 去掉Multimedia support 支持
/device/multimedia support
10. 去掉ADC 驱动
/device drivers/staging drivers/industrial i/o support/analog to digital converters

利用ok335xs-ii 的内核源码,实现自定义板件的内核裁剪:
cp arch/arm/configs/ok335xs2_evm_linux_usb_defconfig .config
1. 内核中去掉rtx-8010.o 驱动 (rtc)
Makefile 中/drivers/real time clock/epson RX-8010 中去掉rtx-8010 驱动
2. 去掉TI81XX onward 驱动 (usb)
make menuconfig 中 device driver /usb support ti81xx onward
3. 去掉 spi .
/device drviers/spi support
4. 加上modules 加载功能:
Enable loadable module support ——–>>>>
进入选项,加上 modules unload 等其他选项(否则 内核无法卸载驱动)

Usb调试(用开发板)

插上thingmagic模块后,如下提示
/mnt # [ 183.521010] usb 1-1.2: new full-speed USB device number 3 using musb-hdrc
[ 183.642408] usb 1-1.2: New USB device found, idVendor=2008, idProduct=1002
[ 183.649619] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 183.657292] usb 1-1.2: Product: M6E Serial
[ 183.661592] usb 1-1.2: Manufacturer: ThingMagic, Inc.

Lsusb命令: Bus 001 Device 003: ID 2008:1002

插上thingmagic usb 模块: 打印如下信息:

thingmagic_usb_probe find driver!
[ 17.091805] 配置所支持的接口数为1
[ 17.098391] 接口类为2
[ 17.103853] 接口的编号数0
[ 17.109673] 该接口所支持的端点数1
[ 17.113277] 端点1的属性为3
[ 17.116099] 端点2的属性为0
[ 17.118916] 属性=0 控制为01表示同步,为02表示批量,为03表示中断
[ 17.128199] 端点1的中断间隔为10
[ 17.131470] 端点2的中断间隔为0
[ 17.137757] 端点1的地址83
[ 17.140484] 端点2的地址0
[ 17.143129] 端点地址:0~3位是端点号,第7位是方向(0-OUT,1-IN)
[ 17.149121] 端点1的最大包的尺寸is64
[ 17.152764] 端点2的最大包的尺寸is0
[ 17.159400] *******************************
[ 17.164674] *******************************
[ 17.227656] thingmagic_usb_probe find driver!
[ 17.232477] 配置所支持的接口数为1
[ 17.239014] 接口类为10
[ 17.244564] 接口的编号数1
[ 17.250377] 该接口所支持的端点数2
[ 17.253834] 端点1的属性为2
[ 17.256648] 端点2的属性为2
[ 17.259461] 属性=0 控制为01表示同步,为02表示批量,为03表示中断
[ 17.268724] 端点1的中断间隔为0
[ 17.271919] 端点2的中断间隔为0
[ 17.278184] 端点1的地址1
[ 17.280817] 端点2的地址82
[ 17.283550] 端点地址:0~3位是端点号,第7位是方向(0-OUT,1-IN)
[ 17.289534] 端点1的最大包的尺寸is64
[ 17.293172] 端点2的最大包的尺寸is64
Probe 函数调用了两次, 所以

参考 comedi/drivers/dt9812.c
Usb_bulk_msg() 用于批量传输的端点收发
usb_int_msg() 用于中断端点的收发

返回值 在 errno.h 中。例: ETIMEDOUT =110
这里写图片描述
这里写图片描述
注意:thingmagic模块如果要用usb模式传输数据,管脚13要拉高。
以thingmagic驱动模块为例:
Usb 驱动的read函数 遇到如下错误.
[ 31.516523] kernel BUG at /home/book/work/src/kernel-3.2/arch/arm/include/asm/dma-mapping.h:321!
[ 31.525679] Internal error: Oops - undefined instruction: 0 [#1]
[ 31.531936] Modules linked in: thingmagic_usb(O)
[ 31.536761] CPU: 0 Tainted: G O (3.2.0 #22)
[ 31.542401] PC is at usb_hcd_map_urb_for_dma+0x350/0x360
[ 31.547947] LR is at thingmagic_usb_exit+0x71c/0x54 [thingmagic_usb]
[ 31.554571] pc : [] lr : [] psr: 80000013
百度查找: urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;(加上这一行)

d:\sourceinsight\linux_3.2\kernel-3.2\kernel-3.2\drivers\usb\core\Message.c
A.修改usb_bulk_msg 函数,增加 urb->transfer_flags|= URB_NO_TRANSFER_DMA_MAP; //write by lxl
当重新编译内核后,发现usb_bulk_msg 可以发送,但不能接收,在prob函数中,一直无法收到Usb数据。
B.将/home/book/work/src/kernel_3_2_0 usb_bulk_msg 函数恢复原样,prob函数调用usb_bulk_msg,又能收发Usb数据了
C.在接收回调函数中加上 spin_lock ,回调函数还是只调用1次。
D.两个接口,1个接口为中断接口,1个端点;另一个接口为批量传输接口,2个端点,注册中断端点(怀疑有数据时,是通过中断端点接收数据的),
依然无法进入 接收回调函数。(在拔下usb时会进入中断、批量传输的接收回调函数)
E. 将 usb_point1_snd_buf= usb_buffer_alloc(dev, len, GFP_KERNEL, &usb_snd_point1_buf_phys);
更改为 usb_point1_snd_buf = kmalloc(len,GFP_KERNEL);
还是无法进入接收的回调函数。
F. 发送函数用

retval = usb_bulk_msg(dev, usb_sndbulkpipe(dev,endpoint->bEndpointAddress), //发送管道       接收函数用 异步
usb_point2_rcv_urb= usb_alloc_urb(0, GFP_KERNEL);
usb_point2_rcv_buf= usb_buffer_alloc(dev, len2, GFP_KERNEL, &usb_point2_rcv_urb->transfer_dma);
usb_point2_rcv_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
usb_fill_bulk_urb(usb_point2_rcv_urb, dev, usb_rcvbulkpipe(dev,endpoint2->bEndpointAddress), usb_point2_rcv_buf, len2, usb_point2_rcv_fx, NULL);    
ret=usb_submit_urb(usb_point2_rcv_urb, GFP_ATOMIC);

结果: 成功一次进入回调函数,再就失败了
176.889500] thingmagic_usb_open
[ 176.893387] usb_point2_rcv_fx call back
[ 176.897485] usb_point2_rcv_buf[0]= ff,……..
[ 252.902248] send data is erro
[ 254.912242] send data is erro
[ 256.922285] send data is erro
G. 接收异步函数中 去掉usb_point2_rcv_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;出现最早曾出现的现象
[ 44.356162] ————[ cut here ]————
[ 44.360973] kernel BUG at /home/book/work/src/kernel-3.2/arch/arm/include/asm/dma-mapping.h:321!
[ 44.370130] Internal error: Oops - undefined instruction: 0 [#1]
[ 44.376387] Modules linked in: thingmagic_usb(O+)
[ 44.381302] CPU: 0 Tainted: G O (3.2.0 #24)
[ 44.386941] PC is at usb_hcd_map_urb_for_dma+0x350/0x360。。。。。。。。。。。。。。。。。。。。。
H. 内核启动过程中打印: musb-hdrc musb-hdrc.1: USB Host mode controller at e084a800 using DMA, IRQ 19
出问题的根本原因是DMA的地址映射问题.
将接收flag 更改为usb_point2_rcv_urb->transfer_flags |=URB_FREE_BUFFER;
[ 44.356162] ————[ cut here ]————
[ 23.045857] kernel BUG at /home/book/work/src/kernel-3.2/arch/arm/include/asm/dma-mapping.h:321!
[ 23.055013] Internal error: Oops - undefined instruction: 0 [#1]
[ 23.061271] Modules linked in: thingmagic_usb(O+)
[ 23.066186] CPU: 0 Tainted: G O (3.2.0 #24)
[ 23.071825] PC is at usb_hcd_map_urb_for_dma+0x350/0x360
[ 23.077359] LR is at 0xffdee080
G. 配置内核
Dirver——>>>>> Usb support ———->>>>>>disable DMA(always use pio)选项 选上。(没有什么影响),
回复内核的设置。
H.usb_buffer_alloc() ; 新版本 是否将这个函数更换????
I. 更改位置:

usb_fill_bulk_urb(usb_point2_rcv_urb, dev, usb_rcvbulkpipe(dev,endpoint2->bEndpointAddress), usb_point2_rcv_buf, len2, usb_point2_rcv_fx, NULL);    
usb_point2_rcv_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP ;

与之前咩有影响
优化代码

  usb_buffer_alloc  用usb_alloc_coherent()
          usb_buffer_free  用 usb_free_coherent()替代      
G. usb_point2_rcv_buf= usb_buffer_alloc(dev, len2, GFP_KERNEL, usb_point2_rcv_urb->transfer_buffer);
  urb->transfer_flags|=  URB_FREE_BUFFER; //write by lxl 

H. Prob 函数中 不申请usb_buffer,usb_urb 及初始化 提交Urb, urb的初始化及提交放在另一个驱动文件中,成功。
调试成功代码: learining_linux/usb thingmagic_usb.c 及 usbtest.c 文件.
F. 发送完数据后,usb接收回调函数被调用2次 .
测试程序,write时间为5ms,现更改为1s , 问题依旧。(回调函数中不提交urb,将不能接收)
最后解决办法:

 if(urb->actual_length>0) // 回调函数虽然调用2次,但有一次urb->actual_length =0,这样在if中复制到buffer,然后读取.
   {   int temp=0;                  
       for(temp=0;temp<urb->actual_length;temp++)
       printk("usb_point2_rcv_buf[%x]=%4x,\n", temp,usb_point2_rcv_buf[temp]);                  
    }   

猜你喜欢

转载自blog.csdn.net/tiger15605353603/article/details/81323883