Jelajahi Sumber

Provide better USB Mass Storage experience with no SD card inserted.

Michael McMaster 4 tahun lalu
induk
melakukan
0b8a87e2cb

+ 5 - 0
lib/SCSI2SD/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;

+ 49 - 17
lib/SCSI2SD/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
 }