]> localhost Git - SCSI2SD-V6.git/commitdiff
Provide better USB Mass Storage experience with no SD card inserted.
authorMichael McMaster <michael@codesrc.com>
Wed, 14 Apr 2021 00:39:17 +0000 (10:39 +1000)
committerMichael McMaster <michael@codesrc.com>
Wed, 14 Apr 2021 00:39:17 +0000 (10:39 +1000)
src/firmware/config.c
src/firmware/usb_device/usbd_msc_storage_sd.c

index e983e71eb03e55517f4922d1727b143aeafe3dfb..564d56942737760d8febfa6f9ce34523be07e5c4 100755 (executable)
@@ -149,7 +149,12 @@ static void debugInit(void)
        // 10ms debug timer to capture logs over USB\r
        __TIM7_CLK_ENABLE();\r
        htim7.Instance = TIM7;\r
+#ifdef STM32F2xx\r
        htim7.Init.Prescaler = 10800 - 1; // 16bit. 108MHz down to 10KHz\r
+#else\r
+       htim7.Init.Prescaler = 18000 - 1; // 16bit. 180MHz down to 10KHz\r
+#endif\r
+\r
        htim7.Init.CounterMode = TIM_COUNTERMODE_UP;\r
        htim7.Init.Period = 100 - 1; // 16bit. 10KHz down to 10ms.\r
        htim7.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;\r
index 132d7a561bd87060ca757752519039c1b0d09372..7cb0d150cd3f20093c9a0e8510371de8867bbce9 100755 (executable)
 #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
 }