فهرست منبع

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;
 
     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;