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

cancel
Showing results for 
Search instead for 
Did you mean: 

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

Jump to solution
369 Views
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

Labels (2)
0 Kudos
1 Solution
250 Views
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.

 

 

View solution in original post

9 Replies
352 Views
yangao
Contributor III

Yes.

0 Kudos
340 Views
b45499
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 Kudos
334 Views
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 Kudos
331 Views
b45499
NXP TechSupport
NXP TechSupport

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

0 Kudos
321 Views
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 Kudos
311 Views
b45499
NXP TechSupport
NXP TechSupport

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

0 Kudos
307 Views
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 Kudos
251 Views
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.

 

 

358 Views
b45499
NXP TechSupport
NXP TechSupport

Have you get your board now?

0 Kudos