usb: device_next: respect bMaxPacketSize0 in control transfers
Only the device operating at high speed has bMaxPacketSize0 set to 64 bytes, the device operating at other speeds may have a different value. For full speed, use the value from the full speed descriptor. Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This commit is contained in:
parent
3d86360c33
commit
f5a3f90a68
@ -59,7 +59,20 @@ static void usbd_ep_ctrl_set_zlp(struct usbd_context *const uds_ctx,
|
||||
struct net_buf *const buf)
|
||||
{
|
||||
struct usb_setup_packet *setup = usbd_get_setup_pkt(uds_ctx);
|
||||
struct usb_device_descriptor *desc = uds_ctx->fs_desc;
|
||||
size_t min_len = MIN(setup->wLength, buf->len);
|
||||
uint8_t mps0 = 0;
|
||||
|
||||
switch (usbd_bus_speed(uds_ctx)) {
|
||||
case USBD_SPEED_FS:
|
||||
mps0 = desc->bMaxPacketSize0;
|
||||
break;
|
||||
case USBD_SPEED_HS:
|
||||
mps0 = USB_CONTROL_EP_MPS;
|
||||
break;
|
||||
default:
|
||||
__ASSERT(false, "Cannot determine bMaxPacketSize0 (unsupported speed)");
|
||||
}
|
||||
|
||||
if (buf->len == 0) {
|
||||
return;
|
||||
@ -70,7 +83,7 @@ static void usbd_ep_ctrl_set_zlp(struct usbd_context *const uds_ctx,
|
||||
* last chunk is wMaxPacketSize long, to indicate the last
|
||||
* packet.
|
||||
*/
|
||||
if (setup->wLength > min_len && !(min_len % USB_CONTROL_EP_MPS)) {
|
||||
if (setup->wLength > min_len && !(min_len % mps0)) {
|
||||
/*
|
||||
* Transfer length is less as requested by wLength and
|
||||
* is multiple of wMaxPacketSize.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user