4141
4242// These are needed to support removal of the medium, so that the USB drive
4343// can be unmounted, and won't be remounted automatically.
44- static uint8_t flash_removed = 0 ;
44+ static uint8_t flash_started = 0 ;
4545
4646#if MICROPY_HW_HAS_SDCARD
47- static uint8_t sdcard_removed = 0 ;
47+ static uint8_t sdcard_started = 0 ;
4848#endif
4949
5050/******************************************************************************/
@@ -73,6 +73,7 @@ static const int8_t FLASH_STORAGE_Inquirydata[] = { // 36 bytes
7373 */
7474int8_t FLASH_STORAGE_Init (uint8_t lun ) {
7575 storage_init ();
76+ flash_started = 1 ;
7677 return 0 ;
7778}
7879
@@ -95,10 +96,10 @@ int8_t FLASH_STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *blo
9596 * @retval Status
9697 */
9798int8_t FLASH_STORAGE_IsReady (uint8_t lun ) {
98- if (flash_removed ) {
99- return -1 ;
99+ if (flash_started ) {
100+ return 0 ;
100101 }
101- return 0 ;
102+ return -1 ;
102103}
103104
104105/**
@@ -111,8 +112,8 @@ int8_t FLASH_STORAGE_IsWriteProtected(uint8_t lun) {
111112}
112113
113114// Remove the lun
114- int8_t FLASH_STORAGE_StopUnit (uint8_t lun ) {
115- flash_removed = 1 ;
115+ int8_t FLASH_STORAGE_StartStopUnit (uint8_t lun , uint8_t started ) {
116+ flash_started = started ;
116117 return 0 ;
117118}
118119
@@ -176,7 +177,7 @@ const USBD_StorageTypeDef USBD_FLASH_STORAGE_fops = {
176177 FLASH_STORAGE_GetCapacity ,
177178 FLASH_STORAGE_IsReady ,
178179 FLASH_STORAGE_IsWriteProtected ,
179- FLASH_STORAGE_StopUnit ,
180+ FLASH_STORAGE_StartStopUnit ,
180181 FLASH_STORAGE_PreventAllowMediumRemoval ,
181182 FLASH_STORAGE_Read ,
182183 FLASH_STORAGE_Write ,
@@ -228,7 +229,7 @@ int8_t SDCARD_STORAGE_Init(uint8_t lun) {
228229 if (!sdcard_power_on ()) {
229230 return -1 ;
230231 }
231-
232+ sdcard_started = 1 ;
232233 return 0 ;
233234
234235}
@@ -264,33 +265,10 @@ int8_t SDCARD_STORAGE_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *bl
264265 * @retval Status
265266 */
266267int8_t SDCARD_STORAGE_IsReady (uint8_t lun ) {
267- if (sdcard_removed ) {
268- return -1 ;
268+ if (sdcard_started ) {
269+ return 0 ;
269270 }
270- /*
271- #ifndef USE_STM3210C_EVAL
272-
273- static int8_t last_status = 0;
274-
275- if(last_status < 0)
276- {
277- SD_Init();
278- last_status = 0;
279- }
280-
281- if(SD_GetStatus() != 0)
282- {
283- last_status = -1;
284- return (-1);
285- }
286- #else
287- if( SD_Init() != 0)
288- {
289- return (-1);
290- }
291- #endif
292- */
293- return 0 ;
271+ return -1 ;
294272}
295273
296274/**
@@ -303,8 +281,8 @@ int8_t SDCARD_STORAGE_IsWriteProtected(uint8_t lun) {
303281}
304282
305283// Remove the lun
306- int8_t SDCARD_STORAGE_StopUnit (uint8_t lun ) {
307- sdcard_removed = 1 ;
284+ int8_t SDCARD_STORAGE_StartStopUnit (uint8_t lun , uint8_t started ) {
285+ sdcard_started = started ;
308286 return 0 ;
309287}
310288
@@ -356,7 +334,7 @@ const USBD_StorageTypeDef USBD_SDCARD_STORAGE_fops = {
356334 SDCARD_STORAGE_GetCapacity ,
357335 SDCARD_STORAGE_IsReady ,
358336 SDCARD_STORAGE_IsWriteProtected ,
359- SDCARD_STORAGE_StopUnit ,
337+ SDCARD_STORAGE_StartStopUnit ,
360338 SDCARD_STORAGE_PreventAllowMediumRemoval ,
361339 SDCARD_STORAGE_Read ,
362340 SDCARD_STORAGE_Write ,
0 commit comments