How to detect a USB device/host is attached to the USB port

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

How to detect a USB device/host is attached to the USB port

跳至解决方案
6,373 次查看
yangao
Contributor III

Hi,

We are using iMX6DL. In our design, we need to do some settings based on whether there is a USB device is attached to the USB OTG port. 

Is there a way to find out that any USB device/host is currently attached to the USB OTG port?

Thanks,

Winston

标签 (2)
0 项奖励
回复
1 解答
6,254 次查看
BiyongSUN
NXP Employee
NXP Employee

udev knows by netlink to mount such as usb disk and knows to invoke usb garget as device. 

How udev know that is the way you know that and the answer for your question. 

The basic knowledge is netlink of linux.  the dmesg is also by netlink link udev. if you write down a netlink program you will get such as usb disk add remove message as udev does. 

From the sysfs  /sys/class, it also can know the usb role. 

 

It is linux question not a question for i.MX Processors  community. 

It is too big topic, suggest you to learn the netlink, udev mechanism first.

 

 

在原帖中查看解决方案

9 回复数
6,356 次查看
yangao
Contributor III

Yes.

0 项奖励
回复
6,344 次查看
Rita_Wang
NXP TechSupport
NXP TechSupport

You can run your board to see the host/device mode, when download images to your board, the board will work on device mode, and when system boot up, you can test the usb host mode.

0 项奖励
回复
6,338 次查看
yangao
Contributor III

Hi,

Would you please elaborate more? from embedded Linux, what command should I use? or any /sys file I should check?

Regards,

Winston

0 项奖励
回复
6,335 次查看
Rita_Wang
NXP TechSupport
NXP TechSupport

Which version of BSP are you using? Have you board boot up?

0 项奖励
回复
6,325 次查看
yangao
Contributor III

We use BSP 3.14*.

The board boots up without any problem - it is already a product for years. Now we want to add some new feature - do something when a USB device/host is connected to the OTG port. But we need to way to detect that a USB device/host is connected.

0 项奖励
回复
6,315 次查看
Rita_Wang
NXP TechSupport
NXP TechSupport

You want the usb to work as host? If yes, you need to connect one otg usb line

0 项奖励
回复
6,311 次查看
yangao
Contributor III

I want to set USB as host or device only when a USB host/device is connected - that goes back to my original question: How to detect that there is a USB device/host currently connected. It does not make sense to set anything if nothing is connected, right?

0 项奖励
回复
6,255 次查看
BiyongSUN
NXP Employee
NXP Employee

udev knows by netlink to mount such as usb disk and knows to invoke usb garget as device. 

How udev know that is the way you know that and the answer for your question. 

The basic knowledge is netlink of linux.  the dmesg is also by netlink link udev. if you write down a netlink program you will get such as usb disk add remove message as udev does. 

From the sysfs  /sys/class, it also can know the usb role. 

 

It is linux question not a question for i.MX Processors  community. 

It is too big topic, suggest you to learn the netlink, udev mechanism first.

 

 

6,362 次查看
Rita_Wang
NXP TechSupport
NXP TechSupport

Have you get your board now?

0 项奖励
回复