aboutsummaryrefslogtreecommitdiff
path: root/stmhal/usbd_msc_storage.c
diff options
context:
space:
mode:
authorDamien George2014-04-15 19:56:32 +0100
committerDamien George2014-04-15 19:56:32 +0100
commit9699ea6a2f85c344296eb0046d9bad8f0c183d1a (patch)
treef39351b2407cb3b355627e2bd3e78397434c1a0e /stmhal/usbd_msc_storage.c
parent4d7f4eb6a924f4df458eda2e624f429d67ef2248 (diff)
stmhal: Fix USB MSC so that it unmounts correctly on Mac OS X.
Mac OS X sends a SCSI command to remove the medium when it unmounts a drive. If this command is not honoured, then OS X will automatically remount the drive, making it impossible to eject. This patch disables the USB MSC when the right SCSI command is sent.
Diffstat (limited to 'stmhal/usbd_msc_storage.c')
-rw-r--r--stmhal/usbd_msc_storage.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/stmhal/usbd_msc_storage.c b/stmhal/usbd_msc_storage.c
index f3ecd023d..0225a2a23 100644
--- a/stmhal/usbd_msc_storage.c
+++ b/stmhal/usbd_msc_storage.c
@@ -35,6 +35,11 @@
#include "diskio.h"
#include "sdcard.h"
+// These are needed to support removal of the medium, so that the USB drive
+// can be unmounted, and won't be remounted automatically.
+static uint8_t flash_removed = 0;
+static uint8_t sdcard_removed = 0;
+
/******************************************************************************/
// Callback functions for when the internal flash is the mass storage device
@@ -83,6 +88,9 @@ int8_t FLASH_STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *blo
* @retval Status
*/
int8_t FLASH_STORAGE_IsReady(uint8_t lun) {
+ if (flash_removed) {
+ return -1;
+ }
return 0;
}
@@ -95,6 +103,12 @@ int8_t FLASH_STORAGE_IsWriteProtected(uint8_t lun) {
return 0;
}
+// Remove the lun
+int8_t FLASH_STORAGE_StopUnit(uint8_t lun) {
+ flash_removed = 1;
+ return 0;
+}
+
/**
* @brief Read data from the medium
* @param lun : logical unit number
@@ -150,6 +164,7 @@ const USBD_StorageTypeDef USBD_FLASH_STORAGE_fops = {
FLASH_STORAGE_GetCapacity,
FLASH_STORAGE_IsReady,
FLASH_STORAGE_IsWriteProtected,
+ FLASH_STORAGE_StopUnit,
FLASH_STORAGE_Read,
FLASH_STORAGE_Write,
FLASH_STORAGE_GetMaxLun,
@@ -236,6 +251,9 @@ int8_t SDCARD_STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *bl
* @retval Status
*/
int8_t SDCARD_STORAGE_IsReady(uint8_t lun) {
+ if (sdcard_removed) {
+ return -1;
+ }
/*
#ifndef USE_STM3210C_EVAL
@@ -271,6 +289,12 @@ int8_t SDCARD_STORAGE_IsWriteProtected(uint8_t lun) {
return 0;
}
+// Remove the lun
+int8_t SDCARD_STORAGE_StopUnit(uint8_t lun) {
+ sdcard_removed = 1;
+ return 0;
+}
+
/**
* @brief Read data from the medium
* @param lun : logical unit number
@@ -315,6 +339,7 @@ const USBD_StorageTypeDef USBD_SDCARD_STORAGE_fops = {
SDCARD_STORAGE_GetCapacity,
SDCARD_STORAGE_IsReady,
SDCARD_STORAGE_IsWriteProtected,
+ SDCARD_STORAGE_StopUnit,
SDCARD_STORAGE_Read,
SDCARD_STORAGE_Write,
SDCARD_STORAGE_GetMaxLun,