aboutsummaryrefslogtreecommitdiff
path: root/stmhal/usbd_msc_storage.c
diff options
context:
space:
mode:
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,