瀏覽代碼

Merge pull request #1126 from uestczyh222/master

 [USB Device]fix an error on msc
Bernard Xiong 7 年之前
父節點
當前提交
31151a775a
共有 2 個文件被更改,包括 8 次插入3 次删除
  1. 6 2
      components/drivers/usb/usbdevice/class/mstorage.c
  2. 2 1
      components/drivers/usb/usbdevice/core/core.c

+ 6 - 2
components/drivers/usb/usbdevice/class/mstorage.c

@@ -954,7 +954,6 @@ static rt_err_t _function_enable(ufunction_t func)
 {
 {
     struct mstorage *data;
     struct mstorage *data;
     RT_ASSERT(func != RT_NULL);
     RT_ASSERT(func != RT_NULL);
-
     RT_DEBUG_LOG(RT_DEBUG_USB, ("Mass storage function enabled\n"));
     RT_DEBUG_LOG(RT_DEBUG_USB, ("Mass storage function enabled\n"));
     data = (struct mstorage*)func->user_data;   
     data = (struct mstorage*)func->user_data;   
 
 
@@ -1027,7 +1026,12 @@ static rt_err_t _function_disable(ufunction_t func)
         rt_free(data->ep_out->buffer);
         rt_free(data->ep_out->buffer);
         data->ep_out->buffer = RT_NULL;
         data->ep_out->buffer = RT_NULL;
     }
     }
-
+    if(data->disk != RT_NULL)
+    {
+        rt_device_close(data->disk);
+        data->disk = RT_NULL;
+    }
+    
     data->status = STAT_CBW;
     data->status = STAT_CBW;
     
     
     return RT_EOK;
     return RT_EOK;

+ 2 - 1
components/drivers/usb/usbdevice/core/core.c

@@ -2144,8 +2144,9 @@ static void rt_usbd_thread_entry(void* parameter)
             break;
             break;
         case USB_MSG_RESET:            
         case USB_MSG_RESET:            
             RT_DEBUG_LOG(RT_DEBUG_USB, ("reset %d\n", device->state));
             RT_DEBUG_LOG(RT_DEBUG_USB, ("reset %d\n", device->state));
-            if (device->state == USB_STATE_ADDRESS)
+            if (device->state == USB_STATE_ADDRESS || device->state == USB_STATE_CONFIGURED)
                 _stop_notify(device);
                 _stop_notify(device);
+            device->state = USB_STATE_NOTATTACHED;
             break;
             break;
         case USB_MSG_PLUG_IN:
         case USB_MSG_PLUG_IN:
             device->state = USB_STATE_ATTACHED;
             device->state = USB_STATE_ATTACHED;