aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-02-15 09:16:17 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-02-15 09:16:17 +0000
commit35ff7323526f5225d1a00c7812291e9fcdbfafac (patch)
treed2fd2eb98544de7e6e2eafae015e8afe33c721b6
parent20a4b38126be234c5f946df9254c7d64502ff855 (diff)
downloadChibiOS-35ff7323526f5225d1a00c7812291e9fcdbfafac.tar.gz
ChibiOS-35ff7323526f5225d1a00c7812291e9fcdbfafac.tar.bz2
ChibiOS-35ff7323526f5225d1a00c7812291e9fcdbfafac.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2740 35acf78f-673a-0410-8e92-d51de3d6d3f4
-rw-r--r--os/hal/platforms/STM32/stm32_usb.h7
-rw-r--r--os/hal/platforms/STM32/usb_lld.c14
-rw-r--r--os/hal/src/usb.c20
3 files changed, 29 insertions, 12 deletions
diff --git a/os/hal/platforms/STM32/stm32_usb.h b/os/hal/platforms/STM32/stm32_usb.h
index 8c04ba85f..8bb0d8b95 100644
--- a/os/hal/platforms/STM32/stm32_usb.h
+++ b/os/hal/platforms/STM32/stm32_usb.h
@@ -108,11 +108,16 @@ typedef struct {
#define STM32_USB ((stm32_usb_t *)STM32_USB_BASE)
/**
- * @brief Pointer to the USB RAM.
+ * @brief Pointer to the USB RAM.
*/
#define STM32_USBRAM ((uint32_t *)STM32_USBRAM_BASE)
/**
+ * @brief Size of the dedicated packet memory.
+ */
+#define USB_PMA_SIZE 512
+
+/**
* @brief Mask of all the toggling bits in the EPR register.
*/
#define EPR_TOGGLE_MASK (EPR_STAT_TX_MASK | EPR_DTOG_TX | \
diff --git a/os/hal/platforms/STM32/usb_lld.c b/os/hal/platforms/STM32/usb_lld.c
index 0a7bc9315..f3bfa15f4 100644
--- a/os/hal/platforms/STM32/usb_lld.c
+++ b/os/hal/platforms/STM32/usb_lld.c
@@ -87,6 +87,9 @@ static const USBEndpointConfig ep0config = {
* @param[in] usbp pointer to the @p USBDriver object
*/
static void pm_reset(USBDriver *usbp) {
+
+ /* The first 64 bytes are reserved for the descriptors table. The effective
+ available RAM for endpoint buffers is just 448 bytes.*/
usbp->pmnext = 64;
}
@@ -97,8 +100,11 @@ static void pm_reset(USBDriver *usbp) {
* @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;
+ uint32_t next;
+
+ next = usbp->pmnext;
usbp->pmnext += size;
+ chDbgAssert(usbp->pmnext > USB_PMA_SIZE, "pm_alloc(), #1", "PMA overflow");
return next;
}
@@ -463,12 +469,14 @@ void usb_lld_init_endpoint(USBDriver *usbp, usbep_t ep) {
void usb_lld_disable_endpoints(USBDriver *usbp) {
unsigned i;
- (void)usbp;
+ /* Resets the packet memory allocator.*/
+ pm_reset(usbp);
+
+ /* Disabling all endpoints.*/
for (i = 1; i <= USB_ENDOPOINTS_NUMBER; i++) {
EPR_TOGGLE(i, 0);
EPR_SET(i, 0);
}
-
}
/**
diff --git a/os/hal/src/usb.c b/os/hal/src/usb.c
index 34e9a14fd..0dbe4b39d 100644
--- a/os/hal/src/usb.c
+++ b/os/hal/src/usb.c
@@ -335,6 +335,8 @@ void usbDisableEndpointsI(USBDriver *usbp) {
chDbgAssert(usbp->state == USB_SELECTED,
"usbDisableEndpointsI(), #1", "invalid state");
+ usbp->transmitting &= ~1;
+ usbp->receiving &= ~1;
for (i = 1; i <= USB_MAX_ENDPOINTS; i++)
usbp->epc[i] = NULL;
@@ -399,7 +401,7 @@ size_t usbWritePacketI(USBDriver *usbp, usbep_t ep,
}
/**
- * @brief Starts a receive operation on an OUT endpoint.
+ * @brief Starts a receive transaction on an OUT endpoint.
* @pre In order to use this function he endpoint must have been
* initialized in transaction mode.
* @post The endpoint callback is invoked when the transfer has been
@@ -410,8 +412,8 @@ size_t usbWritePacketI(USBDriver *usbp, usbep_t ep,
* @param[out] buf buffer where to copy the received data
* @param[in] n maximum number of bytes to copy
* @return The operation status.
- * @retval FALSE Operation complete.
- * @retval TRUE Endpoint busy receiving.
+ * @retval FALSE Operation started successfully.
+ * @retval TRUE Endpoint busy, operation not started.
*
* @iclass
*/
@@ -427,7 +429,7 @@ bool_t usbStartReceiveI(USBDriver *usbp, usbep_t ep,
}
/**
- * @brief Starts a transmit operation on an IN endpoint.
+ * @brief Starts a transmit transaction on an IN endpoint.
* @pre In order to use this function he endpoint must have been
* initialized in transaction mode.
* @post The endpoint callback is invoked when the transfer has been
@@ -438,8 +440,8 @@ bool_t usbStartReceiveI(USBDriver *usbp, usbep_t ep,
* @param[in] buf buffer where to fetch the data to be transmitted
* @param[in] n maximum number of bytes to copy
* @return The operation status.
- * @retval FALSE Operation complete.
- * @retval TRUE Endpoint busy transmitting.
+ * @retval FALSE Operation started successfully.
+ * @retval TRUE Endpoint busy, operation not started.
*
* @iclass
*/
@@ -461,7 +463,7 @@ bool_t usbStartTransmitI(USBDriver *usbp, usbep_t ep,
* @param[in] ep endpoint number
* @return The operation status.
* @retval FALSE Endpoint stalled.
- * @retval TRUE The endpoint was within a transaction, not stalled.
+ * @retval TRUE Endpoint busy, not stalled.
*
* @iclass
*/
@@ -481,7 +483,7 @@ bool_t usbStallReceiveI(USBDriver *usbp, usbep_t ep) {
* @param[in] ep endpoint number
* @return The operation status.
* @retval FALSE Endpoint stalled.
- * @retval TRUE The endpoint was within a transaction, not stalled.
+ * @retval TRUE Endpoint busy, not stalled.
*
* @iclass
*/
@@ -510,6 +512,8 @@ void _usb_reset(USBDriver *usbp) {
usbp->status = 0;
usbp->address = 0;
usbp->configuration = 0;
+ usbp->transmitting = 0;
+ usbp->receiving = 0;
/* Invalidates all endpoints into the USBDriver structure.*/
for (i = 0; i <= USB_MAX_ENDPOINTS; i++)