Detect USB connect/disconnect using USBD ROM Stack?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Detect USB connect/disconnect using USBD ROM Stack?

2,525 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpetersen on Wed Dec 09 12:56:37 MST 2015
I've implemented a USB Device MSC on an LPC1837, using LPCOpen 2.12 and based on the usbd_rom_msc_ram example (modified to use external memory).

I'm able to see the device show up in Windows as a drive, and format it through Windows. Now I need to be able to detect when the user has either 'ejected' the drive from Windows or physically disconnected USB so that I can access the files in memory. I can't seem to find documentation on an interrupt or status bit to poll. How can I detect USB connect/disconnect events using the USBD ROM stack?

Much appreciated!
Labels (1)
0 Kudos
Reply
6 Replies

1,953 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpetersen on Mon Jan 11 12:22:14 MST 2016
Still looking for info on this, does anybody have any input for USB device using the ROM stack?
0 Kudos
Reply

1,953 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MikeSimmonds on Sat Dec 12 09:12:42 MST 2015
PLEASE IGNORE MY POSTS

I had assumed that you were implementing a HOST not a DEVICE.
I have no experience coding for device.

Sorry, Mike.
0 Kudos
Reply

1,953 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MikeSimmonds on Sat Dec 12 09:06:00 MST 2015
Note: I am on LPC1778, my UM says that 5V from USB connector must be available
on USB_PWRDx pin for detection to work!

From UM10470 (LPC17x8) Chapter 6 Pin Configuration


Quote:
USB_PWRD1 — Power Status for USB port 1 (host power switch). When using the
chip in USB host mode, the USB_PWRD input must be enabled. The USB host
controller will only detect a device connect event when the port power bit is set in
the OHCI and the USB_PWRD bit is asserted for the corresponding port.



THIS LITTLE NUGGET SHOULD BE STATED IN THE USB HOST SECTION OF THE MANUALS!!

On our board (self powered) we feed in 5V to the pin via a 47K (I think, don't quote me) series resistor.

Cheers, Mike.
0 Kudos
Reply

1,953 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MikeSimmonds on Sat Dec 12 08:46:24 MST 2015
My bad, I was going by memory and a cursory re-read of the OHCI manual.

In my Interrupt handler (when root hub status change is noted), I actually check
bit 16 of the PortStatus[N] register called CSC in the OHCI doc.
If this is set, then I capture the CCS bit I previously mentioned (bit 0)
and stash this in a (volatile) variable that the rest of the "C" code can see.

These bit names are confusing and easy to mis-spell aren't they.

Note: I cannot share: It is written in assembler and is also company confidential.

NB: remember to (a) clear the status change bit(s) in the PortStatus and
(b) clear the IrqStatus bit(s) in the InterruptStatus in the IRQ handler.

My "C" code polls the 'connected' variable (via a function) ...

static void
WaitInsert(void)
{
static
ulongftt = 1;
ucharwrk[128], s[256];
ulongrc;

if (prvConnect == usbConnect)// any change?
return;// nope

//--------------------------------------//
prvConnect = usbConnect;// remember change

        Do stuff depending on insert (1, non-zero) or remove (0) ...



Cheers, Mike.
0 Kudos
Reply

1,953 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpetersen on Fri Dec 11 14:14:47 MST 2015
Thanks Mike. That was helpful in pointing me in the right direction.

I found a status bit in USB0's PORTSC1_D register for CCS which sounded promising. Upon further investigation though, that status bit does not change even when physically disconnecting USB. According to the user manual -
"A zero indicates that the device did not attach successfully or was forcibly disconnected by the software writing a zero to the Run bit in the USBCMD register. It does not state the device being disconnected or suspended."


Which I found to be true. There is another bit in that same register, SUSP, which indicates when the device is in a suspended mode. It looks like I can use this to determine when USB has been physically disconnected (SUSP goes high, indicating that the device is suspended), but the status remains 'Not Suspended' even when I 'Eject' from Windows.

Does anyone know if I am going about this the right way? Is there a way to detect that windows 'ejected' the device even if it is still physically connected? Does the USBD ROM stack provide any handles into this?

Thanks!
0 Kudos
Reply

1,953 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MikeSimmonds on Thu Dec 10 06:40:33 MST 2015
Read the OHCI document here

See the current connect status in the port[N] status register Sect 7.4.4

You need to ensure that the rhsc (root hub status change) bit is set in the hcInterruptEnable register. Sect 7.1.5

Then on an interrupt look at the connect status.

BTW, I never used the ROM driver (I don't think that the LPC1778 even has one!),
so I cannot give specifics to actually achieve the steps above. Presumably the docs on the various functions
and structures of the ROM API should help once you know what you are looking for.

HTH.

Cheers, Mike.
0 Kudos
Reply