Skip to content

Commit 0d02cdc

Browse files
zeonchewkartben
authored andcommitted
drivers: udc_ambiq: defer enqueue event if the endpoint is stalled
Ambiq USB HAL do not expect endpoint transaction request when an endpoint is stalled. This commit addresses this behavior in shim driver by checking for endpoint's stall status when enqueue request is received, and defer it until endpoint stall is cleared. Signed-off-by: Chew Zeh Yang <[email protected]>
1 parent 0bb3a1c commit 0d02cdc

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

drivers/usb/udc/udc_ambiq.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,10 @@ static int udc_ambiq_ep_enqueue(const struct device *dev, struct udc_ep_config *
265265
udc_ambiq_ep_xfer_complete_callback(dev, USB_CONTROL_EP_IN, 0, 0, NULL);
266266
return 0;
267267
}
268-
k_msgq_put(&drv_msgq, &evt, K_NO_WAIT);
268+
269+
if (!ep_cfg->stat.halted) {
270+
k_msgq_put(&drv_msgq, &evt, K_NO_WAIT);
271+
}
269272

270273
return 0;
271274
}
@@ -299,6 +302,9 @@ static int udc_ambiq_ep_set_halt(const struct device *dev, struct udc_ep_config
299302
LOG_DBG("Halt ep 0x%02x", ep_cfg->addr);
300303

301304
am_hal_usb_ep_stall(priv->usb_handle, ep_cfg->addr);
305+
if (USB_EP_GET_IDX(ep_cfg->addr)) {
306+
ep_cfg->stat.halted = true;
307+
}
302308

303309
return 0;
304310
}
@@ -311,6 +317,17 @@ static int udc_ambiq_ep_clear_halt(const struct device *dev, struct udc_ep_confi
311317

312318
am_hal_usb_ep_clear_stall(priv->usb_handle, ep_cfg->addr);
313319

320+
ep_cfg->stat.halted = false;
321+
322+
/* Resume queued transfer if any */
323+
if (udc_buf_peek(dev, ep_cfg->addr)) {
324+
struct udc_ambiq_event evt = {
325+
.ep = ep_cfg->addr,
326+
.type = UDC_AMBIQ_EVT_XFER,
327+
};
328+
k_msgq_put(&drv_msgq, &evt, K_NO_WAIT);
329+
}
330+
314331
return 0;
315332
}
316333

0 commit comments

Comments
 (0)