USB接口上有4个管脚,OTG功能有5个。原来4个分别是电 D+ D- 地。 现在增加了一个ID。这个ID线就决定了自己做主设备还是从设备。如果ID线是高则自己是从设备,反之是主设备。
USB_OTG_ID定义为W23,即GPIO1_IO24
/test/gpio_get.sh24用来读出gpio value。读出来总是0:低电平。所以也不知道前面这句描述是对是错了。
imx6 kernel configas:
-> USB GadgetDrivers (
->File-backedStorage Gadget(USB_FILE_STORAGE [=m]) 。记得:不是选massstorage. 而且选模块方式,以方便安装模块时输入参数。
内置驱动时,测试打印:
g_file_storagegadget: controller 'fsl-usb2-udc' not recognized
g_file_storagegadget: No serial-number string provided!
g_file_storagegadget: no file given for LUN0
显然,这就是模块参数未给定导致的。
编译模块:
makeM=drivers/usb/gadget/ modules
得到
root@ubuntu:/home/imx6s/linux-3.0.101#make M=drivers/usb/gadget/ modules
Building modules, stage 2.
MODPOST 1 modules
LD [M] drivers/usb/gadget/g_file_storage.ko
root@imx6s ~$insmod /lib/modules/g_file_storage.ko file=/dev/mmcblk0
g_file_storagegadget: controller 'fsl-usb2-udc' not recognized
g_file_storagegadget: No serial-number string provided!
g_file_storagegadget: File-backed Storage Gadget, version: 1 September 2010
g_file_storagegadget: Number of LUNs=1
g_file_storagegadget-lun0: ro=0, nofua=0, file: /dev/mmcblk0
Suspend udc forOTG auto detect
fsl-usb2-udc: bindto driver g_file_storage
root@imx6s ~$g_file_storage gadget: high speed config #1
win7也同时显示说找到设备驱动,磁盘驱动器:linux File-Stor Gadget USB Device
下面反复插拔USB-PC线几次,然后换成USB-SD卡,都是可以的。但再换回USB-PC线就不行了,找不见设备。
root@imx6s ~$g_file_storage gadget: high speed config #1
root@imx6s ~$g_file_storage gadget: high speed config #1
root@imx6s ~$
root@imx6s ~$g_file_storage gadget: high speed config #1
root@imx6s ~$
root@imx6s ~$ usb1-1: new high speed USB device number 2 using fsl-ehci
usb 1-1: devicev0930 p6545 is not supported
scsi0 :usb-storage 1-1:1.0
scsi 0:0:0:0:Direct-Access TOSHIBA TransMemory PMAP PQ: 0 ANSI: 4
sd 0:0:0:0: [sda]30489408 512-byte logical blocks: (15.6 GB/14.5 GiB)
sd 0:0:0:0: [sda]Write Protect is off
sd 0:0:0:0: [sda]No Caching mode page found
sd 0:0:0:0: [sda]Assuming drive cache: write through
sd 0:0:0:0: [sda]No Caching mode page found
sd 0:0:0:0: [sda]Assuming drive cache: write through
sda: sda1
sd 0:0:0:0: [sda]No Caching mode page found
sd 0:0:0:0: [sda]Assuming drive cache: write through
sd 0:0:0:0: [sda]Attached SCSI removable disk
root@imx6s ~$ usb1-1: USB disconnect, device number 2
wait otg vbuschange timeout!
root@imx6s ~$ usb1-1: new high speed USB device number 3 using fsl-ehci
usb 1-1: devicev0930 p6545 is not supported
scsi1 :usb-storage 1-1:1.0
scsi 1:0:0:0:Direct-Access TOSHIBA TransMemory PMAP PQ: 0 ANSI:4
sd 1:0:0:0: [sda]30489408 512-byte logical blocks: (15.6 GB/14.5 GiB)
sd 1:0:0:0: [sda]Write Protect is off
sd 1:0:0:0: [sda]No Caching mode page found
sd 1:0:0:0: [sda]Assuming drive cache: write through
sd 1:0:0:0: [sda]No Caching mode page found
sd 1:0:0:0: [sda]Assuming drive cache: write through
sda: sda1
sd 1:0:0:0: [sda]No Caching mode page found
sd 1:0:0:0: [sda]Assuming drive cache: write through
sd 1:0:0:0: [sda]Attached SCSI removable disk
root@imx6s ~$
root@imx6s ~$ usb1-1: USB disconnect, device number 3
wait otgvbus change timeout!
root@imx6s ~$
root@imx6s ~$ usb1-1: new high speed USB device number 4 using fsl-ehci
usb 1-1: devicev0930 p6545 is not supported
scsi2 :usb-storage 1-1:1.0
scsi 2:0:0:0:Direct-Access TOSHIBA TransMemory PMAP PQ: 0 ANSI: 4
sd 2:0:0:0: [sda]30489408 512-byte logical blocks: (15.6 GB/14.5 GiB)
sd 2:0:0:0: [sda]Write Protect is off
sd 2:0:0:0: [sda]No Caching mode page found
sd 2:0:0:0: [sda]Assuming drive cache: write through
sd 2:0:0:0: [sda]No Caching mode page found
sd 2:0:0:0: [sda]Assuming drive cache: write through
sda: sda1
sd 2:0:0:0: [sda]No Caching mode page found
sd 2:0:0:0: [sda]Assuming drive cache: write through
sd 2:0:0:0: [sda]Attached SCSI removable disk
usb 1-1: USBdisconnect, device number 4
wait otg vbuschange timeout!
USB在host模式时,才需要对外输出电源。slave mode时,不需要输出电源,但也不影响工作。
电源管脚:
IMX_GPIO_NR(4, 15),111
/test/gpio_set.sh111 0 //关pwr
实测不影响工作。其实,我觉得USB_ID和USB_VBUS就没什么关系。