From aaa7697cfcd622a8d6ea4e5a30b5f2bc25cd77e9 Mon Sep 17 00:00:00 2001 From: arighi Date: Wed, 22 Sep 2010 10:18:31 +0000 Subject: [PATCH] STM32: USB: support EP0 read/write operations via standard interface Allow to submit EP0 read/write requests using the standard interface usb_ep_read/write(). git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4256 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/cpu/cortex-m3/drv/usb_stm32.c | 39 ++++++++++++++++------------ 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/bertos/cpu/cortex-m3/drv/usb_stm32.c b/bertos/cpu/cortex-m3/drv/usb_stm32.c index 52f208dc..eff625a4 100644 --- a/bertos/cpu/cortex-m3/drv/usb_stm32.c +++ b/bertos/cpu/cortex-m3/drv/usb_stm32.c @@ -1098,20 +1098,23 @@ ssize_t usb_ep_read(int ep, void *buffer, ssize_t size) { int ep_num = USB_EpLogToPhysAdd(ep); - if (UNLIKELY(!size)) - return 0; - size = MIN(size, USB_RX_MAX_SIZE); - rx_done = false; - rx_size = 0; - /* Non-blocking read for EP0 */ if (ep_num == CTRL_ENP_OUT) { size = usb_size(size, setup_packet.wLength); - __usb_ep_write(ep_num, buffer, size, - USB_StatusHandler); + if (!size) + USB_StatusHandler(ep_num); + else + __usb_ep_read(ep_num, buffer, size, + USB_StatusHandler); return size; } + if (UNLIKELY(!size)) + return 0; + size = MIN(size, USB_RX_MAX_SIZE); + rx_done = false; + rx_size = 0; + /* Blocking read */ __usb_ep_read(ep_num, buffer, size, usb_ep_read_complete); while (!rx_done) @@ -1140,20 +1143,24 @@ ssize_t usb_ep_write(int ep, const void *buffer, ssize_t size) { int ep_num = USB_EpLogToPhysAdd(ep); - if (UNLIKELY(!size)) - return 0; - size = MIN(size, USB_TX_MAX_SIZE); - tx_done = false; - tx_size = 0; - /* Non-blocking write for EP0 */ if (ep_num == CTRL_ENP_IN) { size = usb_size(size, setup_packet.wLength); - __usb_ep_write(ep_num, buffer, size, - USB_StatusHandler); + LOG_INFO("%s: size = %d\n", __func__, size); + if (!size) + USB_StatusHandler(ep_num); + else + __usb_ep_write(ep_num, buffer, size, + USB_StatusHandler); return size; } + if (UNLIKELY(!size)) + return 0; + size = MIN(size, USB_TX_MAX_SIZE); + tx_done = false; + tx_size = 0; + /* Blocking write */ __usb_ep_write(ep_num, buffer, size, usb_ep_write_complete); while (!tx_done) -- 2.25.1