mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Tue Jun 24 14:45:08 2014 +0100
Revision:
237:f3da66175598
Child:
375:3d36234a1087
Synchronized with git revision 8ef659bca81f12dfc896b5a7af7c2abbd1a1b8b7

Full URL: https://github.com/mbedmicro/mbed/commit/8ef659bca81f12dfc896b5a7af7c2abbd1a1b8b7/

[NUCLEO_F334R8] Add platform files

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 237:f3da66175598 1 /**
mbed_official 237:f3da66175598 2 ******************************************************************************
mbed_official 237:f3da66175598 3 * @file stm32f3xx_hal_pcd_ex.c
mbed_official 237:f3da66175598 4 * @author MCD Application Team
mbed_official 237:f3da66175598 5 * @version V1.0.1
mbed_official 237:f3da66175598 6 * @date 18-June-2014
mbed_official 237:f3da66175598 7 * @brief Extended PCD HAL module driver.
mbed_official 237:f3da66175598 8 * This file provides firmware functions to manage the following
mbed_official 237:f3da66175598 9 * functionalities of the USB Peripheral Controller:
mbed_official 237:f3da66175598 10 * + Configururation of the PMA for EP
mbed_official 237:f3da66175598 11 *
mbed_official 237:f3da66175598 12 ******************************************************************************
mbed_official 237:f3da66175598 13 * @attention
mbed_official 237:f3da66175598 14 *
mbed_official 237:f3da66175598 15 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 237:f3da66175598 16 *
mbed_official 237:f3da66175598 17 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 237:f3da66175598 18 * are permitted provided that the following conditions are met:
mbed_official 237:f3da66175598 19 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 237:f3da66175598 20 * this list of conditions and the following disclaimer.
mbed_official 237:f3da66175598 21 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 237:f3da66175598 22 * this list of conditions and the following disclaimer in the documentation
mbed_official 237:f3da66175598 23 * and/or other materials provided with the distribution.
mbed_official 237:f3da66175598 24 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 237:f3da66175598 25 * may be used to endorse or promote products derived from this software
mbed_official 237:f3da66175598 26 * without specific prior written permission.
mbed_official 237:f3da66175598 27 *
mbed_official 237:f3da66175598 28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 237:f3da66175598 29 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 237:f3da66175598 30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 237:f3da66175598 31 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 237:f3da66175598 32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 237:f3da66175598 33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 237:f3da66175598 34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 237:f3da66175598 35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 237:f3da66175598 36 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 237:f3da66175598 37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 237:f3da66175598 38 *
mbed_official 237:f3da66175598 39 ******************************************************************************
mbed_official 237:f3da66175598 40 */
mbed_official 237:f3da66175598 41
mbed_official 237:f3da66175598 42 /* Includes ------------------------------------------------------------------*/
mbed_official 237:f3da66175598 43 #include "stm32f3xx_hal.h"
mbed_official 237:f3da66175598 44
mbed_official 237:f3da66175598 45 /** @addtogroup STM32F3xx_HAL_Driver
mbed_official 237:f3da66175598 46 * @{
mbed_official 237:f3da66175598 47 */
mbed_official 237:f3da66175598 48
mbed_official 237:f3da66175598 49 /** @defgroup PCDEx
mbed_official 237:f3da66175598 50 * @brief PCD HAL Extended module driver
mbed_official 237:f3da66175598 51 * @{
mbed_official 237:f3da66175598 52 */
mbed_official 237:f3da66175598 53
mbed_official 237:f3da66175598 54 #ifdef HAL_PCD_MODULE_ENABLED
mbed_official 237:f3da66175598 55
mbed_official 237:f3da66175598 56 #if defined(STM32F302x8) || defined(STM32F302xC) || \
mbed_official 237:f3da66175598 57 defined(STM32F303xC) || defined(STM32F373xC)
mbed_official 237:f3da66175598 58
mbed_official 237:f3da66175598 59 /* Private typedef -----------------------------------------------------------*/
mbed_official 237:f3da66175598 60 /* Private define ------------------------------------------------------------*/
mbed_official 237:f3da66175598 61 /* Private macro -------------------------------------------------------------*/
mbed_official 237:f3da66175598 62 /* Private variables ---------------------------------------------------------*/
mbed_official 237:f3da66175598 63 /* Private function prototypes -----------------------------------------------*/
mbed_official 237:f3da66175598 64 /* Private functions ---------------------------------------------------------*/
mbed_official 237:f3da66175598 65
mbed_official 237:f3da66175598 66
mbed_official 237:f3da66175598 67 /** @defgroup PCD_Private_Functions
mbed_official 237:f3da66175598 68 * @{
mbed_official 237:f3da66175598 69 */
mbed_official 237:f3da66175598 70
mbed_official 237:f3da66175598 71 /** @defgroup PCD_Group1 Initialization and de-initialization functions
mbed_official 237:f3da66175598 72 * @brief Initialization and Configuration functions
mbed_official 237:f3da66175598 73 *
mbed_official 237:f3da66175598 74 @verbatim
mbed_official 237:f3da66175598 75 ===============================================================================
mbed_official 237:f3da66175598 76 ##### Peripheral extended features methods #####
mbed_official 237:f3da66175598 77 ===============================================================================
mbed_official 237:f3da66175598 78 @endverbatim
mbed_official 237:f3da66175598 79 * @{
mbed_official 237:f3da66175598 80 */
mbed_official 237:f3da66175598 81
mbed_official 237:f3da66175598 82 /**
mbed_official 237:f3da66175598 83 * @brief Configure PMA for EP
mbed_official 237:f3da66175598 84 * @param hpcd : PCD handle
mbed_official 237:f3da66175598 85 * @param ep_addr: endpoint address
mbed_official 237:f3da66175598 86 * @param ep_kind: endpoint Kind
mbed_official 237:f3da66175598 87 * @arg USB_SNG_BUF: Single Buffer used
mbed_official 237:f3da66175598 88 * @arg USB_DBL_BUF: Double Buffer used
mbed_official 237:f3da66175598 89 * @param pmaadress: EP address in The PMA: In case of single buffer endpoint
mbed_official 237:f3da66175598 90 * this parameter is 16-bit value providing the address
mbed_official 237:f3da66175598 91 * in PMA allocated to endpoint.
mbed_official 237:f3da66175598 92 * In case of double buffer endpoint this parameter
mbed_official 237:f3da66175598 93 * is a 32-bit value providing the endpoint buffer 0 address
mbed_official 237:f3da66175598 94 * in the LSB part of 32-bit value and endpoint buffer 1 address
mbed_official 237:f3da66175598 95 * in the MSB part of 32-bit value.
mbed_official 237:f3da66175598 96 * @retval : status
mbed_official 237:f3da66175598 97 */
mbed_official 237:f3da66175598 98
mbed_official 237:f3da66175598 99 HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd,
mbed_official 237:f3da66175598 100 uint16_t ep_addr,
mbed_official 237:f3da66175598 101 uint16_t ep_kind,
mbed_official 237:f3da66175598 102 uint32_t pmaadress)
mbed_official 237:f3da66175598 103
mbed_official 237:f3da66175598 104 {
mbed_official 237:f3da66175598 105 PCD_EPTypeDef *ep;
mbed_official 237:f3da66175598 106
mbed_official 237:f3da66175598 107 /* initialize ep structure*/
mbed_official 237:f3da66175598 108 if ((0x80 & ep_addr) == 0x80)
mbed_official 237:f3da66175598 109 {
mbed_official 237:f3da66175598 110 ep = &hpcd->IN_ep[ep_addr & 0x7F];
mbed_official 237:f3da66175598 111 }
mbed_official 237:f3da66175598 112 else
mbed_official 237:f3da66175598 113 {
mbed_official 237:f3da66175598 114 ep = &hpcd->OUT_ep[ep_addr];
mbed_official 237:f3da66175598 115 }
mbed_official 237:f3da66175598 116
mbed_official 237:f3da66175598 117 /* Here we check if the endpoint is single or double Buffer*/
mbed_official 237:f3da66175598 118 if (ep_kind == PCD_SNG_BUF)
mbed_official 237:f3da66175598 119 {
mbed_official 237:f3da66175598 120 /*Single Buffer*/
mbed_official 237:f3da66175598 121 ep->doublebuffer = 0;
mbed_official 237:f3da66175598 122 /*Configure te PMA*/
mbed_official 237:f3da66175598 123 ep->pmaadress = (uint16_t)pmaadress;
mbed_official 237:f3da66175598 124 }
mbed_official 237:f3da66175598 125 else /*USB_DBL_BUF*/
mbed_official 237:f3da66175598 126 {
mbed_official 237:f3da66175598 127 /*Double Buffer Endpoint*/
mbed_official 237:f3da66175598 128 ep->doublebuffer = 1;
mbed_official 237:f3da66175598 129 /*Configure the PMA*/
mbed_official 237:f3da66175598 130 ep->pmaaddr0 = pmaadress & 0xFFFF;
mbed_official 237:f3da66175598 131 ep->pmaaddr1 = (pmaadress & 0xFFFF0000) >> 16;
mbed_official 237:f3da66175598 132 }
mbed_official 237:f3da66175598 133
mbed_official 237:f3da66175598 134 return HAL_OK;
mbed_official 237:f3da66175598 135 }
mbed_official 237:f3da66175598 136
mbed_official 237:f3da66175598 137 #if defined(STM32F301x8) || \
mbed_official 237:f3da66175598 138 defined(STM32F303x8) || defined(STM32F303xC) || defined(STM32F373xC) || \
mbed_official 237:f3da66175598 139 defined(STM32F334x8) || defined(STM32F373xC) || defined(STM32F378xx)
mbed_official 237:f3da66175598 140
mbed_official 237:f3da66175598 141
mbed_official 237:f3da66175598 142 /**
mbed_official 237:f3da66175598 143 * @brief Copy a buffer from user memory area to packet memory area (PMA)
mbed_official 237:f3da66175598 144 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 145 * @param pbUsrBuf: pointer to user memory area.
mbed_official 237:f3da66175598 146 * @param wPMABufAddr: address into PMA.
mbed_official 237:f3da66175598 147 * @param wNBytes: no. of bytes to be copied.
mbed_official 237:f3da66175598 148 * @retval None
mbed_official 237:f3da66175598 149 */
mbed_official 237:f3da66175598 150 void PCD_WritePMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
mbed_official 237:f3da66175598 151 {
mbed_official 237:f3da66175598 152 uint32_t n = (wNBytes + 1) >> 1; /* n = (wNBytes + 1) / 2 */
mbed_official 237:f3da66175598 153 uint32_t i, temp1, temp2;
mbed_official 237:f3da66175598 154 uint16_t *pdwVal;
mbed_official 237:f3da66175598 155 pdwVal = (uint16_t *)(wPMABufAddr * 2 + (uint32_t)USBx + 0x400);
mbed_official 237:f3da66175598 156 for (i = n; i != 0; i--)
mbed_official 237:f3da66175598 157 {
mbed_official 237:f3da66175598 158 temp1 = (uint16_t) * pbUsrBuf;
mbed_official 237:f3da66175598 159 pbUsrBuf++;
mbed_official 237:f3da66175598 160 temp2 = temp1 | (uint16_t) * pbUsrBuf << 8;
mbed_official 237:f3da66175598 161 *pdwVal++ = temp2;
mbed_official 237:f3da66175598 162 pdwVal++;
mbed_official 237:f3da66175598 163 pbUsrBuf++;
mbed_official 237:f3da66175598 164 }
mbed_official 237:f3da66175598 165 }
mbed_official 237:f3da66175598 166
mbed_official 237:f3da66175598 167 /**
mbed_official 237:f3da66175598 168 * @brief Copy a buffer from user memory area to packet memory area (PMA)
mbed_official 237:f3da66175598 169 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 170 * @param pbUsrBuf = pointer to user memory area.
mbed_official 237:f3da66175598 171 * @param wPMABufAddr: address into PMA.
mbed_official 237:f3da66175598 172 * @param wNBytes: no. of bytes to be copied.
mbed_official 237:f3da66175598 173 * @retval None
mbed_official 237:f3da66175598 174 */
mbed_official 237:f3da66175598 175 void PCD_ReadPMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
mbed_official 237:f3da66175598 176 {
mbed_official 237:f3da66175598 177 uint32_t n = (wNBytes + 1) >> 1;/* /2*/
mbed_official 237:f3da66175598 178 uint32_t i;
mbed_official 237:f3da66175598 179 uint32_t *pdwVal;
mbed_official 237:f3da66175598 180 pdwVal = (uint32_t *)(wPMABufAddr * 2 + (uint32_t)USBx + 0x400);
mbed_official 237:f3da66175598 181 for (i = n; i != 0; i--)
mbed_official 237:f3da66175598 182 {
mbed_official 237:f3da66175598 183 *(uint16_t*)pbUsrBuf++ = *pdwVal++;
mbed_official 237:f3da66175598 184 pbUsrBuf++;
mbed_official 237:f3da66175598 185 }
mbed_official 237:f3da66175598 186 }
mbed_official 237:f3da66175598 187 #endif
mbed_official 237:f3da66175598 188
mbed_official 237:f3da66175598 189 #if defined(STM32F302x8) || defined(STM32F302xC)
mbed_official 237:f3da66175598 190
mbed_official 237:f3da66175598 191 /**
mbed_official 237:f3da66175598 192 * @brief Copy a buffer from user memory area to packet memory area (PMA)
mbed_official 237:f3da66175598 193 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 194 * @param pbUsrBuf: pointer to user memory area.
mbed_official 237:f3da66175598 195 * @param wPMABufAddr: address into PMA.
mbed_official 237:f3da66175598 196 * @param wNBytes: no. of bytes to be copied.
mbed_official 237:f3da66175598 197 * @retval None
mbed_official 237:f3da66175598 198 */
mbed_official 237:f3da66175598 199 void PCD_WritePMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
mbed_official 237:f3da66175598 200 {
mbed_official 237:f3da66175598 201 uint32_t n = (wNBytes + 1) >> 1;
mbed_official 237:f3da66175598 202 uint32_t i;
mbed_official 237:f3da66175598 203 uint16_t temp1, temp2;
mbed_official 237:f3da66175598 204 uint16_t *pdwVal;
mbed_official 237:f3da66175598 205 pdwVal = (uint16_t *)(wPMABufAddr + (uint32_t)USBx + 0x400);
mbed_official 237:f3da66175598 206
mbed_official 237:f3da66175598 207 for (i = n; i != 0; i--)
mbed_official 237:f3da66175598 208 {
mbed_official 237:f3da66175598 209 temp1 = (uint16_t) * pbUsrBuf;
mbed_official 237:f3da66175598 210 pbUsrBuf++;
mbed_official 237:f3da66175598 211 temp2 = temp1 | (uint16_t) * pbUsrBuf << 8;
mbed_official 237:f3da66175598 212 *pdwVal++ = temp2;
mbed_official 237:f3da66175598 213 pbUsrBuf++;
mbed_official 237:f3da66175598 214 }
mbed_official 237:f3da66175598 215 }
mbed_official 237:f3da66175598 216
mbed_official 237:f3da66175598 217 /**
mbed_official 237:f3da66175598 218 * @brief Copy a buffer from user memory area to packet memory area (PMA)
mbed_official 237:f3da66175598 219 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 220 * @param pbUsrBuf = pointer to user memory area.
mbed_official 237:f3da66175598 221 * @param wPMABufAddr: address into PMA.
mbed_official 237:f3da66175598 222 * @param wNBytes: no. of bytes to be copied.
mbed_official 237:f3da66175598 223 * @retval None
mbed_official 237:f3da66175598 224 */
mbed_official 237:f3da66175598 225 void PCD_ReadPMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
mbed_official 237:f3da66175598 226 {
mbed_official 237:f3da66175598 227 uint32_t n = (wNBytes + 1) >> 1;
mbed_official 237:f3da66175598 228 uint32_t i;
mbed_official 237:f3da66175598 229 uint16_t *pdwVal;
mbed_official 237:f3da66175598 230 pdwVal = (uint16_t *)(wPMABufAddr + (uint32_t)USBx + 0x400);
mbed_official 237:f3da66175598 231 for (i = n; i != 0; i--)
mbed_official 237:f3da66175598 232 {
mbed_official 237:f3da66175598 233 *(uint16_t*)pbUsrBuf++ = *pdwVal++;
mbed_official 237:f3da66175598 234 pbUsrBuf++;
mbed_official 237:f3da66175598 235 }
mbed_official 237:f3da66175598 236 }
mbed_official 237:f3da66175598 237 #endif
mbed_official 237:f3da66175598 238
mbed_official 237:f3da66175598 239 /**
mbed_official 237:f3da66175598 240 * @brief Software Device Connection
mbed_official 237:f3da66175598 241 * @param hpcd: PCD handle
mbed_official 237:f3da66175598 242 * @param state: Device state
mbed_official 237:f3da66175598 243 * @retval None
mbed_official 237:f3da66175598 244 */
mbed_official 237:f3da66175598 245 __weak void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state)
mbed_official 237:f3da66175598 246 {
mbed_official 237:f3da66175598 247 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 237:f3da66175598 248 the HAL_PCDEx_SetConnectionState could be implenetd in the user file
mbed_official 237:f3da66175598 249 */
mbed_official 237:f3da66175598 250 }
mbed_official 237:f3da66175598 251
mbed_official 237:f3da66175598 252 /**
mbed_official 237:f3da66175598 253 * @}
mbed_official 237:f3da66175598 254 */
mbed_official 237:f3da66175598 255
mbed_official 237:f3da66175598 256 /**
mbed_official 237:f3da66175598 257 * @}
mbed_official 237:f3da66175598 258 */
mbed_official 237:f3da66175598 259
mbed_official 237:f3da66175598 260 #endif /* defined(STM32F302x8) || defined(STM32F302xC) || */
mbed_official 237:f3da66175598 261 /* defined(STM32F303xC) || defined(STM32F373xC) */
mbed_official 237:f3da66175598 262
mbed_official 237:f3da66175598 263 #endif /* HAL_PCD_MODULE_ENABLED */
mbed_official 237:f3da66175598 264 /**
mbed_official 237:f3da66175598 265 * @}
mbed_official 237:f3da66175598 266 */
mbed_official 237:f3da66175598 267
mbed_official 237:f3da66175598 268 /**
mbed_official 237:f3da66175598 269 * @}
mbed_official 237:f3da66175598 270 */
mbed_official 237:f3da66175598 271
mbed_official 237:f3da66175598 272 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/