From b902669a0a8603a6427081e6ca69cabe3a9ee47a Mon Sep 17 00:00:00 2001 From: Michael McMaster Date: Sat, 29 Jan 2022 22:41:39 +1000 Subject: [PATCH] Workaround for Windows handling USB errors when no SD card inserted --- CHANGELOG | 4 ++++ src/firmware/config.c | 2 +- src/firmware/usb_device/usbd_msc_scsi.c | 32 ++++++++++++++++++++++--- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2fe7e7fb..a3857832 100644 --- 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 diff --git a/src/firmware/config.c b/src/firmware/config.c index 451ad623..3863d397 100755 --- a/src/firmware/config.c +++ b/src/firmware/config.c @@ -36,7 +36,7 @@ #include -static const uint16_t FIRMWARE_VERSION = 0x064D; +static const uint16_t FIRMWARE_VERSION = 0x064E; // Optional static config extern uint8_t* __fixed_config; diff --git a/src/firmware/usb_device/usbd_msc_scsi.c b/src/firmware/usb_device/usbd_msc_scsi.c index 9ebccb8c..9c2f139c 100755 --- a/src/firmware/usb_device/usbd_msc_scsi.c +++ b/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) { - 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 { -- 2.38.5