Device Disconnect

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

Device Disconnect

Jump to solution
818 Views
OldNick
Contributor IV

Does anybody know what happens in the device stack when you pull the plug out of the PC?

 

Using modified Kwikstick example for SDCard to USB-MSD.  MQX 3.7 or 3.8 on Kinetis

 

I mount the SDcard at boot.  Then, unmount the SDcard when bAttach is detected so MSD and PM don't argue with each other.

 

Of course, I want to re-mount the SD-card when the Host PC is disconnected.

 

I have some problems with Windoze adding lots of generic storage devices until it finally realises what it is looking at, but my USB analyser is on its way.  So in the meantime, I thought I'd dig through the drivers to see what happens when the plug is pulled, and if there is a callback for that.

 

Haven't found it so far.

?

Labels (1)
Tags (1)
0 Kudos
1 Solution
466 Views
MarcoE
Contributor II

Thank you for the hint, i want to add some detail of my implementation (my project is based on the ramdisk example):

 

I previously unregistered this service with 

_usb_device_unregister_service(handle, USB_SERVICE_SLEEP);

then registered it to my callback routine with

_usb_device_register_service(handle, USB_SERVICE_SLEEP, USB_Sleep_Callback, (void *) 0);

 

Using a global variable which tracks the correct enumeration of the device I can identify the SLEEP events that effectively correspond to a physical disconnection of the host PC.

 

Now all seems working fine.

 

View solution in original post

0 Kudos
3 Replies
466 Views
MarcoE
Contributor II

I also have to remount MFS on SD-Card when the host PC is disconnected from my board.

Have you eventually found a callback for this type of event?

 

If no, is there some workaround (e.g. reading periodically some registers where I can check if there is activity on bus or something similar?)

 

Thank you

0 Kudos
466 Views
BielikM
Contributor III

MQX usb device hasnt had detach event yet. You can use sleep event. This event is used when device is disconected from host ,but also when host dont want to comunicate with device.

You can register this callback like following:

_usb_device_register_service(handle, USB_SERVICE_SLEEP, MySuspendEventHandler, (void *)some_parameter);

0 Kudos
467 Views
MarcoE
Contributor II

Thank you for the hint, i want to add some detail of my implementation (my project is based on the ramdisk example):

 

I previously unregistered this service with 

_usb_device_unregister_service(handle, USB_SERVICE_SLEEP);

then registered it to my callback routine with

_usb_device_register_service(handle, USB_SERVICE_SLEEP, USB_Sleep_Callback, (void *) 0);

 

Using a global variable which tracks the correct enumeration of the device I can identify the SLEEP events that effectively correspond to a physical disconnection of the host PC.

 

Now all seems working fine.

 

0 Kudos