Skip to content

Commit 08688f7

Browse files
authored
Merge pull request #3712 from egbert-h/master
mstorage.c: fix bug in device descriptor that MAC OS enumeration failed.
2 parents 68c5269 + 0bfb881 commit 08688f7

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

components/drivers/usb/usbdevice/class/cdc_vcom.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,9 @@ ufunction_t rt_usbd_function_cdc_create(udevice_t device)
589589

590590
/* create a cdc function */
591591
func = rt_usbd_function_new(device, &dev_desc, &ops);
592-
//not support HS
593-
//rt_usbd_device_set_qualifier(device, &dev_qualifier);
592+
593+
/* support HS */
594+
rt_usbd_device_set_qualifier(device, &dev_qualifier);
594595

595596
/* allocate memory for cdc vcom data */
596597
data = (struct vcom*)rt_malloc(sizeof(struct vcom));

components/drivers/usb/usbdevice/class/hid.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct hid_s
2929
uep_t ep_in;
3030
uep_t ep_out;
3131
int status;
32-
rt_uint16_t protocol;
32+
rt_uint8_t protocol;
3333
rt_uint8_t report_buf[MAX_REPORT_SIZE];
3434
struct rt_messagequeue hid_mq;
3535
};
@@ -246,7 +246,7 @@ static struct udevice_descriptor _dev_desc =
246246
USB_DESC_LENGTH_DEVICE, //bLength;
247247
USB_DESC_TYPE_DEVICE, //type;
248248
USB_BCD_VERSION, //bcdUSB;
249-
USB_CLASS_HID, //bDeviceClass;
249+
0x0, //bDeviceClass;
250250
0x00, //bDeviceSubClass;
251251
0x00, //bDeviceProtocol;
252252
64, //bMaxPacketSize0;
@@ -266,8 +266,8 @@ static struct usb_qualifier_descriptor dev_qualifier =
266266
sizeof(dev_qualifier), //bLength
267267
USB_DESC_TYPE_DEVICEQUALIFIER, //bDescriptorType
268268
0x0200, //bcdUSB
269-
USB_CLASS_MASS_STORAGE, //bDeviceClass
270-
0x06, //bDeviceSubClass
269+
0x0, //bDeviceClass
270+
0x0, //bDeviceSubClass
271271
0x50, //bDeviceProtocol
272272
64, //bMaxPacketSize0
273273
0x01, //bNumConfigurations
@@ -347,7 +347,7 @@ const static struct uhid_comm_descriptor _hid_comm_desc =
347347
USB_DYNAMIC | USB_DIR_IN,
348348
USB_EP_ATTR_INT,
349349
0x40,
350-
0x01,
350+
0x0A,
351351
},
352352

353353
/* Endpoint Descriptor OUT */
@@ -458,6 +458,7 @@ static rt_err_t _interface_handler(ufunction_t func, ureq_t setup)
458458

459459
struct hid_s *data = (struct hid_s *) func->user_data;
460460

461+
461462
switch (setup->bRequest)
462463
{
463464
case USB_REQ_GET_DESCRIPTOR:
@@ -486,7 +487,7 @@ static rt_err_t _interface_handler(ufunction_t func, ureq_t setup)
486487
dcd_ep0_send_status(func->device->dcd);
487488
break;
488489
case USB_HID_REQ_GET_PROTOCOL:
489-
rt_usbd_ep0_write(func->device, &data->protocol,2);
490+
rt_usbd_ep0_write(func->device, &data->protocol,1);
490491
break;
491492
case USB_HID_REQ_SET_REPORT:
492493

@@ -692,8 +693,9 @@ ufunction_t rt_usbd_function_hid_create(udevice_t device)
692693

693694
/* create a cdc function */
694695
func = rt_usbd_function_new(device, &_dev_desc, &ops);
695-
//not support hs
696-
//rt_usbd_device_set_qualifier(device, &_dev_qualifier);
696+
697+
/* For high speed mode supporting */
698+
rt_usbd_device_set_qualifier(device, &dev_qualifier);
697699

698700
/* allocate memory for cdc vcom data */
699701
data = (struct hid_s*)rt_malloc(sizeof(struct hid_s));

components/drivers/usb/usbdevice/class/mstorage.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,11 @@ static rt_err_t _ep_in_handler(ufunction_t func, rt_size_t size)
610610
rt_usbd_ep_set_stall(func->device, data->ep_out);
611611
}
612612
else
613-
{
614-
rt_usbd_ep_set_stall(func->device, data->ep_in);
613+
{
614+
//rt_kprintf("warning:in stall path but not stall\n");
615+
616+
/* FIXME: Disable the operation or the disk cannot work. */
617+
//rt_usbd_ep_set_stall(func->device, data->ep_in);
615618
}
616619
data->csw_response.data_reside = 0;
617620
}
@@ -719,9 +722,22 @@ static void _cb_len_calc(ufunction_t func, struct scsi_cmd* cmd,
719722
break;
720723
}
721724
}
725+
726+
//workaround: for stability in full-speed mode
727+
else if(cmd->cmd_len == 12)
728+
{
729+
switch(cmd->type)
730+
{
731+
case COUNT:
732+
data->cb_data_size = cbw->cb[4];
733+
break;
734+
default:
735+
break;
736+
}
737+
}
722738
else
723739
{
724-
// rt_kprintf("cmd_len error %d\n", cmd->cmd_len);
740+
rt_kprintf("cmd_len error %d\n", cmd->cmd_len);
725741
}
726742
}
727743

@@ -737,7 +753,7 @@ static rt_bool_t _cbw_verify(ufunction_t func, struct scsi_cmd* cmd,
737753
data = (struct mstorage*)func->user_data;
738754
if(cmd->cmd_len != cbw->cb_len)
739755
{
740-
// rt_kprintf("cb_len error\n");
756+
rt_kprintf("cb_len error\n");
741757
cmd->cmd_len = cbw->cb_len;
742758
}
743759

@@ -768,7 +784,7 @@ static rt_bool_t _cbw_verify(ufunction_t func, struct scsi_cmd* cmd,
768784

769785
if(cbw->xfer_len < data->cb_data_size)
770786
{
771-
// rt_kprintf("xfer_len < data_size\n");
787+
rt_kprintf("xfer_len < data_size\n");
772788
data->cb_data_size = cbw->xfer_len;
773789
data->csw_response.status = 1;
774790
}

0 commit comments

Comments
 (0)