Эх сурвалжийг харах

Workaround for Windows handling USB errors when no SD card inserted

Michael McMaster 3 жил өмнө
parent
commit
8c9de484b3

+ 4 - 0
lib/SCSI2SD/CHANGELOG

@@ -1,3 +1,7 @@
+2022xxxx        6.4.14
+    - Fix firmware version displaying as "0.0" in scsi2sd-util when there is no
+    SD card inserted.
+
 20220121        6.4.13
 20220121        6.4.13
     - Fix SCSI writes with sector sizes larger than 512.
     - Fix SCSI writes with sector sizes larger than 512.
     - Fix 2Gb SD cards being detected as 1Gb
     - Fix 2Gb SD cards being detected as 1Gb

+ 1 - 1
lib/SCSI2SD/src/firmware/config.c

@@ -36,7 +36,7 @@
 
 
 #include <string.h>
 #include <string.h>
 
 
-static const uint16_t FIRMWARE_VERSION = 0x064D;
+static const uint16_t FIRMWARE_VERSION = 0x064E;
 
 
 // Optional static config
 // Optional static config
 extern uint8_t* __fixed_config;
 extern uint8_t* __fixed_config;

+ 29 - 3
lib/SCSI2SD/src/firmware/usb_device/usbd_msc_scsi.c

@@ -267,12 +267,38 @@ static int8_t SCSI_ReadCapacity10(USBD_HandleTypeDef  *pdev, uint8_t lun, uint8_
   
   
   if(((USBD_StorageTypeDef *)pdev->pUserData)->GetCapacity(lun, &hmsc->scsi_blk_nbr, &hmsc->scsi_blk_size) != 0)
   if(((USBD_StorageTypeDef *)pdev->pUserData)->GetCapacity(lun, &hmsc->scsi_blk_nbr, &hmsc->scsi_blk_size) != 0)
   {
   {
-    SCSI_SenseCode(pdev,
+    memset(hmsc->bot_data, 0, 8);
+    if (hmsc->bot_state == USBD_BOT_DATA_IN)
+    {
+        if (hmsc->bot_data_length > 0)
+        {
+            USBD_LL_Transmit (pdev, 
+                MSC_EPIN_ADDR,
+                hmsc->bot_data,
+                hmsc->bot_data_length);
+            hmsc->csw.dDataResidue -= hmsc->bot_data_length;
+            hmsc->bot_data_length = 0;
+            return 0;
+        }
+        else
+        {
+            return -1; // Time to send the error.
+        }
+    }
+    else
+    {
+        SCSI_SenseCode(pdev,
                    lun,
                    lun,
                    NOT_READY, 
                    NOT_READY, 
                    MEDIUM_NOT_PRESENT);
                    MEDIUM_NOT_PRESENT);
-    hmsc->bot_state = USBD_BOT_NO_DATA;
-    return -1;
+
+        // Don't send the error just yet. Microsoft Windows fails to detect the CSW
+        // prior to the 8 byte response is sent. Windows also insists on calling
+        // ReadCapacity even when TestUnitReady fails with MEDIUM_NOT_PRESENT
+        hmsc->bot_state = USBD_BOT_DATA_IN;
+        hmsc->bot_data_length = MIN(8, hmsc->csw.dDataResidue);
+        return 0;
+    }
   } 
   } 
   else
   else
   {
   {