Skip to content

Commit 3ed9dc3

Browse files
Emil Obalskijhedberg
authored andcommitted
usb: Fix for set/reset endpoints
setting/resetting endpoints is required when switching to alternate interfaces. This is a common operation for usb audio class. When audio device is enumerated host invokes set_interface request to alternate with 0 endpoints associated. That operation lead to disable never enabled endpoints. With previous solution error message will appear. This commit limits error messages to be present only if endpoint was configured/enabled before and there was a problem when trying to configure/enable it for the first time. * Kinetis driver was updated with return error value when ep was already configured/enabled. * nxp driver updated with return error value when ep was already enabled * sam0 driver updated with return codes instead of magic numbers. This is fix patch to #21741 Signed-off-by: Emil Obalski <[email protected]>
1 parent 82a6208 commit 3ed9dc3

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

drivers/usb/device/usb_dc_kinetis.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ int usb_dc_ep_configure(const struct usb_dc_ep_cfg_data * const cfg)
341341
if (ep_idx && (dev_data.ep_ctrl[ep_idx].status.in_enabled ||
342342
dev_data.ep_ctrl[ep_idx].status.out_enabled)) {
343343
LOG_WRN("endpoint already configured");
344-
return -EBUSY;
344+
return -EALREADY;
345345
}
346346

347347
LOG_DBG("ep %x, mps %d, type %d", cfg->ep_addr, cfg->ep_mps,
@@ -531,7 +531,7 @@ int usb_dc_ep_enable(const u8_t ep)
531531
if (ep_idx && (dev_data.ep_ctrl[ep_idx].status.in_enabled ||
532532
dev_data.ep_ctrl[ep_idx].status.out_enabled)) {
533533
LOG_WRN("endpoint 0x%x already enabled", ep);
534-
return -EBUSY;
534+
return -EALREADY;
535535
}
536536

537537
if (EP_ADDR2DIR(ep) == USB_EP_DIR_OUT) {

drivers/usb/device/usb_dc_mcux_ehci.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ int usb_dc_ep_enable(const u8_t ep)
232232
}
233233
if (s_Device.eps[ep_abs_idx].ep_occupied) {
234234
LOG_WRN("endpoint 0x%x already enabled", ep);
235-
return -EBUSY;
235+
return -EALREADY;
236236
}
237237

238238
if ((EP_ADDR2IDX(ep) != USB_CONTROL_ENDPOINT) && (EP_ADDR2DIR(ep) == USB_EP_DIR_OUT)) {

drivers/usb/device/usb_dc_sam0.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ int usb_dc_ep_enable(const u8_t ep)
494494

495495
if (ep_num >= USB_NUM_ENDPOINTS) {
496496
LOG_ERR("endpoint index/address out of range");
497-
return -1;
497+
return -EINVAL;
498498
}
499499

500500
if (for_in) {
@@ -519,7 +519,7 @@ int usb_dc_ep_disable(u8_t ep)
519519

520520
if (ep_num >= USB_NUM_ENDPOINTS) {
521521
LOG_ERR("endpoint index/address out of range");
522-
return -1;
522+
return -EINVAL;
523523
}
524524

525525
endpoint->EPINTENCLR.reg = USB_DEVICE_EPINTENCLR_TRCPT0

subsys/usb/usb_device.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ static bool usb_get_descriptor(u16_t type_index, u16_t lang_id,
467467
static bool set_endpoint(const struct usb_ep_descriptor *ep_desc)
468468
{
469469
struct usb_dc_ep_cfg_data ep_cfg;
470+
int ret;
470471

471472
ep_cfg.ep_addr = ep_desc->bEndpointAddress;
472473
ep_cfg.ep_mps = sys_le16_to_cpu(ep_desc->wMaxPacketSize);
@@ -480,12 +481,20 @@ static bool set_endpoint(const struct usb_ep_descriptor *ep_desc)
480481
LOG_DBG("Set endpoint 0x%x type %u MPS %u",
481482
ep_cfg.ep_addr, ep_cfg.ep_type, ep_cfg.ep_mps);
482483

483-
if (usb_dc_ep_configure(&ep_cfg) < 0) {
484-
LOG_WRN("Failed to configure endpoint 0x%02x", ep_cfg.ep_addr);
484+
ret = usb_dc_ep_configure(&ep_cfg);
485+
if (ret == -EALREADY) {
486+
LOG_WRN("Endpoint 0x%02x already configured", ep_cfg.ep_addr);
487+
} else if (ret) {
488+
LOG_ERR("Failed to configure endpoint 0x%02x", ep_cfg.ep_addr);
489+
return false;
485490
}
486491

487-
if (usb_dc_ep_enable(ep_cfg.ep_addr) < 0) {
488-
LOG_WRN("Failed to enable endpoint 0x%02x", ep_cfg.ep_addr);
492+
ret = usb_dc_ep_enable(ep_cfg.ep_addr);
493+
if (ret == -EALREADY) {
494+
LOG_WRN("Endpoint 0x%02x already enabled", ep_cfg.ep_addr);
495+
} else if (ret) {
496+
LOG_ERR("Failed to enable endpoint 0x%02x", ep_cfg.ep_addr);
497+
return false;
489498
}
490499

491500
usb_dev.configured = true;
@@ -506,6 +515,7 @@ static bool set_endpoint(const struct usb_ep_descriptor *ep_desc)
506515
static bool reset_endpoint(const struct usb_ep_descriptor *ep_desc)
507516
{
508517
struct usb_dc_ep_cfg_data ep_cfg;
518+
int ret;
509519

510520
ep_cfg.ep_addr = ep_desc->bEndpointAddress;
511521
ep_cfg.ep_type = ep_desc->bmAttributes;
@@ -519,7 +529,10 @@ static bool reset_endpoint(const struct usb_ep_descriptor *ep_desc)
519529

520530
usb_cancel_transfer(ep_cfg.ep_addr);
521531

522-
if (usb_dc_ep_disable(ep_cfg.ep_addr) < 0) {
532+
ret = usb_dc_ep_disable(ep_cfg.ep_addr);
533+
if (ret == -EALREADY) {
534+
LOG_WRN("Endpoint 0x%02x already disabled", ep_cfg.ep_addr);
535+
} else if (ret) {
523536
LOG_ERR("Failed to disable endpoint 0x%02x", ep_cfg.ep_addr);
524537
return false;
525538
}

0 commit comments

Comments
 (0)