瀏覽代碼

ZuluSCSIv1.1 (GD32F205): Fix USB serial port logging on Windows

Previously USB serial number was disabled to save RAM,
but the length was left as 12. This confused Windows
and caused USB enumeration to fail.

Changed serial number to fake "1234".
This avoids Windows from guessing a new COM port number every
time the device is changed between ports.
Petteri Aimonen 11 月之前
父節點
當前提交
fdb99e2229
共有 2 個文件被更改,包括 44 次插入9 次删除
  1. 20 3
      lib/ZuluSCSI_platform_GD32F205/gd32_cdc_acm_core.c
  2. 24 6
      lib/ZuluSCSI_platform_GD32F205/usbd_msc_core.c

+ 20 - 3
lib/ZuluSCSI_platform_GD32F205/gd32_cdc_acm_core.c

@@ -232,15 +232,32 @@ static const usb_desc_str product_string =
     .unicode_string = {'Z', 'u', 'l', 'u', 'S', 'C', 'S', 'I'}
     .unicode_string = {'Z', 'u', 'l', 'u', 'S', 'C', 'S', 'I'}
 };
 };
 
 
-/* USBD serial string */
+#ifdef USB_ENABLE_SERIALNUMBER
+/* USBD serial string
+ * This gets set by serial_string_get() in GD32 SPL usbd_enum.c */
+static usb_desc_str serial_string =
+{
+    .header =
+     {
+         .bLength         = USB_STRING_LEN(12U),
+         .bDescriptorType = USB_DESCTYPE_STR,
+     }
+};
+#else
+/* Save some RAM by disabling the serial number.
+ * Note that contents must not have null bytes or Windows gets confused
+ * Having non-empty fake serial number avoids Windows recreating the
+ * device every time it moves between USB ports. */
 static const usb_desc_str serial_string =
 static const usb_desc_str serial_string =
 {
 {
     .header = 
     .header = 
      {
      {
-         .bLength         = USB_STRING_LEN(12), 
+         .bLength         = USB_STRING_LEN(4U),
          .bDescriptorType = USB_DESCTYPE_STR,
          .bDescriptorType = USB_DESCTYPE_STR,
-     }
+     },
+     .unicode_string = {'1', '2', '3', '4'}
 };
 };
+#endif
 
 
 /* USB string descriptor set */
 /* USB string descriptor set */
 void *const gd32_usbd_cdc_strings[] = 
 void *const gd32_usbd_cdc_strings[] = 

+ 24 - 6
lib/ZuluSCSI_platform_GD32F205/usbd_msc_core.c

@@ -166,14 +166,32 @@ static __ALIGN_BEGIN const usb_desc_str product_string __ALIGN_END = {
     .unicode_string = {'G', 'D', '3', '2', '-', 'U', 'S', 'B', '_', 'M', 'S', 'C'}
     .unicode_string = {'G', 'D', '3', '2', '-', 'U', 'S', 'B', '_', 'M', 'S', 'C'}
 };
 };
 
 
-/* USBD serial string */
-static __ALIGN_BEGIN const usb_desc_str serial_string __ALIGN_END = {
+#ifdef USB_ENABLE_SERIALNUMBER
+/* USBD serial string
+ * This gets set by serial_string_get() in GD32 SPL usbd_enum.c */
+static usb_desc_str serial_string =
+{
     .header =
     .header =
-    {
-        .bLength         = USB_STRING_LEN(12U),
-        .bDescriptorType = USB_DESCTYPE_STR,
-    }
+     {
+         .bLength         = USB_STRING_LEN(12U),
+         .bDescriptorType = USB_DESCTYPE_STR,
+     }
+};
+#else
+/* Save some RAM by disabling the serial number.
+ * Note that contents must not have null bytes or Windows gets confused
+ * Having non-empty fake serial number avoids Windows recreating the
+ * device every time it moves between USB ports. */
+static const usb_desc_str serial_string =
+{
+    .header =
+     {
+         .bLength         = USB_STRING_LEN(4U),
+         .bDescriptorType = USB_DESCTYPE_STR,
+     },
+     .unicode_string = {'1', '2', '3', '4'}
 };
 };
+#endif
 
 
 /* USB string descriptor */
 /* USB string descriptor */
 void *const usbd_msc_strings[] = {
 void *const usbd_msc_strings[] = {