Hi all, I am using the stm32usb_mem keil example for USB mass storage implementation. It is working well as mass storage device. I found that when i right click the device to use the eject option. I got an error message "An error was encountered trying to eject Device(G:)". The device cannot be removed. Anyone can solve this problem.
Thanks Aru
Are you working on this Keil example? "STM32 USB Mass Storage Device Example" http://www.keil.com/download/docs/362.asp
In your code, SCSI_MEDIA_REMOVAL (PREVENT ALLOW MEDIUM REMOVAL) is always accepted, as follows.
void MSC_GetCBW (void) { ... case SCSI_MEDIA_REMOVAL: CSW.bStatus = CSW_CMD_PASSED; MSC_SetCSW(); // goto fail;
Does your drive have auto-eject capability? If it doesn't, fail this command, as the original code does. MSC device doesn't need to accept every SCSI command sent by host. It should fail on unsupported SCSI commands.
Rather, a problem of the original example is, it always returns the same SenseData of NO SENSE (Key:0x00), NO ADDITIONAL SENSE INFORMATION (ASC/ASCQ=0x00/0x00). After fail of SCSI command, it should return typical SenseData, such as,
Sense Key, ASC/ASCQ NOT_READY (0x02), MEDIUM_NOT_PRESENT (0x3A/0x00) ILLEGAL REQUEST (0x05), INVALID COMMAND OPERATION CODE (0x20/0x00) UNIT_ATTENTION (0x06), NOT_READY_TO_READY_CHANGE, MEDIUM_MAY_HAVE_CHANGED (0x28/0x00) etc.
Tsuneo
Hi chinzei, Thanks for your reply.... Yes,i am using this stm32usb_mem example. I need my drive should have auto eject capability. What are the commands and its value need to implement to work this example. Thanks a lot.......
> I need my drive should have auto eject capability.
Er.., does your drive have auto eject mechanism, such as CD/DVD tray which ejects a medium automatically? Or, do you want, by right-click eject, the drive disappears from "My Computer" window?
I observed the behavior of a couple of USB sticks on this issue (right-click, eject) on Windows. Typical responses are,
PREVENT ALLOW MEDIUM REMOVAL(PREVENT:01b - prohibit removal): fails - ILLEGAL REQUEST, INVALID COMMAND OPERATION CODE
PREVENT ALLOW MEDIUM REMOVAL(PREVENT:00b - allow removal): success
START STOP UNIT(IMMED:0, POWER CONDITION:0h(START_VALID), LOEJ:1, START:0) : success
After START STOP UNIT, the sticks fails all commands, including TEST UNIT READY, with NOT_READY, MEDIUM_NOT_PRESENT sense data.
None of USB sticks disappear from "My Computer" by right-click eject
Hi chinzei,
Thanks for your reply...
>>Er.., does your drive have auto eject mechanism, such as CD/DVD tray which ejects a medium >>automatically? >>Or, do you want, by right-click eject, the drive disappears from "My Computer" window?
I need device removal by right-click eject, the drive should disappears from "My Computer" window.
How to implement the following commands in this example?
After successfull execution of these commands...>>None of USB sticks disappear from "My Computer" by right-click eject
Did the device remove from My computer? Thanks
> I need device removal by right-click eject, the drive should disappears from "My Computer" window.
Umm... Though it isn't usual, there is no way other than soft-disconnect of the device.
USB sticks emulate SD card readers. In the view point of USB, USB stick isn't a removable disk, because its medium (memory) isn't removable. But in practice, USB sticks have been implemented as removable. I believe it's because of safety, to cancel write cache. OS writes to removable disks immediately without any write cache. When a disk is accidentally plugged off, write cache increases possibility of file system inconsistency.
After a removable drive ejects its medium, the drive itself still connects to the host PC. After CD, DVD or SD are ejected, you'll see the drive / card reader remain on "My Computer". Just like these drives, USB sticks also keep its emulated "drive" after eject. Just plug-off makes these "drives" disappear. That is, you have to plug off the stick to make it disappear.
Firmware emulates plug-off using soft-disconnect. Call USB_Connect( FALSE ), after the device finishes SCSI_START_STOP_UNIT command.
Hi chinzei, Thanks for your reply... I ejected the media as your suggestion.. The device is removed from PC and its file contents are not available..but I got an error during ejection... "An error was encountered trying to eject Device(G:)" I found from the debug message after execution of these commands:SCSI_MEDIA_REMOVAL SCSI_START_STOP_UNIT,OS sends these commands for another time. But the media is not available,it think the MEDIA is not responding and produce the error... Thanks
Hi Chinzei, Thank for your discussion... Now the device successfully removed from "My Computer" Thanks