cancel
Showing results for 
Search instead for 
Did you mean: 

Force OS to re-enumerate mass storage device

Mostafa B
Associate II
Posted on November 20, 2013 at 11:22

Dear all,

I am developing a mass storage device using

http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00037051.pdf

. The number of drives must change dynamically based on a certain event (e.g., a new drive mush show up after pushing a button on the board). I could accomplish this if I could force windows to issue 

http://en.wikipedia.org/wiki/SCSI_Report_LUNs_Command

command again (it is a SCSI command that retrieves the number of logical units on the device). But so far I have had no success.

My current solution is to detach/attach the usb interface using OTG_FS_DCTL register but it causes all volumes to disappear at first and then reappear again. I was wondering if it would be possible to force the operating system to re-enumerate usb devices on the bus without restarting the interface.

Regards,

Mostafa
3 REPLIES 3
damh
Associate II
Posted on November 21, 2013 at 11:15

Possible solution (probably there are easier ways ;) :(

You can simulate an USB-hub. Every ''logical'' volume can be simulated as a separate USB-device.

Other way can be a MTP-USB-device (like mobile phones). It allows a lively storage (that is changing ''itself'' without interaction of the Host-USB-device (PC).
tsuneo
Senior
Posted on November 22, 2013 at 01:02

> The number of drives must change dynamically based on a certain event

You may reserve the LUN(s) at the Get_Max_LUN request in the early stage of MSC (Mass-Storage Class) enumeration. Get_Max_LUN returns the max number expected by your application.

After Get_Max_LUN, OS may ask these SCSI commands for each LUN.

- TestUnitReady

- Inquiry

- ModeSense6/10

- ReadFormatCapacity

- ReadCapacity

For working derives (LUNs), your firmware responds to these commands, as usual.

For absent drives, your firmware fails these SCSI commands (except for Inquiry), and returns NOT_READY sense code to RequestSense. Inquiry should be responded decently, either with or without target drive.

OS keeps to ask these SCSI commands for absent drives, until your firmware succeeds on these commands.

We'll find this method in secure USB stick, which mounts the target drive after password type-in.

Tsuneo
Mostafa B
Associate II
Posted on December 02, 2013 at 19:12

It worked!

The only problem is that all inactive drives show up in Explorer. This seems logical since Windows thinks they are removable devices but no disk is inserted yet.

I looked for software-based solutions and it seems that sending IOCTL_STORAGE_FIND_NEW_DEVICES command using DeviceIoControl function might be useful but I have not tried it yet.

I think damh's idea could solve this problem but it seems much harder to implement.

Thank you both very much!