bugfix for 183d49, add CONFIG_USBDEV_EP0_INDATA_NO_COPY

This commit is contained in:
sakumisu
2024-05-03 14:00:57 +08:00
parent 9cb992bed7
commit ccef9b92cc
2 changed files with 13 additions and 3 deletions

View File

@@ -41,6 +41,11 @@
/* Setup packet log for debug */ /* Setup packet log for debug */
// #define CONFIG_USBDEV_SETUP_LOG_PRINT // #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 */ /* Check if the input descriptor is correct */
// #define CONFIG_USBDEV_DESC_CHECK // #define CONFIG_USBDEV_DESC_CHECK

View File

@@ -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) void usbd_event_ep0_setup_complete_handler(uint8_t busid, uint8_t *psetup)
{ {
struct usb_setup_packet *setup = &g_usbd_core[busid].setup; struct usb_setup_packet *setup = &g_usbd_core[busid].setup;
uint8_t *buf;
memcpy(setup, psetup, 8); memcpy(setup, psetup, 8);
#ifdef CONFIG_USBDEV_SETUP_LOG_PRINT #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 */ /* 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); usbd_ep_set_stall(busid, USB_CONTROL_IN_EP0);
return; 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. /* 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). * 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) { if (buf != g_usbd_core[busid].ep0_data_buf) {
memcpy(g_usbd_core[busid].req_data, g_usbd_core[busid].ep0_data_buf, g_usbd_core[busid].ep0_data_buf_residue); #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 { } else {
/* use memcpy(*data, xxx, len); has copied into ep0 buffer, we do nothing */ /* use memcpy(*data, xxx, len); has copied into ep0 buffer, we do nothing */
} }