Skip to content

Commit 243f7c4

Browse files
tmon-nordickartben
authored andcommitted
drivers: udc_dwc2: Disable control IN endpoint on timeout
DWC2 core sets DIEPCTL0 SNAK when SETUP packet is received. The CNAK bit results in device sending NAK in response to IN token sent to EP0, but it does not modify the TxFIFO in any way. The stale data in TxFIFO can then lead to "FIFO space is too low" error. Solve the issue by disabling and flushing IN endpoint 0 if previous control transfer did not finish. Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
1 parent b6cfb45 commit 243f7c4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

drivers/usb/udc/udc_dwc2.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ struct udc_dwc2_data {
140140
uint8_t setup[8];
141141
};
142142

143+
static void udc_dwc2_ep_disable(const struct device *dev,
144+
struct udc_ep_config *const cfg, bool stall);
145+
143146
#if defined(CONFIG_PINCTRL)
144147
#include <zephyr/drivers/pinctrl.h>
145148

@@ -829,6 +832,7 @@ static int dwc2_handle_evt_setup(const struct device *dev)
829832

830833
buf = udc_buf_get_all(cfg_in);
831834
if (buf) {
835+
udc_dwc2_ep_disable(dev, cfg_in, false);
832836
net_buf_unref(buf);
833837
}
834838

@@ -1557,7 +1561,8 @@ static void udc_dwc2_ep_disable(const struct device *dev,
15571561
return;
15581562
}
15591563

1560-
if (!is_iso && (dxepctl & USB_DWC2_DEPCTL_NAKSTS)) {
1564+
if (!is_iso && (dxepctl & USB_DWC2_DEPCTL_NAKSTS) &&
1565+
!(dxepctl & USB_DWC2_DEPCTL_EPENA)) {
15611566
/* Endpoint already sends forced NAKs. STALL if necessary. */
15621567
if (stall) {
15631568
dxepctl |= USB_DWC2_DEPCTL_STALL;

0 commit comments

Comments
 (0)