android usb otg转换成host调试笔记

(原创作品,转载请标明转载路径)

近日在mstar 786平台上有个需求,即把usb otg转换成host接U盘。


开始调试时,以为只要把OTG的配置去掉,即CONFIG_USB_MS_OTG屏蔽掉即可,但编译烧录后,插入和拨出U盘时发现提示


android_work: did not send uevent (0 0   (null))


U盘的灯也不亮,说明没有上电。


后来搜索了有关资料,才发现需要把USB_CID脚拉低,拉低表示工作在HOST模式下。


有2种方式拉低该引脚:

1)硬件上把它强制拉低。

2)软件上拉低,在kernel目录下的drivers\usb\otg\ms_otg.c  中的ms_otg_init_irq函数,把如下代码屏蔽掉:

// OTG id pin pull-up
/*    reg_t = readl(&msotg->op_regs->usbc_regs->port_ctrl);
    reg_t |= IDPULLUP_CTRL;
    writel(reg_t, &msotg->op_regs->usbc_regs->port_ctrl);*/


编译烧录后,开机插入U盘,有如下LOG,表示识别成功:




[ 1374.141871] hub_events


[ 1374.144655] hub_port_connect_change


[ 1374.303911] hub_port_init


[ 1374.306911] ==13==> hub_port_init 1 
[ 1374.310873] Plug in USB Port1
[ 1374.503906] usb 3-1: new high speed USB device number 3 using Mstar-ehci-1
[ 1374.958064] usb-storage 3-1:1.0: Quirks match for vid 058f pid 6387: 20
[ 1374.965494] usb-storage 3-1:1.0: This device (058f,6387,010b S 06 P 50) has unneeded SubClass and Protocol entries in unusual_devs.h (kernel 3.4.5)
[ 1374.965505]    Please send a copy of this message to <[email protected]> and <[email protected]>
[ 1374.992704] scsi1 : usb-storage 3-1:1.0
[ 1374.999392] hub_events


[ 1375.002158] hub_events


[ 1375.996046] scsi 1:0:0:0: Direct-Access     Generic  Flash Disk       8.07 PQ: 0 ANSI: 4
[ 1376.008295] sd 1:0:0:0: [sdb] 16293888 512-byte logical blocks: (8.34 GB/7.76 GiB)
[ 1376.017568] sd 1:0:0:0: [sdb] Write Protect is off
[ 1376.023685] sd 1:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn‘t support DPO or FUA
[ 1376.038784]  sdb: sdb1
[ 1376.046711] sd 1:0:0:0: [sdb] Attached SCSI removable disk
[ 1376.054754] sd 1:0:0:0: Attached scsi generic sg0 type 0



识别成功后,在/dev/block/下会生成一个设备节点,有可能叫sda1


需要手动把它mount到mnt目录后才可访问:

mount -t vfat /dev/block/sda1 /mnt/sdcard


然后就可以在root权限下cd sdcard访问该U盘内容


郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。