]> localhost Git - SCSI2SD-V6.git/commitdiff
Fix implementation of USB MSC READ FORMAT CAPACITIES command to handle no SD card...
authorMichael McMaster <michael@codesrc.com>
Tue, 20 Apr 2021 12:45:05 +0000 (22:45 +1000)
committerMichael McMaster <michael@codesrc.com>
Tue, 20 Apr 2021 12:45:05 +0000 (22:45 +1000)
src/firmware/usb_device/usbd_msc_scsi.c
src/firmware/usb_device/usbd_msc_storage_sd.c

index aa0880c20a8c72d77dbf51cb0886517e48c52773..9cedc7be667feabeb5b32cbdda08fe083b5382d6 100755 (executable)
@@ -306,11 +306,24 @@ static int8_t SCSI_ReadFormatCapacity(USBD_HandleTypeDef  *pdev, uint8_t lun, ui
   
   if(((USBD_StorageTypeDef *)pdev->pUserData)->GetCapacity(lun, &blk_nbr, &blk_size) != 0)
   {
-    SCSI_SenseCode(pdev,
-                   lun,
-                   NOT_READY, 
-                   MEDIUM_NOT_PRESENT);
-    return -1;
+    // Capacity List Header
+    // [0] Reserved
+    // [1] Reserved
+    // [2] Reserved
+    
+    hmsc->bot_data[3] = 0x08; // Capacity List Length (8 bytes, 1 descriptor)
+
+    // Number of blocks. MAXIMUM
+    // 0x400000 is 2TB worth of 512 blocks.
+    hmsc->bot_data[4] = 0x00;
+    hmsc->bot_data[5] = 0x3F;
+    hmsc->bot_data[6] = 0xFF;
+    hmsc->bot_data[7] = 0xFF;
+    
+    hmsc->bot_data[8] = 0x03; // Descriptor code - No media.
+    hmsc->bot_data[9] = 0x00;
+    hmsc->bot_data[10] = 0x02; // 0x200 512 bytes
+    hmsc->bot_data[11] = 0x00;
   } 
   else
   {
@@ -320,15 +333,16 @@ static int8_t SCSI_ReadFormatCapacity(USBD_HandleTypeDef  *pdev, uint8_t lun, ui
     hmsc->bot_data[6] = (uint8_t)((blk_nbr - 1) >>  8);
     hmsc->bot_data[7] = (uint8_t)(blk_nbr - 1);
     
-    hmsc->bot_data[8] = 0x02;
+    hmsc->bot_data[8] = 0x02; // Descriptor code - Formatted media
     hmsc->bot_data[9] = (uint8_t)(blk_size >>  16);
     hmsc->bot_data[10] = (uint8_t)(blk_size >>  8);
     hmsc->bot_data[11] = (uint8_t)(blk_size);
+  }
     
     hmsc->bot_data_length = 12;
     return 0;
-  }
 }
+
 /**
 * @brief  SCSI_ModeSense6
 *         Process Mode Sense6 command
index 7cb0d150cd3f20093c9a0e8510371de8867bbce9..8fb7d5fa1e981efd3a86fd7485529f2e59104202 100755 (executable)
@@ -36,7 +36,7 @@
 #include "../inquiry.h"
 #include "usb_device.h"
 
-uint8_t NoSDInquiryData[] =  /* 36 */
+uint8_t NoSDInquiryData[36] =
 {
   /* LUN 0 */
   0x00,
@@ -50,7 +50,7 @@ uint8_t NoSDInquiryData[] =  /* 36 */
   'C', 'O', 'D', 'E', 'S', 'R', 'C', ' ', /* Manufacturer : 8 bytes */
   'S', 'C', 'S', 'I', '2', 'S', 'D', ' ', /* Product      : 16 Bytes */
   ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
-  '6', '.', 'X', 'X',                     /* Version      : 4 Bytes */
+  '6', '.', 'X', 'X'                      /* Version      : 4 Bytes */
 };
 
 static int8_t s2s_usbd_storage_Init(uint8_t lun);