Browse Source

Merge branch 'main' into feature/common-file-update

John Morio Sakaguchi 11 months ago
parent
commit
8c83ae4dbb

+ 7 - 2
lib/ZuluSCSI_platform_GD32F205/ZuluSCSI_platform.cpp

@@ -47,6 +47,10 @@ bool g_moved_select_in = false;
 // hw_config.cpp c functions
 #include "platform_hw_config.h"
 
+// usb_log_poll() is called through function pointer to
+// avoid including USB in SD card bootloader.
+static void (*g_usb_log_poll_func)(void);
+static void usb_log_poll();
 
 
 /*************************/
@@ -396,6 +400,7 @@ void platform_late_init()
 
     // Initialize usb for CDC serial output
     usb_serial_init();
+    g_usb_log_poll_func = &usb_log_poll;
 
     logmsg("Platform: ", g_platform_name);
     logmsg("FW Version: ", g_log_firmwareversion);
@@ -617,7 +622,7 @@ void show_hardfault(uint32_t *sp)
 
     while (1)
     {
-        usb_log_poll();
+        if (g_usb_log_poll_func) g_usb_log_poll_func();
         // Flash the crash address on the LED
         // Short pulse means 0, long pulse means 1
         int base_delay = 1000;
@@ -690,7 +695,7 @@ void __assert_func(const char *file, int line, const char *func, const char *exp
 
     while(1)
     {
-        usb_log_poll();
+        if (g_usb_log_poll_func) g_usb_log_poll_func();
         LED_OFF();
         for (int j = 0; j < 1000; j++) delay_ns(100000);
         LED_ON();

+ 21 - 4
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'}
 };
 
-/* 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 =
 {
     .header = 
      {
-         .bLength         = USB_STRING_LEN(12), 
+         .bLength         = USB_STRING_LEN(4U),
          .bDescriptorType = USB_DESCTYPE_STR,
-     }
+     },
+     .unicode_string = {'1', '2', '3', '4'}
 };
+#endif
 
 /* USB string descriptor set */
 void *const gd32_usbd_cdc_strings[] = 
@@ -452,7 +469,7 @@ static uint8_t cdc_acm_req (usb_dev *udev, usb_req *req)
         break;
 
     default:
-        break;
+        return REQ_NOTSUPP;
     }
 
     return USBD_OK;

+ 9 - 0
lib/ZuluSCSI_platform_GD32F205/usb_serial.cpp

@@ -52,6 +52,15 @@ bool usb_serial_ready(void)
     // check that (our) serial is the currently active class
     if ((USBD_CONFIGURED == cdc_acm.dev.cur_status) && (cdc_acm.dev.desc == &gd32_cdc_desc)) 
     {
+        gd32_usb_cdc_handler *cdc = (gd32_usb_cdc_handler *)cdc_acm.dev.class_data[CDC_COM_INTERFACE];
+        if (cdc->packet_receive)
+        {
+            // Discard any received data.
+            // Otherwise it queues up on the host side and can cause the port to hang.
+            cdc->packet_receive = 0;
+            gd32_cdc_acm_data_receive(&cdc_acm);
+        }
+
         if (1U == gd32_cdc_acm_check_ready(&cdc_acm)) 
         {
             return true;

+ 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'}
 };
 
-/* 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 =
-    {
-        .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 */
 void *const usbd_msc_strings[] = {

+ 1 - 1
src/ZuluSCSI_config.h

@@ -28,7 +28,7 @@
 #include <ZuluSCSI_platform_config.h>
 
 // Use variables for version number
-#define FW_VER_NUM      "24.11.29"
+#define FW_VER_NUM      "24.12.02"
 #define FW_VER_SUFFIX   "devel"
 
 #define DEF_STRINGFY(DEF) STRINGFY(DEF)