Skip to content

Commit 6c3f2da

Browse files
authored
fixed bug on macOS - pico usb device sends more data than requested by usb host (#283)
1 parent 8b1d1ee commit 6c3f2da

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

usb/device/dev_lowlevel/dev_lowlevel.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,13 @@ void usb_start_transfer(struct usb_endpoint_configuration *ep, uint8_t *buf, uin
264264
* @brief Send device descriptor to host
265265
*
266266
*/
267-
void usb_handle_device_descriptor(void) {
267+
void usb_handle_device_descriptor(volatile struct usb_setup_packet *pkt) {
268268
const struct usb_device_descriptor *d = dev_config.device_descriptor;
269269
// EP0 in
270270
struct usb_endpoint_configuration *ep = usb_get_endpoint_configuration(EP0_IN_ADDR);
271271
// Always respond with pid 1
272272
ep->next_pid = 1;
273-
usb_start_transfer(ep, (uint8_t *) d, sizeof(struct usb_device_descriptor));
273+
usb_start_transfer(ep, (uint8_t *) d, MIN(sizeof(struct usb_device_descriptor), pkt->wLength));
274274
}
275275

276276
/**
@@ -305,7 +305,7 @@ void usb_handle_config_descriptor(volatile struct usb_setup_packet *pkt) {
305305
// Send data
306306
// Get len by working out end of buffer subtract start of buffer
307307
uint32_t len = (uint32_t) buf - (uint32_t) &ep0_buf[0];
308-
usb_start_transfer(usb_get_endpoint_configuration(EP0_IN_ADDR), &ep0_buf[0], len);
308+
usb_start_transfer(usb_get_endpoint_configuration(EP0_IN_ADDR), &ep0_buf[0], MIN(len, pkt->wLength));
309309
}
310310

311311
/**
@@ -337,7 +337,7 @@ void usb_handle_string_descriptor(volatile struct usb_setup_packet *pkt) {
337337
len = usb_prepare_string_descriptor(dev_config.descriptor_strings[i - 1]);
338338
}
339339

340-
usb_start_transfer(usb_get_endpoint_configuration(EP0_IN_ADDR), &ep0_buf[0], len);
340+
usb_start_transfer(usb_get_endpoint_configuration(EP0_IN_ADDR), &ep0_buf[0], MIN(len, pkt->wLength));
341341
}
342342

343343
/**
@@ -404,7 +404,7 @@ void usb_handle_setup_packet(void) {
404404

405405
switch (descriptor_type) {
406406
case USB_DT_DEVICE:
407-
usb_handle_device_descriptor();
407+
usb_handle_device_descriptor(pkt);
408408
printf("GET DEVICE DESCRIPTOR\r\n");
409409
break;
410410

0 commit comments

Comments
 (0)