Skip to content

Commit 043aa83

Browse files
jfischer-nofabiobaltieri
authored andcommitted
drivers: udc_stm32: remove wrong header and fix udc_ep_enable()
Driver includes wrong header zephyr/usb/usb_device.h and uses defines from include/zephyr/drivers/usb/usb_dc.h. Also fix udc_ep_enable() implementation in general. HAL_PCD_EP_Open() takes the ep_type parameter as uint8_t integer type and the shim driver should not just pass int type. It is recommended that drivers use ep_cfg or cfg for struct udc_ep_config, fix this as well. Signed-off-by: Johann Fischer <[email protected]>
1 parent 9ec7697 commit 043aa83

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

drivers/usb/udc/udc_stm32.c

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include <zephyr/drivers/pinctrl.h>
2121
#include <zephyr/drivers/clock_control/stm32_clock_control.h>
2222
#include <zephyr/sys/util.h>
23-
#include <zephyr/usb/usb_device.h>
2423

2524
#include "udc_common.h"
2625

@@ -636,44 +635,43 @@ static int udc_stm32_host_wakeup(const struct device *dev)
636635
return 0;
637636
}
638637

639-
static inline int eptype2hal(enum usb_dc_ep_transfer_type eptype)
640-
{
641-
switch (eptype) {
642-
case USB_DC_EP_CONTROL:
643-
return EP_TYPE_CTRL;
644-
case USB_DC_EP_ISOCHRONOUS:
645-
return EP_TYPE_ISOC;
646-
case USB_DC_EP_BULK:
647-
return EP_TYPE_BULK;
648-
case USB_DC_EP_INTERRUPT:
649-
return EP_TYPE_INTR;
650-
default:
651-
return -EINVAL;
652-
}
653-
654-
return -EINVAL;
655-
}
656-
657638
static int udc_stm32_ep_enable(const struct device *dev,
658-
struct udc_ep_config *ep)
639+
struct udc_ep_config *ep_cfg)
659640
{
660-
enum usb_dc_ep_transfer_type type = ep->attributes & USB_EP_TRANSFER_TYPE_MASK;
661641
struct udc_stm32_data *priv = udc_get_private(dev);
662642
HAL_StatusTypeDef status;
643+
uint8_t ep_type;
663644
int ret;
664645

665-
LOG_DBG("Enable ep 0x%02x", ep->addr);
646+
LOG_DBG("Enable ep 0x%02x", ep_cfg->addr);
647+
648+
switch (ep_cfg->attributes & USB_EP_TRANSFER_TYPE_MASK) {
649+
case USB_EP_TYPE_CONTROL:
650+
ep_type = EP_TYPE_CTRL;
651+
break;
652+
case USB_EP_TYPE_BULK:
653+
ep_type = EP_TYPE_BULK;
654+
break;
655+
case USB_EP_TYPE_INTERRUPT:
656+
ep_type = EP_TYPE_INTR;
657+
break;
658+
case USB_EP_TYPE_ISO:
659+
ep_type = EP_TYPE_ISOC;
660+
break;
661+
default:
662+
return -EINVAL;
663+
}
666664

667-
ret = udc_stm32_ep_mem_config(dev, ep, true);
665+
ret = udc_stm32_ep_mem_config(dev, ep_cfg, true);
668666
if (ret) {
669667
return ret;
670668
}
671669

672-
status = HAL_PCD_EP_Open(&priv->pcd, ep->addr, ep->mps,
673-
eptype2hal(type));
670+
status = HAL_PCD_EP_Open(&priv->pcd, ep_cfg->addr, ep_cfg->mps,
671+
ep_type);
674672
if (status != HAL_OK) {
675673
LOG_ERR("HAL_PCD_EP_Open failed(0x%02x), %d",
676-
ep->addr, (int)status);
674+
ep_cfg->addr, (int)status);
677675
return -EIO;
678676
}
679677

0 commit comments

Comments
 (0)