From 5dfee764d68fd26646c0d3c15cc477f33cd75e32 Mon Sep 17 00:00:00 2001 From: Michael McMaster Date: Tue, 20 Apr 2021 22:45:05 +1000 Subject: [PATCH] Fix implementation of USB MSC READ FORMAT CAPACITIES command to handle no SD card inserted under windows --- src/firmware/usb_device/usbd_msc_scsi.c | 28 ++++++++++++++----- src/firmware/usb_device/usbd_msc_storage_sd.c | 4 +-- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/firmware/usb_device/usbd_msc_scsi.c b/src/firmware/usb_device/usbd_msc_scsi.c index aa0880c2..9cedc7be 100755 --- a/src/firmware/usb_device/usbd_msc_scsi.c +++ b/src/firmware/usb_device/usbd_msc_scsi.c @@ -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 diff --git a/src/firmware/usb_device/usbd_msc_storage_sd.c b/src/firmware/usb_device/usbd_msc_storage_sd.c index 7cb0d150..8fb7d5fa 100755 --- a/src/firmware/usb_device/usbd_msc_storage_sd.c +++ b/src/firmware/usb_device/usbd_msc_storage_sd.c @@ -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); -- 2.38.5