diff options
| author | sakumisu <[email protected]> | 2021-11-16 10:27:38 +0800 |
|---|---|---|
| committer | sakumisu <[email protected]> | 2021-11-16 10:27:38 +0800 |
| commit | 0b056ae3fda33d003dca8c7661b7f177f68beaf1 (patch) | |
| tree | 18f7a85a56123cdcbbad04a2d74b16aa1c681ba6 | |
| parent | 10da78cb0bc0fd5b7d247ce16488fcb66d18a9b5 (diff) | |
fix zlp process, when ep0_data_len is zero
| -rw-r--r-- | core/usbd_core.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/core/usbd_core.c b/core/usbd_core.c index 24e3c07e..47929088 100644 --- a/core/usbd_core.c +++ b/core/usbd_core.c @@ -964,16 +964,13 @@ static void usbd_send_to_host(uint16_t len) * last chunk is wMaxPacketSize long, to indicate the last
* packet.
*/
- /* Send less data as requested during the Setup stage */
- if ((!usbd_core_cfg.ep0_data_buf_residue) && (len > usbd_core_cfg.ep0_data_buf_len)) {
- /* Transfers a zero-length packet */
- if (!(usbd_core_cfg.ep0_data_buf_len % USB_CTRL_EP_MPS)) {
- USBD_LOG_DBG("send zlp\r\n");
- usbd_core_cfg.zlp_flag = true;
- }
+ if ((!usbd_core_cfg.ep0_data_buf_residue) && (usbd_core_cfg.ep0_data_buf_len >= USB_CTRL_EP_MPS) && !(usbd_core_cfg.ep0_data_buf_len % USB_CTRL_EP_MPS)) {
+ /* Transfers a zero-length packet next*/
+ usbd_core_cfg.zlp_flag = true;
}
} else {
usbd_core_cfg.zlp_flag = false;
+ USBD_LOG_DBG("send zlp\r\n");
if (usbd_ep_write(USB_CONTROL_IN_EP0, NULL, 0, NULL) < 0) {
USBD_LOG_ERR("USB write zlp failed\r\n");
return;
@@ -1015,8 +1012,6 @@ static void usbd_ep0_setup_handler(void) if (setup->wLength &&
setup->bmRequestType_b.Dir == USB_REQUEST_HOST_TO_DEVICE) {
USBD_LOG_DBG("prepare to out data\r\n");
- /*set ep ack to recv next data*/
- usbd_ep_read(USB_CONTROL_OUT_EP0, NULL, 0, NULL);
return;
}
@@ -1084,6 +1079,7 @@ static void usbd_ep0_out_handler(void) USBD_LOG_ERR("ep0_data_buf_residue is not zero\r\n");
}
}
+
static void usbd_ep0_in_handler(void)
{
struct usb_setup_packet *setup = &usbd_core_cfg.setup;
@@ -1091,6 +1087,8 @@ static void usbd_ep0_in_handler(void) /* Send more data if available */
if (usbd_core_cfg.ep0_data_buf_residue != 0 || usbd_core_cfg.zlp_flag == true) {
usbd_send_to_host(setup->wLength);
+ } else {
+ /*ep0 tx has completed,and no data to send,so do nothing*/
}
}
|
