瀏覽代碼

GD32F205: Fix occassional problems with USB serial port

Return proper error on unknown requests.
Don't hang on received data.
Petteri Aimonen 11 月之前
父節點
當前提交
b905521523
共有 2 個文件被更改,包括 10 次插入1 次删除
  1. 1 1
      lib/ZuluSCSI_platform_GD32F205/gd32_cdc_acm_core.c
  2. 9 0
      lib/ZuluSCSI_platform_GD32F205/usb_serial.cpp

+ 1 - 1
lib/ZuluSCSI_platform_GD32F205/gd32_cdc_acm_core.c

@@ -469,7 +469,7 @@ static uint8_t cdc_acm_req (usb_dev *udev, usb_req *req)
         break;
         break;
 
 
     default:
     default:
-        break;
+        return REQ_NOTSUPP;
     }
     }
 
 
     return USBD_OK;
     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
     // check that (our) serial is the currently active class
     if ((USBD_CONFIGURED == cdc_acm.dev.cur_status) && (cdc_acm.dev.desc == &gd32_cdc_desc)) 
     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)) 
         if (1U == gd32_cdc_acm_check_ready(&cdc_acm)) 
         {
         {
             return true;
             return true;