diff options
| author | sakumisu <[email protected]> | 2024-05-03 14:00:57 +0800 |
|---|---|---|
| committer | sakumisu <[email protected]> | 2024-05-03 14:07:26 +0800 |
| commit | ccef9b92cc4a9a34bf0bd5af880398a0e66b1dc8 (patch) | |
| tree | 9c3c36883a69be3ac5f157720ef437c8afe56ba8 | |
| parent | 9cb992bed7b352b6affde48aeb22f498de54927f (diff) | |
bugfix for 183d49, add CONFIG_USBDEV_EP0_INDATA_NO_COPY
| -rw-r--r-- | cherryusb_config_template.h | 5 | ||||
| -rw-r--r-- | core/usbd_core.c | 11 |
2 files changed, 13 insertions, 3 deletions
diff --git a/cherryusb_config_template.h b/cherryusb_config_template.h index ea695b13..008ff921 100644 --- a/cherryusb_config_template.h +++ b/cherryusb_config_template.h @@ -41,6 +41,11 @@ /* Setup packet log for debug */ // #define CONFIG_USBDEV_SETUP_LOG_PRINT +/* Send ep0 in data from user buffer instead of copying into ep0 reqdata + * Please note that user buffer must be aligned with CONFIG_USB_ALIGN_SIZE +*/ +// #define CONFIG_USBDEV_EP0_INDATA_NO_COPY + /* Check if the input descriptor is correct */ // #define CONFIG_USBDEV_DESC_CHECK diff --git a/core/usbd_core.c b/core/usbd_core.c index 54bd9074..3ef0dbdf 100644 --- a/core/usbd_core.c +++ b/core/usbd_core.c @@ -1011,6 +1011,7 @@ void usbd_event_reset_handler(uint8_t busid) void usbd_event_ep0_setup_complete_handler(uint8_t busid, uint8_t *psetup) { struct usb_setup_packet *setup = &g_usbd_core[busid].setup; + uint8_t *buf; memcpy(setup, psetup, 8); #ifdef CONFIG_USBDEV_SETUP_LOG_PRINT @@ -1037,7 +1038,7 @@ void usbd_event_ep0_setup_complete_handler(uint8_t busid, uint8_t *psetup) } /* Ask installed handler to process request */ - if (!usbd_setup_request_handler(busid, setup, &g_usbd_core[busid].ep0_data_buf, &g_usbd_core[busid].ep0_data_buf_len)) { + if (!usbd_setup_request_handler(busid, setup, &buf, &g_usbd_core[busid].ep0_data_buf_len)) { usbd_ep_set_stall(busid, USB_CONTROL_IN_EP0); return; } @@ -1053,8 +1054,12 @@ void usbd_event_ep0_setup_complete_handler(uint8_t busid, uint8_t *psetup) /* use *data = xxx; g_usbd_core[busid].ep0_data_buf records real data address, we should copy data into ep0 buffer. * Why we should copy once? because some chips are not access to flash with dma if real data address is in flash address(such as ch32). */ - if (g_usbd_core[busid].ep0_data_buf != g_usbd_core[busid].req_data) { - memcpy(g_usbd_core[busid].req_data, g_usbd_core[busid].ep0_data_buf, g_usbd_core[busid].ep0_data_buf_residue); + if (buf != g_usbd_core[busid].ep0_data_buf) { +#ifdef CONFIG_USBDEV_EP0_INDATA_NO_COPY + g_usbd_core[busid].ep0_data_buf = buf; +#else + memcpy(g_usbd_core[busid].ep0_data_buf, buf, g_usbd_core[busid].ep0_data_buf_residue); +#endif } else { /* use memcpy(*data, xxx, len); has copied into ep0 buffer, we do nothing */ } |
