feat: support custom ep0 mps

Signed-off-by: sakumisu <1203593632@qq.com>
This commit is contained in:
sakumisu
2025-10-22 20:34:22 +08:00
parent 76e7c1e163
commit dd46b8ce39
4 changed files with 66 additions and 17 deletions

View File

@@ -649,7 +649,7 @@ void USBD_IRQHandler(uint8_t busid)
memset(g_chipidea_udc[busid].in_ep, 0, sizeof(struct chipidea_ep_state) * CONFIG_USBDEV_EP_NUM);
memset(g_chipidea_udc[busid].out_ep, 0, sizeof(struct chipidea_ep_state) * CONFIG_USBDEV_EP_NUM);
usbd_event_reset_handler(busid);
chipidea_bus_reset(busid, 64);
chipidea_bus_reset(busid, g_chipidea_udc[busid].in_ep[0].ep_mps);
}
if (int_status & intr_suspend) {

View File

@@ -675,6 +675,7 @@ uint8_t usbd_get_port_speed(uint8_t busid)
int usbd_ep_open(uint8_t busid, const struct usb_endpoint_descriptor *ep)
{
uint8_t ep_idx = USB_EP_GET_IDX(ep->bEndpointAddress);
uint16_t ep_mps;
USB_ASSERT_MSG(ep_idx < (g_dwc2_udc[busid].hw_params.num_dev_ep + 1), "Ep addr %02x overflow", ep->bEndpointAddress);
@@ -682,14 +683,34 @@ int usbd_ep_open(uint8_t busid, const struct usb_endpoint_descriptor *ep)
g_dwc2_udc[busid].out_ep[ep_idx].ep_mps = USB_GET_MAXPACKETSIZE(ep->wMaxPacketSize);
g_dwc2_udc[busid].out_ep[ep_idx].ep_type = USB_GET_ENDPOINT_TYPE(ep->bmAttributes);
ep_mps = USB_GET_MAXPACKETSIZE(ep->wMaxPacketSize);
if (ep_idx == 0) {
switch (ep_mps) {
case 64:
ep_mps = EP_MPS_64;
break;
case 32:
ep_mps = EP_MPS_32;
break;
case 16:
ep_mps = EP_MPS_16;
break;
case 8:
ep_mps = EP_MPS_8;
break;
default:
ep_mps = EP_MPS_64;
break;
}
}
USB_OTG_DEV->DAINTMSK |= USB_OTG_DAINTMSK_OEPM & (uint32_t)(1UL << (16 + ep_idx));
if ((USB_OTG_OUTEP(ep_idx)->DOEPCTL & USB_OTG_DOEPCTL_USBAEP) == 0) {
USB_OTG_OUTEP(ep_idx)->DOEPCTL |= (USB_GET_MAXPACKETSIZE(ep->wMaxPacketSize) & USB_OTG_DOEPCTL_MPSIZ) |
((uint32_t)USB_GET_ENDPOINT_TYPE(ep->bmAttributes) << 18) |
USB_OTG_DIEPCTL_SD0PID_SEVNFRM |
USB_OTG_DOEPCTL_USBAEP;
}
USB_OTG_OUTEP(ep_idx)->DOEPCTL |= (ep_mps & USB_OTG_DOEPCTL_MPSIZ) |
((uint32_t)USB_GET_ENDPOINT_TYPE(ep->bmAttributes) << 18) |
USB_OTG_DIEPCTL_SD0PID_SEVNFRM |
USB_OTG_DOEPCTL_USBAEP;
} else {
uint16_t fifo_size;
if (ep_idx == 0) {
@@ -703,14 +724,34 @@ int usbd_ep_open(uint8_t busid, const struct usb_endpoint_descriptor *ep)
g_dwc2_udc[busid].in_ep[ep_idx].ep_mps = USB_GET_MAXPACKETSIZE(ep->wMaxPacketSize);
g_dwc2_udc[busid].in_ep[ep_idx].ep_type = USB_GET_ENDPOINT_TYPE(ep->bmAttributes);
ep_mps = USB_GET_MAXPACKETSIZE(ep->wMaxPacketSize);
if (ep_idx == 0) {
switch (ep_mps) {
case 64:
ep_mps = EP_MPS_64;
break;
case 32:
ep_mps = EP_MPS_32;
break;
case 16:
ep_mps = EP_MPS_16;
break;
case 8:
ep_mps = EP_MPS_8;
break;
default:
ep_mps = EP_MPS_64;
break;
}
}
USB_OTG_DEV->DAINTMSK |= USB_OTG_DAINTMSK_IEPM & (uint32_t)(1UL << ep_idx);
if ((USB_OTG_INEP(ep_idx)->DIEPCTL & USB_OTG_DIEPCTL_USBAEP) == 0) {
USB_OTG_INEP(ep_idx)->DIEPCTL |= (USB_GET_MAXPACKETSIZE(ep->wMaxPacketSize) & USB_OTG_DIEPCTL_MPSIZ) |
((uint32_t)USB_GET_ENDPOINT_TYPE(ep->bmAttributes) << 18) | (ep_idx << 22) |
USB_OTG_DIEPCTL_SD0PID_SEVNFRM |
USB_OTG_DIEPCTL_USBAEP;
}
USB_OTG_INEP(ep_idx)->DIEPCTL |= (ep_mps & USB_OTG_DIEPCTL_MPSIZ) |
((uint32_t)USB_GET_ENDPOINT_TYPE(ep->bmAttributes) << 18) | (ep_idx << 22) |
USB_OTG_DIEPCTL_SD0PID_SEVNFRM |
USB_OTG_DIEPCTL_USBAEP;
dwc2_flush_txfifo(busid, ep_idx);
}
return 0;
@@ -1046,7 +1087,7 @@ void USBD_IRQHandler(uint8_t busid)
usbd_event_ep_out_complete_handler(busid, ep_idx, g_dwc2_udc[busid].out_ep[ep_idx].actual_xfer_len);
}
}
// clang-format off
// clang-format off
process_setup:
// clang-format on
if ((epint & USB_OTG_DOEPINT_STUP) == USB_OTG_DOEPINT_STUP) {

View File

@@ -307,7 +307,7 @@ void USBD_IRQHandler(uint8_t busid)
memset(g_hpm_udc[busid].in_ep, 0, sizeof(struct hpm_ep_state) * USB_NUM_BIDIR_ENDPOINTS);
memset(g_hpm_udc[busid].out_ep, 0, sizeof(struct hpm_ep_state) * USB_NUM_BIDIR_ENDPOINTS);
usbd_event_reset_handler(busid);
usb_device_bus_reset(handle, 64);
usb_device_bus_reset(handle, g_hpm_udc[busid].in_ep[0].ep_mps);
}
if (int_status & intr_suspend) {