From: Michael McMaster Date: Wed, 14 Apr 2021 00:39:17 +0000 (+1000) Subject: Provide better USB Mass Storage experience with no SD card inserted. X-Git-Tag: v6.4.1~3 X-Git-Url: http://git.codesrc.com/gitweb.cgi?a=commitdiff_plain;h=60b6c10fda89c9a69831360046a168749c9b3b04;p=SCSI2SD-V6.git Provide better USB Mass Storage experience with no SD card inserted. --- diff --git a/src/firmware/config.c b/src/firmware/config.c index e983e71e..564d5694 100755 --- a/src/firmware/config.c +++ b/src/firmware/config.c @@ -149,7 +149,12 @@ static void debugInit(void) // 10ms debug timer to capture logs over USB __TIM7_CLK_ENABLE(); htim7.Instance = TIM7; +#ifdef STM32F2xx htim7.Init.Prescaler = 10800 - 1; // 16bit. 108MHz down to 10KHz +#else + htim7.Init.Prescaler = 18000 - 1; // 16bit. 180MHz down to 10KHz +#endif + htim7.Init.CounterMode = TIM_COUNTERMODE_UP; htim7.Init.Period = 100 - 1; // 16bit. 10KHz down to 10ms. htim7.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; diff --git a/src/firmware/usb_device/usbd_msc_storage_sd.c b/src/firmware/usb_device/usbd_msc_storage_sd.c index 132d7a56..7cb0d150 100755 --- a/src/firmware/usb_device/usbd_msc_storage_sd.c +++ b/src/firmware/usb_device/usbd_msc_storage_sd.c @@ -36,7 +36,22 @@ #include "../inquiry.h" #include "usb_device.h" - +uint8_t NoSDInquiryData[] = /* 36 */ +{ + /* LUN 0 */ + 0x00, + 0x80, // Removable + 0x02, + 0x02, + 0x1F, // Standard length + 0x00, + 0x00, + 0x00, + '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 */ +}; static int8_t s2s_usbd_storage_Init(uint8_t lun); @@ -106,31 +121,48 @@ int8_t s2s_usbd_storage_GetCapacity (uint8_t lun, uint32_t *block_num, uint16_t { const S2S_TargetCfg* cfg = getUsbConfig(lun); - uint32_t capacity = getScsiCapacity( - cfg->sdSectorStart, - cfg->bytesPerSector, - cfg->scsiSectors); - - *block_num = capacity; - *block_size = cfg->bytesPerSector; - return capacity ? 0 : 1; + if (cfg->scsiId & S2S_CFG_TARGET_ENABLED) + { + uint32_t capacity = getScsiCapacity( + cfg->sdSectorStart, + cfg->bytesPerSector, + cfg->scsiSectors); + + *block_num = capacity; + *block_size = cfg->bytesPerSector; + return capacity ? 0 : 1; + } + else + { + *block_num = 0; + *block_size = 512; + return 1; + } } uint32_t s2s_usbd_storage_Inquiry (uint8_t lun, uint8_t* buf, uint8_t maxlen) { const S2S_TargetCfg* cfg = getUsbConfig(lun); - - return s2s_getStandardInquiry(cfg, buf, maxlen); + if (cfg->scsiId & S2S_CFG_TARGET_ENABLED) + { + return s2s_getStandardInquiry(cfg, buf, maxlen); + } + else + { + memcpy(buf, NoSDInquiryData, maxlen < sizeof(NoSDInquiryData) ? maxlen : sizeof(NoSDInquiryData)); + return sizeof(NoSDInquiryData); + } } int8_t s2s_usbd_storage_IsReady (uint8_t lun) { - const S2S_TargetCfg* cfg = getUsbConfig(lun); - return ( - cfg && - (blockDev.state & DISK_PRESENT) && - (blockDev.state & DISK_INITIALISED) - ) ? 0 : 1; // inverse logic + const S2S_TargetCfg* cfg = getUsbConfig(lun); + return ( + cfg && + (cfg->scsiId & S2S_CFG_TARGET_ENABLED) && + (blockDev.state & DISK_PRESENT) && + (blockDev.state & DISK_INITIALISED) + ) ? 0 : 1; // inverse logic }