THead USB适配方案

THead USB适配方案

目录:

一、配置USB为Device模式

二、配置USB为Host模式

三、配置USB为OTG模式

四、Device或者OTG模式下开启HDC功能

内容:

一、配置USB为Device模式

配置USB为Device模式,主要是利用了USB Composite及USB GADGET F_FS

CONFIG_USB_DWC3=y

CONFIG_USB_DWC3_THEAD=y

CONFIG_USB_DWC3_GADGET=y

CONFIG_CONFIGFS_FS=y

CONFIG_USB_LIBCOMPOSITE=y

CONFIG_TTY=y

CONFIG_USB_CONFIGFS_SERIAL=y

CONFIG_PROC_FS=y

CONFIG_USB_F_FS=y

CONFIG_USB_GADGET=y

CONFIG_USB_GADGET_DEBUG=y

CONFIG_USB_GADGET_DEBUG_FILES=y

CONFIG_USB_GADGET_DEBUG_FS=y

CONFIG_USB_GADGET_VBUS_DRAW=2

CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS=2

# CONFIG_USB_SERIAL_CONSOLE is not set

CONFIG_USB_CONFIGFS=y

CONFIG_USB_CONFIGFS_UEVENT=y

CONFIG_USB_CONFIGFS_F_FS=y

CONFIG_USB_CONFIGFS_F_ACC=y

CONFIG_USB_CONFIGFS_F_AUDIO_SRC=y

CONFIG_USB_CONFIGFS_F_MIDI=y

CONFIG_USB_ZERO=m

CONFIG_USB_ETH=m

CONFIG_USB_ETH_EEM=y

CONFIG_USB_G_NCM=m

CONFIG_USB_MASS_STORAGE=m

CONFIG_USB_G_SERIAL=m

CONFIG_USB_G_MULTI=m

#CONFIG_USB_G_MULTI_CDC=y

对应的DTS为:

&usb{

dr_mode = "peripheral";//peripheral host otg

//usb-role-switch;

//role-switch-default-mode = "host";

};

二、配置USB为Host模式

CONFIG_USB=y

CONFIG_USB_XHCI_HCD=y

CONFIG_USB_XHCI_PLATFORM=y

CONFIG_USB_EHCI_HCD=y

CONFIG_USB_OHCI_HCD=y

CONFIG_USB_STORAGE=y

CONFIG_USB_STORAGE_SDDR09=y

CONFIG_USB_STORAGE_SDDR55=y

CONFIG_USB_DWC3=y

CONFIG_USB_DWC3_THEAD=y

CONFIG_USB_DWC3_HOST=y

对应的DTS为:

&usb{

dr_mode = "host";//peripheral host otg

//usb-role-switch;

//role-switch-default-mode = "host";

};

  • 配置USB为OTG模式

主要是把USB与设备模式配置都打开,同时配置下面内容

HOST模式主要使用

CONFIG_USB=y

CONFIG_USB_DWC3_HOST=y

DEVICE模式主要使用

CONFIG_USB_GADGET=y

CONFIG_USB_LIBCOMPOSITE=y

CONFIG_USB_DWC3_GADGET=y

OTG模式下面需要

CONFIG_USB_DWC3_HOST与CONFIG_USB_DWC3_GADGET不配置

而是配置CONFIG_USB_DWC3_DUAL_ROLE=y,同时

CONFIG_USB_ROLE_SWITCH=y

对应的DTS为:

&usb{

dr_mode = "otg";//peripheral host otg

usb-role-switch;

//role-switch-default-mode = "host";

};

同时修改

THead USB适配方案_第1张图片

 

在HDC命令行界面可以输入下面命令进行模式切换

切换为主机模式

echo "host" >/sys/class/usb_role/ffe7040000.dwc3-role-switch/role

切换为设备模式

echo "device" >/sys/class/usb_role/ffe7040000.dwc3-role-switch/role

相关驱动文件:

drivers/usb/dwc3/dwc3-thead.c

->dwc3_thead_probe

drivers/usb/dwc3/core.c

->dwc3_probe

->dwc3_get_dr_mode

->dwc3_core_init

->dwc3_debugfs_init(dwc3/debugfs.c)

->dwc3_core_init_mode

->dwc3_gadget_init(dwc3/gadget.c)

->dwc3_host_init(dwc3/host.c)

->dwc3_drd_init(dwc3/drd.c)

drivers/usb/dwc3/debugfs.c

drivers/usb/dwc3/gadget.c

drivers/usb/dwc3/host.c

drivers/usb/dwc3/drd.c

drivers/usb/gadget/udc/core.c

drivers/usb/gadget/composite.c

参考文档:

USB 设备模式流程

Linux USB 3.0驱动分析(八)——Gadget UDC驱动分析 - luoyuna - 博客园

USB设备模式,做U盘

linux 内核配置otg,Linux 4.9.11 测试USB OTG功能_weixin_39723655的博客-CSDN博客

USB_CONFIGFS_SERIAL:

Depends on: USB_SUPPORT [=y] && USB_GADGET [=y] && USB_CONFIGFS [=y] && TTY [=y]           

USB_DWC3_DUAL_ROLE:

Depends on: (USB [=y]=y || USB [=y]=USB_DWC3 [=y]) && (USB_GADGET [=y]=y || USB_GADGET [=y]=USB_DWC3 [=y]) && (EXTCON [=y]=y || EXTCON [=y]=USB_DWC3 [=y])     

USB_CONFIGFS_UEVENT:

Depends on: USB_SUPPORT [=y] && USB_GADGET [=y] && USB_CONFIGFS [=y]

USB_CONFIGFS_F_FS

Depends on: USB_SUPPORT [=y] && USB_GADGET [=y] && USB_CONFIGFS [=y]  

USB_F_FS:

Selected by :

USB_CONFIGFS_F_FS [=y] && USB_SUPPORT [=y] && USB_GADGET [=y] && USB_CONFIGFS [=y]  

USB_ROLE_SWITCH

Selected by :

USB_DWC3 [=y] && USB_SUPPORT [=y] && (USB [=y] || USB_GADGET [=y]) && HAS_DMA [=y] && USB_DWC3_DUAL_ROLE [=n]                                                                                  

你可能感兴趣的:(java,开发语言)