From: arighi Date: Thu, 30 Sep 2010 13:17:03 +0000 (+0000) Subject: STM32: USB: define descriptors only for the allocated endpoints X-Git-Tag: 2.6.0~18 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=45b784ed8ed1b37ccd1fa56258fb9d082de55216;p=bertos.git STM32: USB: define descriptors only for the allocated endpoints There is no need to define descriptors for all the supported hardware endpoints, but just for the ones that are actually used. Also check the validity of the endpoint addresses considering the allocated endpoints. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4383 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cpu/cortex-m3/drv/usb_stm32.c b/bertos/cpu/cortex-m3/drv/usb_stm32.c index 0aa4c188..d8012911 100644 --- a/bertos/cpu/cortex-m3/drv/usb_stm32.c +++ b/bertos/cpu/cortex-m3/drv/usb_stm32.c @@ -92,7 +92,7 @@ struct stm32_usb static struct stm32_usb *usb = (struct stm32_usb *)USB_BASE_ADDR; /* Endpoint descriptors: used for handling requests to use with endpoints */ -static stm32_UsbEp ep_cnfg[ENP_MAX_NUMB]; +static stm32_UsbEp ep_cnfg[EP_MAX_NUM]; /* USB EP0 control descriptor */ static const UsbEndpointDesc USB_CtrlEpDescr0 = @@ -148,8 +148,7 @@ static UsbDevice *usb_dev; static stm32_UsbMemSlot *mem_use; /* USB packet memory management: memory buffer metadata */ -#define EP_MAX_SLOTS 16 -static stm32_UsbMemSlot memory_buffer[EP_MAX_SLOTS]; +static stm32_UsbMemSlot memory_buffer[EP_MAX_HW_NUM >> 1]; /* Endpoint TX and RX buffers */ /// \cond @@ -687,7 +686,7 @@ out: \ static stm32_UsbIoStatus __usb_ep_read(int ep, void *buffer, ssize_t size, void (*complete)(int)) { - if (UNLIKELY((ep >= ENP_MAX_NUMB) || (ep & 0x01))) + if (UNLIKELY((ep >= EP_MAX_NUM) || (ep & 0x01))) { LOG_ERR("%s: invalid EP number %d\n", __func__, ep); ASSERT(0); @@ -706,7 +705,7 @@ __usb_ep_read(int ep, void *buffer, ssize_t size, void (*complete)(int)) static stm32_UsbIoStatus __usb_ep_write(int ep, const void *buffer, ssize_t size, void (*complete)(int)) { - if (UNLIKELY((ep >= ENP_MAX_NUMB) || !(ep & 0x01))) + if (UNLIKELY((ep >= EP_MAX_NUM) || !(ep & 0x01))) { LOG_ERR("%s: invalid EP number %d\n", __func__, ep); ASSERT(0); @@ -1106,7 +1105,7 @@ static void usb_status_handler(UNUSED_ARG(int, EP)) static void usb_endpointRead_complete(int ep) { - if (UNLIKELY(ep >= ENP_MAX_NUMB)) + if (UNLIKELY(ep >= EP_MAX_NUM)) { ASSERT(0); return; @@ -1160,7 +1159,7 @@ ssize_t usb_endpointRead(int ep, void *buffer, ssize_t size) static void usb_endpointWrite_complete(int ep) { - if (UNLIKELY(ep >= ENP_MAX_NUMB)) + if (UNLIKELY(ep >= EP_MAX_NUM)) { ASSERT(0); return; diff --git a/bertos/cpu/cortex-m3/drv/usb_stm32.h b/bertos/cpu/cortex-m3/drv/usb_stm32.h index c0199349..96790250 100644 --- a/bertos/cpu/cortex-m3/drv/usb_stm32.h +++ b/bertos/cpu/cortex-m3/drv/usb_stm32.h @@ -42,6 +42,7 @@ #include #include +#include #define USB_BASE_ADDR 0x40005C00 @@ -52,13 +53,16 @@ #define USB_EP0_MAX_SIZE 8 #define USB_XFER_MAX_SIZE 64 +#define EP_MAX_SLOTS USB_EP_MAX +#define EP_MAX_NUM (EP_MAX_SLOTS << 1) + /* USB packet memory organization */ #define USB_PACKET_MEMORY_BASE 0x40006000 #define USB_PACKET_MEMORY_SIZE 512 /* Offset of the buffer descriptor table inside the packet memory */ #define USB_BDT_OFFSET \ - ((USB_PACKET_MEMORY_SIZE - (sizeof(stm32_UsbBd) * ENP_MAX_NUMB)) & ~7) + ((USB_PACKET_MEMORY_SIZE - (sizeof(stm32_UsbBd) * EP_MAX_HW_NUM)) & ~7) #define USB_MEM_ADDR(offset) \ (USB_PACKET_MEMORY_BASE + ((offset << 1) & ~3) + (offset & 1)) @@ -168,7 +172,7 @@ typedef enum stm32_UsbEP ENP14_OUT, ENP14_IN, ENP15_OUT, ENP15_IN, - ENP_MAX_NUMB + EP_MAX_HW_NUM } stm32_UsbEP; /* STM32 USB packet memory slot */