Device Disconnect

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Device Disconnect

跳至解决方案
829 次查看
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 解答
477 次查看
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 回复数
477 次查看
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 项奖励
477 次查看
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 项奖励
478 次查看
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 项奖励