From a8fb71bed75148cd16b43e5b47790c106d30967c Mon Sep 17 00:00:00 2001 From: sakumisu <1203593632@qq.com> Date: Fri, 8 Jul 2022 22:33:05 +0800 Subject: [PATCH] update ep config --- port/ch32/usb_dc_usbfs.c | 4 +++- port/ch32/usb_dc_usbhs.c | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/port/ch32/usb_dc_usbfs.c b/port/ch32/usb_dc_usbfs.c index f8258f71..9c9bd055 100644 --- a/port/ch32/usb_dc_usbfs.c +++ b/port/ch32/usb_dc_usbfs.c @@ -106,9 +106,11 @@ int usbd_ep_open(const struct usbd_endpoint_cfg *ep_cfg) if (USB_EP_DIR_IS_OUT(ep_cfg->ep_addr)) { g_ch32_usbfs_udc.out_ep[ep_idx].ep_mps = ep_cfg->ep_mps; g_ch32_usbfs_udc.out_ep[ep_idx].ep_type = ep_cfg->ep_type; + USB_SET_RX_CTRL(ep_idx, USBFS_UEP_R_RES_ACK | USBFS_UEP_AUTO_TOG); } else { g_ch32_usbfs_udc.in_ep[ep_idx].ep_mps = ep_cfg->ep_mps; g_ch32_usbfs_udc.in_ep[ep_idx].ep_type = ep_cfg->ep_type; + USB_SET_TX_CTRL(ep_idx, USBFS_UEP_T_RES_NAK | USBFS_UEP_AUTO_TOG); } return 0; } @@ -306,7 +308,7 @@ void USBD_IRQHandler(void) for (uint8_t ep_idx = 1; ep_idx < USB_NUM_BIDIR_ENDPOINTS; ep_idx++) { USB_SET_TX_LEN(ep_idx, 0); USB_SET_TX_CTRL(ep_idx, USBFS_UEP_T_RES_NAK | USBFS_UEP_AUTO_TOG); - USB_SET_RX_CTRL(ep_idx, USBFS_UEP_R_RES_ACK | USBFS_UEP_AUTO_TOG); + USB_SET_RX_CTRL(ep_idx, USBFS_UEP_R_RES_NAK | USBFS_UEP_AUTO_TOG); } usbd_event_notify_handler(USBD_EVENT_RESET, NULL); diff --git a/port/ch32/usb_dc_usbhs.c b/port/ch32/usb_dc_usbhs.c index 2a43ac42..a2565c9d 100644 --- a/port/ch32/usb_dc_usbhs.c +++ b/port/ch32/usb_dc_usbhs.c @@ -119,10 +119,12 @@ int usbd_ep_open(const struct usbd_endpoint_cfg *ep_cfg) g_ch32_usbhs_udc.out_ep[ep_idx].ep_mps = ep_cfg->ep_mps; g_ch32_usbhs_udc.out_ep[ep_idx].ep_type = ep_cfg->ep_type; USBHS_DEVICE->ENDP_CONFIG |= (1 << (ep_idx + 16)); + USB_SET_RX_CTRL(ep_idx, USBHS_EP_R_RES_ACK | USBHS_EP_R_TOG_0 | USBHS_EP_R_AUTOTOG); } else { g_ch32_usbhs_udc.in_ep[ep_idx].ep_mps = ep_cfg->ep_mps; g_ch32_usbhs_udc.in_ep[ep_idx].ep_type = ep_cfg->ep_type; USBHS_DEVICE->ENDP_CONFIG |= (1 << (ep_idx)); + USB_SET_TX_CTRL(ep_idx, USBHS_EP_T_RES_NAK | USBHS_EP_T_TOG_0 | USBHS_EP_T_AUTOTOG); } USB_SET_MAX_LEN(ep_idx, ep_cfg->ep_mps); return 0; @@ -185,7 +187,7 @@ int usbd_ep_write(const uint8_t ep, const uint8_t *data, uint32_t data_len, uint } else { USB_SET_TX_LEN(ep_idx, 0); USB_SET_TX_CTRL(ep_idx, (USB_GET_TX_CTRL(ep_idx) & ~USBHS_EP_T_RES_MASK) | USBHS_EP_T_RES_ACK); - USB_SET_TX_CTRL(ep_idx, epx_data_toggle[ep_idx - 1] ? USBHS_EP_T_TOG_1 : USBHS_EP_T_TOG_0); + USB_SET_TX_CTRL(ep_idx, USB_GET_TX_CTRL(ep_idx) | epx_data_toggle[ep_idx - 1] ? USBHS_EP_T_TOG_1 : USBHS_EP_T_TOG_0); epx_data_toggle[ep_idx - 1] ^= 1; } return 0; @@ -206,7 +208,7 @@ int usbd_ep_write(const uint8_t ep, const uint8_t *data, uint32_t data_len, uint memcpy(&g_ch32_usbhs_udc.ep_databuf[ep_idx - 1][512], data, data_len); USB_SET_TX_CTRL(ep_idx, (USB_GET_TX_CTRL(ep_idx) & ~(USBHS_EP_T_RES_MASK | USBHS_EP_T_TOG_MASK)) | USBHS_EP_T_RES_ACK); - USB_SET_TX_CTRL(ep_idx, epx_data_toggle[ep_idx - 1] ? USBHS_EP_T_TOG_1 : USBHS_EP_T_TOG_0); + USB_SET_TX_CTRL(ep_idx, USB_GET_TX_CTRL(ep_idx) | epx_data_toggle[ep_idx - 1] ? USBHS_EP_T_TOG_1 : USBHS_EP_T_TOG_0); epx_data_toggle[ep_idx - 1] ^= 1; } if (ret_bytes) { @@ -308,7 +310,7 @@ void USBD_IRQHandler(void) for (uint8_t ep_idx = 1; ep_idx < USB_NUM_BIDIR_ENDPOINTS; ep_idx++) { USB_SET_TX_LEN(ep_idx, 0); USB_SET_TX_CTRL(ep_idx, USBHS_EP_T_AUTOTOG | USBHS_EP_T_RES_NAK); // autotog does not work - USB_SET_RX_CTRL(ep_idx, USBHS_EP_R_AUTOTOG | USBHS_EP_R_RES_ACK); + USB_SET_RX_CTRL(ep_idx, USBHS_EP_R_AUTOTOG | USBHS_EP_R_RES_NAK); epx_data_toggle[ep_idx - 1] = false; }