From dd6a0b3ccdd62873e1cb874969741e3fb683db4b Mon Sep 17 00:00:00 2001 From: gdisirio Date: Sun, 13 Feb 2011 20:55:57 +0000 Subject: Implemented automatic allocation in the packet memory of the STM32 USB driver, no need to specify addresses anymore. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2737 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/platforms/STM32/usb_lld.c | 33 +++++++++++++++++++++++++++------ os/hal/platforms/STM32/usb_lld.h | 12 ++++-------- testhal/STM32/USB_CDC/main.c | 8 +------- 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/os/hal/platforms/STM32/usb_lld.c b/os/hal/platforms/STM32/usb_lld.c index f09e6d0ea..cecbc9934 100644 --- a/os/hal/platforms/STM32/usb_lld.c +++ b/os/hal/platforms/STM32/usb_lld.c @@ -44,7 +44,6 @@ USBDriver USBD1; #endif - /*===========================================================================*/ /* Driver local variables. */ /*===========================================================================*/ @@ -62,15 +61,34 @@ static const USBEndpointConfig ep0config = { _usb_ep0in, _usb_ep0out, 0x40, - 0x40, - 0x40, - 0x80 + 0x40 }; /*===========================================================================*/ /* Driver local functions. */ /*===========================================================================*/ +/** + * @brief Resets the packet memory allocator. + * + * @param[in] usbp pointer to the @p USBDriver object + */ +static void pm_reset(USBDriver *usbp) { + usbp->pmnext = 64; +} + +/** + * @brief Resets the packet memory allocator. + * + * @param[in] usbp pointer to the @p USBDriver object + * @param[in] size size of the packet buffer to allocate + */ +static uint32_t pm_alloc(USBDriver *usbp, size_t size) { + uint32_t next = usbp->pmnext; + usbp->pmnext += size; + return next; +} + /** * @brief Copies a packet from memory into a packet buffer. * @@ -342,6 +360,9 @@ void usb_lld_reset(USBDriver *usbp) { cntr |= CNTR_SOFM; STM32_USB->CNTR = cntr; + /* Resets the packet memory allocator.*/ + pm_reset(usbp); + /* EP0 initialization.*/ memset(&ep0state, 0, sizeof ep0state); ep0state.config = &ep0config; @@ -417,8 +438,8 @@ void usb_lld_init_endpoint(USBDriver *usbp, usbep_t ep) { dp = USB_GET_DESCRIPTOR(ep); dp->TXCOUNT = 0; dp->RXCOUNT = nblocks; - dp->TXADDR = epcp->inaddr; - dp->RXADDR = epcp->outaddr; + dp->TXADDR = pm_alloc(usbp, epcp->in_maxsize); + dp->RXADDR = pm_alloc(usbp, epcp->out_maxsize); } /** diff --git a/os/hal/platforms/STM32/usb_lld.h b/os/hal/platforms/STM32/usb_lld.h index c1b00de06..d82fda644 100644 --- a/os/hal/platforms/STM32/usb_lld.h +++ b/os/hal/platforms/STM32/usb_lld.h @@ -127,14 +127,6 @@ typedef struct { */ uint16_t out_maxsize; /* End of the mandatory fields.*/ - /** - * @brief Endpoint IN buffer address as offset in the PMA. - */ - uint16_t inaddr; - /** - * @brief Endpoint OUT buffer address as offset in the PMA. - */ - uint16_t outaddr; } USBEndpointConfig; @@ -265,6 +257,10 @@ struct USBDriver { */ uint8_t configuration; /* End of the mandatory fields.*/ + /** + * @brief Pointer to the next address in the packet memory. + */ + uint32_t pmnext; }; /*===========================================================================*/ diff --git a/testhal/STM32/USB_CDC/main.c b/testhal/STM32/USB_CDC/main.c index 05c8fa11a..00f0d0e66 100644 --- a/testhal/STM32/USB_CDC/main.c +++ b/testhal/STM32/USB_CDC/main.c @@ -255,8 +255,6 @@ static const USBEndpointConfig ep1config = { sduDataTransmitted, NULL, 0x0040, - 0x0000, - 0x00C0, 0x0000 }; @@ -268,8 +266,6 @@ static const USBEndpointConfig ep2config = { sduInterruptTransmitted, NULL, 0x0010, - 0x0000, - 0x0100, 0x0000 }; @@ -281,9 +277,7 @@ static const USBEndpointConfig ep3config = { NULL, sduDataReceived, 0x0000, - 0x0040, - 0x0000, - 0x0110 + 0x0040 }; /* -- cgit v1.2.3