PORTS Forum

Ports and Interfaces => USB => Topic started by: nstjean on April 28, 2016, 03:10:21 pm

Title: USB detection on Linux Embedded
Post by: nstjean on April 28, 2016, 03:10:21 pm
Hi,
On a phyCORE-AM335x running Linux, I am trying to detect when USB cable is connect and disconnect. Is there a way to handle interrupt or event on USB from withing a main application?

I noticed that the interrupt count in /proc/interrupt for "musb-hdrc.0" increases when cable is connect/disconnected.

Yet, I have tried using libudev, without success.

A message is displayed on terminal when connecting and disconnecting USB cable between PC and board.
"[...] musb Haptic controller gadget disconnected" and "[...] Haptic Controller: high-speed #1: 2mA, Haptic controller [...] Haptic Controller: Using interface 0"

Any advice or comment will be appreciated
Thanks
Title: Re: USB detection on Linux Embedded
Post by: Jan Axelson on April 28, 2016, 09:42:30 pm
Maybe this will help:

http://unix.stackexchange.com/questions/28548/how-to-run-custom-scripts-upon-usb-device-plug-in
Title: Re: USB detection on Linux Embedded
Post by: nstjean on May 02, 2016, 10:17:12 am
Thanks Jan,

This link gave me hints, but, I did not manage to trig an event when connecting and disconnecting the usb cable. When I run "udevadm monitor", there is no event displayed upon cable connection or disconnection.

On my setup, the phyCore is the device, and I wish to detect when the PC (host) is connected or not. The detection is on the phyCORE side (linux embedded).

I have also been looking for a detection of the power USB from PC, found nothing yet.
Title: Re: USB detection on Linux Embedded
Post by: Jan Axelson on May 02, 2016, 08:26:51 pm
What will the device do with the information?

Typically, a device learns of attach/detach by detecting the presence/absence of VBUS.
Title: Re: USB detection on Linux Embedded
Post by: nstjean on May 03, 2016, 10:53:38 am
The idea is to know when to open and close the handle on the USB device, depending of existing link or not between device and PC.
Title: Re: USB detection on Linux Embedded
Post by: Jan Axelson on May 03, 2016, 04:58:54 pm
Some ideas here:

https://e2e.ti.com/support/embedded/linux/f/354/t/65332