Device Disconnect

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 
826件の閲覧回数
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.

?

ラベル(1)
タグ(1)
0 件の賞賛
1 解決策
474件の閲覧回数
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 件の賞賛
3 返答(返信)
474件の閲覧回数
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 件の賞賛
474件の閲覧回数
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 件の賞賛
475件の閲覧回数
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 件の賞賛