]> localhost Git - SCSI2SD-V6.git/commitdiff
Workaround for Windows handling USB errors when no SD card inserted
authorMichael McMaster <michael@codesrc.com>
Sat, 29 Jan 2022 12:41:39 +0000 (22:41 +1000)
committerMichael McMaster <michael@codesrc.com>
Sat, 29 Jan 2022 12:41:39 +0000 (22:41 +1000)
CHANGELOG
src/firmware/config.c
src/firmware/usb_device/usbd_msc_scsi.c

index 2fe7e7fb958e78f88ee79dd67ffbf9e3376f4d2a..a385783242f88993dec1be4301c0640ce2492f67 100644 (file)
--- a/CHANGELOG
+++ b/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
     - Fix SCSI writes with sector sizes larger than 512.
     - Fix 2Gb SD cards being detected as 1Gb
index 451ad623a4037bcaa542292c8803706be4d26db1..3863d3975f26ec9d2c48ecabf7b4effa6c66f3ef 100755 (executable)
@@ -36,7 +36,7 @@
 \r
 #include <string.h>\r
 \r
-static const uint16_t FIRMWARE_VERSION = 0x064D;\r
+static const uint16_t FIRMWARE_VERSION = 0x064E;\r
 \r
 // Optional static config\r
 extern uint8_t* __fixed_config;\r
index 9ebccb8c553839ba233967bbe7b33f1c37982715..9c2f139c6d14590b63b1ccf07d0d06fa2411cc9a 100755 (executable)
@@ -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)
   {
-    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,
                    NOT_READY, 
                    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
   {