Skip to content

Commit acd2fa7

Browse files
jfischer-nofabiobaltieri
authored andcommitted
drivers: udc_dwc2: fix interpretation of NUMDEVEPS and INEPS fields
The NUMDEVEPS field provides the number of endpoints in addition to the control endpoint. It is used to iterate over GHWCFG1 register value to get correct number of configured IN/OUT endpoints. To get it correctly, we need to use it internally as number including control endpoint. Interpretation of INEPS misses +1 because value 0 means 1 IN endpoint and so on. Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
1 parent b117155 commit acd2fa7

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

drivers/usb/udc/udc_dwc2.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ struct udc_dwc2_data {
6969
uint32_t max_pktcnt;
7070
uint32_t tx_len[16];
7171
unsigned int dynfifosizing : 1;
72-
/* Number of endpoints in addition to control endpoint */
72+
/* Number of endpoints including control endpoint */
7373
uint8_t numdeveps;
7474
/* Number of IN endpoints including control endpoint */
7575
uint8_t ineps;
@@ -948,7 +948,7 @@ static void dwc2_unset_unused_fifo(const struct device *dev)
948948
struct udc_dwc2_data *const priv = udc_get_private(dev);
949949
struct udc_ep_config *tmp;
950950

951-
for (uint8_t i = priv->ineps; i > 0; i--) {
951+
for (uint8_t i = priv->ineps - 1U; i > 0; i--) {
952952
tmp = udc_get_ep_cfg(dev, i | USB_EP_DIR_IN);
953953

954954
if (tmp->stat.enabled && (priv->txf_set & BIT(i))) {
@@ -1396,10 +1396,10 @@ static int udc_dwc2_init_controller(const struct device *dev)
13961396
}
13971397

13981398
/* Get the number or endpoints and IN endpoints we can use later */
1399-
priv->numdeveps = usb_dwc2_get_ghwcfg2_numdeveps(ghwcfg2);
1400-
priv->ineps = usb_dwc2_get_ghwcfg4_ineps(ghwcfg4);
1401-
LOG_DBG("Number of endpoints (NUMDEVEPS) %u", priv->numdeveps);
1402-
LOG_DBG("Number of IN endpoints (INEPS) %u", priv->ineps);
1399+
priv->numdeveps = usb_dwc2_get_ghwcfg2_numdeveps(ghwcfg2) + 1U;
1400+
priv->ineps = usb_dwc2_get_ghwcfg4_ineps(ghwcfg4) + 1U;
1401+
LOG_DBG("Number of endpoints (NUMDEVEPS + 1) %u", priv->numdeveps);
1402+
LOG_DBG("Number of IN endpoints (INEPS + 1) %u", priv->ineps);
14031403

14041404
LOG_DBG("Number of periodic IN endpoints (NUMDEVPERIOEPS) %u",
14051405
usb_dwc2_get_ghwcfg4_numdevperioeps(ghwcfg4));

0 commit comments

Comments
 (0)