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

ソリューションへジャンプ
3,415件の閲覧回数
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 解決策
3,296件の閲覧回数
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 返答(返信)
3,398件の閲覧回数
yangao
Contributor III

Yes.

0 件の賞賛
3,386件の閲覧回数
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 件の賞賛
3,380件の閲覧回数
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 件の賞賛
3,377件の閲覧回数
Rita_Wang
NXP TechSupport
NXP TechSupport

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

0 件の賞賛
3,367件の閲覧回数
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 件の賞賛
3,357件の閲覧回数
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 件の賞賛
3,353件の閲覧回数
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 件の賞賛
3,297件の閲覧回数
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.

 

 

3,404件の閲覧回数
Rita_Wang
NXP TechSupport
NXP TechSupport

Have you get your board now?

0 件の賞賛