Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions drivers/usb/udc/udc_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,7 @@ int udc_enable(const struct device *dev)
}

data->stage = CTRL_PIPE_STAGE_SETUP;
data->setup = NULL;

ret = api->enable(dev);
if (ret == 0) {
Expand Down Expand Up @@ -1011,6 +1012,14 @@ void udc_ctrl_update_stage(const struct device *dev,
if (bi->setup && bi->ep == USB_CONTROL_EP_OUT) {
uint16_t length = udc_data_stage_length(buf);

if (data->setup) {
/* Host started new control transfer before the previous
* one finished. This was most likely due to a timeout.
* Release old setup buffer as it is no longer needed.
*/
net_buf_unref(data->setup);
}

data->setup = buf;

if (data->stage != CTRL_PIPE_STAGE_SETUP) {
Expand Down
7 changes: 6 additions & 1 deletion drivers/usb/udc/udc_dwc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@
uint8_t setup[8];
};

static void udc_dwc2_ep_disable(const struct device *dev,
struct udc_ep_config *const cfg, bool stall);

Check notice on line 144 in drivers/usb/udc/udc_dwc2.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

drivers/usb/udc/udc_dwc2.c:144 -static void udc_dwc2_ep_disable(const struct device *dev, - struct udc_ep_config *const cfg, bool stall); +static void udc_dwc2_ep_disable(const struct device *dev, struct udc_ep_config *const cfg, + bool stall);
#if defined(CONFIG_PINCTRL)
#include <zephyr/drivers/pinctrl.h>

Expand Down Expand Up @@ -801,6 +804,7 @@

buf = udc_buf_get_all(dev, USB_CONTROL_EP_IN);
if (buf) {
udc_dwc2_ep_disable(dev, udc_get_ep_cfg(dev, USB_CONTROL_EP_IN), false);
net_buf_unref(buf);
}

Expand Down Expand Up @@ -1493,8 +1497,9 @@
dxepctl_reg = dwc2_get_dxepctl_reg(dev, cfg->addr);
dxepctl = sys_read32(dxepctl_reg);

if (!is_iso && (dxepctl & USB_DWC2_DEPCTL_NAKSTS)) {
if (!is_iso && (dxepctl & USB_DWC2_DEPCTL_NAKSTS) &&
!(dxepctl & USB_DWC2_DEPCTL_EPENA)) {
/* Endpoint already sends forced NAKs. STALL if necessary. */

Check notice on line 1502 in drivers/usb/udc/udc_dwc2.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

drivers/usb/udc/udc_dwc2.c:1502 - if (!is_iso && (dxepctl & USB_DWC2_DEPCTL_NAKSTS) && - !(dxepctl & USB_DWC2_DEPCTL_EPENA)) { + if (!is_iso && (dxepctl & USB_DWC2_DEPCTL_NAKSTS) && !(dxepctl & USB_DWC2_DEPCTL_EPENA)) {
if (stall) {
dxepctl |= USB_DWC2_DEPCTL_STALL;
sys_write32(dxepctl, dxepctl_reg);
Expand Down
2 changes: 2 additions & 0 deletions subsys/usb/device_next/usbd_ch9.c
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,7 @@ int usbd_handle_ctrl_xfer(struct usbd_context *const uds_ctx,
buf, bi->ep, buf->len, bi->setup, bi->data, bi->status);

if (bi->setup && bi->ep == USB_CONTROL_EP_OUT) {
struct udc_data *data = uds_ctx->dev->data;
struct net_buf *next_buf;

if (ctrl_xfer_get_setup(uds_ctx, buf)) {
Expand All @@ -1112,6 +1113,7 @@ int usbd_handle_ctrl_xfer(struct usbd_context *const uds_ctx,

/* Remove setup packet buffer from the chain */
next_buf = net_buf_frag_del(NULL, buf);
data->setup = NULL;
if (next_buf == NULL) {
LOG_ERR("Buffer for data|status is missing");
goto ctrl_xfer_stall;
Expand Down
Loading