Modified version of the mbed library for use with the Nucleo boards.

Dependents:   EEPROMWrite Full-Project

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Mon Sep 28 14:00:11 2015 +0100
Revision:
632:7687fb9c4f91
Parent:
385:be64abf45658
Child:
634:ac7d6880524d
Synchronized with git revision f7ce4ed029cc611121464252ff28d5e8beb895b0

Full URL: https://github.com/mbedmicro/mbed/commit/f7ce4ed029cc611121464252ff28d5e8beb895b0/

NUCLEO_F303K8 - add support of the STM32F303K8

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 632:7687fb9c4f91 5 * @version V1.1.1
mbed_official 632:7687fb9c4f91 6 * @date 19-June-2015
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 375:3d36234a1087 10 * + Configuration 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 632:7687fb9c4f91 15 * <h2><center>&copy; COPYRIGHT(c) 2015 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 375:3d36234a1087 49 /** @defgroup PCDEx PCD Extended HAL module driver
mbed_official 375:3d36234a1087 50 * @brief PCDEx PCDEx Extended HAL 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 375:3d36234a1087 56 #if defined(STM32F302xE) || defined(STM32F303xE) || \
mbed_official 375:3d36234a1087 57 defined(STM32F302xC) || defined(STM32F303xC) || \
mbed_official 375:3d36234a1087 58 defined(STM32F302x8) || \
mbed_official 375:3d36234a1087 59 defined(STM32F373xC)
mbed_official 237:f3da66175598 60
mbed_official 237:f3da66175598 61 /* Private typedef -----------------------------------------------------------*/
mbed_official 237:f3da66175598 62 /* Private define ------------------------------------------------------------*/
mbed_official 237:f3da66175598 63 /* Private macro -------------------------------------------------------------*/
mbed_official 237:f3da66175598 64 /* Private variables ---------------------------------------------------------*/
mbed_official 237:f3da66175598 65 /* Private function prototypes -----------------------------------------------*/
mbed_official 375:3d36234a1087 66 /* Exported functions ---------------------------------------------------------*/
mbed_official 237:f3da66175598 67
mbed_official 375:3d36234a1087 68 /** @defgroup PCDEx_Exported_Functions PCD Extended Exported Functions
mbed_official 237:f3da66175598 69 * @{
mbed_official 237:f3da66175598 70 */
mbed_official 237:f3da66175598 71
mbed_official 375:3d36234a1087 72 /** @defgroup PCDEx_Exported_Functions_Group1 Extended Initialization and de-initialization functions
mbed_official 237:f3da66175598 73 * @brief Initialization and Configuration functions
mbed_official 237:f3da66175598 74 *
mbed_official 237:f3da66175598 75 @verbatim
mbed_official 237:f3da66175598 76 ===============================================================================
mbed_official 237:f3da66175598 77 ##### Peripheral extended features methods #####
mbed_official 237:f3da66175598 78 ===============================================================================
mbed_official 237:f3da66175598 79 @endverbatim
mbed_official 237:f3da66175598 80 * @{
mbed_official 237:f3da66175598 81 */
mbed_official 237:f3da66175598 82
mbed_official 237:f3da66175598 83 /**
mbed_official 237:f3da66175598 84 * @brief Configure PMA for EP
mbed_official 375:3d36234a1087 85 * @param hpcd: PCD handle
mbed_official 237:f3da66175598 86 * @param ep_addr: endpoint address
mbed_official 237:f3da66175598 87 * @param ep_kind: endpoint Kind
mbed_official 237:f3da66175598 88 * @arg USB_SNG_BUF: Single Buffer used
mbed_official 237:f3da66175598 89 * @arg USB_DBL_BUF: Double Buffer used
mbed_official 237:f3da66175598 90 * @param pmaadress: EP address in The PMA: In case of single buffer endpoint
mbed_official 237:f3da66175598 91 * this parameter is 16-bit value providing the address
mbed_official 237:f3da66175598 92 * in PMA allocated to endpoint.
mbed_official 237:f3da66175598 93 * In case of double buffer endpoint this parameter
mbed_official 237:f3da66175598 94 * is a 32-bit value providing the endpoint buffer 0 address
mbed_official 237:f3da66175598 95 * in the LSB part of 32-bit value and endpoint buffer 1 address
mbed_official 237:f3da66175598 96 * in the MSB part of 32-bit value.
mbed_official 237:f3da66175598 97 * @retval : status
mbed_official 237:f3da66175598 98 */
mbed_official 237:f3da66175598 99
mbed_official 237:f3da66175598 100 HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd,
mbed_official 237:f3da66175598 101 uint16_t ep_addr,
mbed_official 237:f3da66175598 102 uint16_t ep_kind,
mbed_official 237:f3da66175598 103 uint32_t pmaadress)
mbed_official 237:f3da66175598 104
mbed_official 237:f3da66175598 105 {
mbed_official 237:f3da66175598 106 PCD_EPTypeDef *ep;
mbed_official 237:f3da66175598 107
mbed_official 237:f3da66175598 108 /* initialize ep structure*/
mbed_official 237:f3da66175598 109 if ((0x80 & ep_addr) == 0x80)
mbed_official 237:f3da66175598 110 {
mbed_official 237:f3da66175598 111 ep = &hpcd->IN_ep[ep_addr & 0x7F];
mbed_official 237:f3da66175598 112 }
mbed_official 237:f3da66175598 113 else
mbed_official 237:f3da66175598 114 {
mbed_official 237:f3da66175598 115 ep = &hpcd->OUT_ep[ep_addr];
mbed_official 237:f3da66175598 116 }
mbed_official 237:f3da66175598 117
mbed_official 237:f3da66175598 118 /* Here we check if the endpoint is single or double Buffer*/
mbed_official 237:f3da66175598 119 if (ep_kind == PCD_SNG_BUF)
mbed_official 237:f3da66175598 120 {
mbed_official 237:f3da66175598 121 /*Single Buffer*/
mbed_official 237:f3da66175598 122 ep->doublebuffer = 0;
mbed_official 237:f3da66175598 123 /*Configure te PMA*/
mbed_official 237:f3da66175598 124 ep->pmaadress = (uint16_t)pmaadress;
mbed_official 237:f3da66175598 125 }
mbed_official 237:f3da66175598 126 else /*USB_DBL_BUF*/
mbed_official 237:f3da66175598 127 {
mbed_official 237:f3da66175598 128 /*Double Buffer Endpoint*/
mbed_official 237:f3da66175598 129 ep->doublebuffer = 1;
mbed_official 237:f3da66175598 130 /*Configure the PMA*/
mbed_official 237:f3da66175598 131 ep->pmaaddr0 = pmaadress & 0xFFFF;
mbed_official 237:f3da66175598 132 ep->pmaaddr1 = (pmaadress & 0xFFFF0000) >> 16;
mbed_official 237:f3da66175598 133 }
mbed_official 237:f3da66175598 134
mbed_official 237:f3da66175598 135 return HAL_OK;
mbed_official 237:f3da66175598 136 }
mbed_official 375:3d36234a1087 137 /**
mbed_official 375:3d36234a1087 138 * @}
mbed_official 375:3d36234a1087 139 */
mbed_official 237:f3da66175598 140
mbed_official 375:3d36234a1087 141 /**
mbed_official 375:3d36234a1087 142 * @}
mbed_official 375:3d36234a1087 143 */
mbed_official 375:3d36234a1087 144
mbed_official 375:3d36234a1087 145 /** @defgroup PCDEx_Private_Functions PCD Extended Private Functions
mbed_official 375:3d36234a1087 146 * @{
mbed_official 375:3d36234a1087 147 */
mbed_official 375:3d36234a1087 148 #if defined(STM32F303xC) || \
mbed_official 375:3d36234a1087 149 defined(STM32F303x8) || defined(STM32F334x8) || \
mbed_official 375:3d36234a1087 150 defined(STM32F301x8) || \
mbed_official 375:3d36234a1087 151 defined(STM32F373xC) || defined(STM32F378xx)
mbed_official 237:f3da66175598 152
mbed_official 237:f3da66175598 153
mbed_official 237:f3da66175598 154 /**
mbed_official 237:f3da66175598 155 * @brief Copy a buffer from user memory area to packet memory area (PMA)
mbed_official 237:f3da66175598 156 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 157 * @param pbUsrBuf: pointer to user memory area.
mbed_official 237:f3da66175598 158 * @param wPMABufAddr: address into PMA.
mbed_official 237:f3da66175598 159 * @param wNBytes: no. of bytes to be copied.
mbed_official 237:f3da66175598 160 * @retval None
mbed_official 237:f3da66175598 161 */
mbed_official 237:f3da66175598 162 void PCD_WritePMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
mbed_official 237:f3da66175598 163 {
mbed_official 237:f3da66175598 164 uint32_t n = (wNBytes + 1) >> 1; /* n = (wNBytes + 1) / 2 */
mbed_official 237:f3da66175598 165 uint32_t i, temp1, temp2;
mbed_official 237:f3da66175598 166 uint16_t *pdwVal;
mbed_official 237:f3da66175598 167 pdwVal = (uint16_t *)(wPMABufAddr * 2 + (uint32_t)USBx + 0x400);
mbed_official 237:f3da66175598 168 for (i = n; i != 0; i--)
mbed_official 237:f3da66175598 169 {
mbed_official 237:f3da66175598 170 temp1 = (uint16_t) * pbUsrBuf;
mbed_official 237:f3da66175598 171 pbUsrBuf++;
mbed_official 237:f3da66175598 172 temp2 = temp1 | (uint16_t) * pbUsrBuf << 8;
mbed_official 237:f3da66175598 173 *pdwVal++ = temp2;
mbed_official 237:f3da66175598 174 pdwVal++;
mbed_official 237:f3da66175598 175 pbUsrBuf++;
mbed_official 237:f3da66175598 176 }
mbed_official 237:f3da66175598 177 }
mbed_official 237:f3da66175598 178
mbed_official 237:f3da66175598 179 /**
mbed_official 237:f3da66175598 180 * @brief Copy a buffer from user memory area to packet memory area (PMA)
mbed_official 237:f3da66175598 181 * @param USBx: USB peripheral instance register address.
mbed_official 375:3d36234a1087 182 * @param pbUsrBuf: pointer to user memory area.
mbed_official 237:f3da66175598 183 * @param wPMABufAddr: address into PMA.
mbed_official 237:f3da66175598 184 * @param wNBytes: no. of bytes to be copied.
mbed_official 237:f3da66175598 185 * @retval None
mbed_official 237:f3da66175598 186 */
mbed_official 237:f3da66175598 187 void PCD_ReadPMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
mbed_official 237:f3da66175598 188 {
mbed_official 237:f3da66175598 189 uint32_t n = (wNBytes + 1) >> 1;/* /2*/
mbed_official 237:f3da66175598 190 uint32_t i;
mbed_official 237:f3da66175598 191 uint32_t *pdwVal;
mbed_official 237:f3da66175598 192 pdwVal = (uint32_t *)(wPMABufAddr * 2 + (uint32_t)USBx + 0x400);
mbed_official 237:f3da66175598 193 for (i = n; i != 0; i--)
mbed_official 237:f3da66175598 194 {
mbed_official 237:f3da66175598 195 *(uint16_t*)pbUsrBuf++ = *pdwVal++;
mbed_official 237:f3da66175598 196 pbUsrBuf++;
mbed_official 237:f3da66175598 197 }
mbed_official 237:f3da66175598 198 }
mbed_official 375:3d36234a1087 199 #endif /* STM32F303xC || */
mbed_official 375:3d36234a1087 200 /* STM32F303x8 || STM32F334x8 || */
mbed_official 375:3d36234a1087 201 /* STM32F301x8 || */
mbed_official 375:3d36234a1087 202 /* STM32F373xC || STM32F378xx */
mbed_official 237:f3da66175598 203
mbed_official 375:3d36234a1087 204 #if defined(STM32F302xE) || defined(STM32F303xE) || \
mbed_official 375:3d36234a1087 205 defined(STM32F302xC) || \
mbed_official 375:3d36234a1087 206 defined(STM32F302x8)
mbed_official 237:f3da66175598 207 /**
mbed_official 237:f3da66175598 208 * @brief Copy a buffer from user memory area to packet memory area (PMA)
mbed_official 237:f3da66175598 209 * @param USBx: USB peripheral instance register address.
mbed_official 237:f3da66175598 210 * @param pbUsrBuf: pointer to user memory area.
mbed_official 237:f3da66175598 211 * @param wPMABufAddr: address into PMA.
mbed_official 237:f3da66175598 212 * @param wNBytes: no. of bytes to be copied.
mbed_official 237:f3da66175598 213 * @retval None
mbed_official 237:f3da66175598 214 */
mbed_official 237:f3da66175598 215 void PCD_WritePMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
mbed_official 237:f3da66175598 216 {
mbed_official 237:f3da66175598 217 uint32_t n = (wNBytes + 1) >> 1;
mbed_official 237:f3da66175598 218 uint32_t i;
mbed_official 237:f3da66175598 219 uint16_t temp1, temp2;
mbed_official 237:f3da66175598 220 uint16_t *pdwVal;
mbed_official 237:f3da66175598 221 pdwVal = (uint16_t *)(wPMABufAddr + (uint32_t)USBx + 0x400);
mbed_official 237:f3da66175598 222
mbed_official 237:f3da66175598 223 for (i = n; i != 0; i--)
mbed_official 237:f3da66175598 224 {
mbed_official 237:f3da66175598 225 temp1 = (uint16_t) * pbUsrBuf;
mbed_official 237:f3da66175598 226 pbUsrBuf++;
mbed_official 237:f3da66175598 227 temp2 = temp1 | (uint16_t) * pbUsrBuf << 8;
mbed_official 237:f3da66175598 228 *pdwVal++ = temp2;
mbed_official 237:f3da66175598 229 pbUsrBuf++;
mbed_official 237:f3da66175598 230 }
mbed_official 237:f3da66175598 231 }
mbed_official 237:f3da66175598 232
mbed_official 237:f3da66175598 233 /**
mbed_official 237:f3da66175598 234 * @brief Copy a buffer from user memory area to packet memory area (PMA)
mbed_official 237:f3da66175598 235 * @param USBx: USB peripheral instance register address.
mbed_official 375:3d36234a1087 236 * @param pbUsrBuf: pointer to user memory area.
mbed_official 237:f3da66175598 237 * @param wPMABufAddr: address into PMA.
mbed_official 237:f3da66175598 238 * @param wNBytes: no. of bytes to be copied.
mbed_official 237:f3da66175598 239 * @retval None
mbed_official 237:f3da66175598 240 */
mbed_official 237:f3da66175598 241 void PCD_ReadPMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
mbed_official 237:f3da66175598 242 {
mbed_official 237:f3da66175598 243 uint32_t n = (wNBytes + 1) >> 1;
mbed_official 237:f3da66175598 244 uint32_t i;
mbed_official 237:f3da66175598 245 uint16_t *pdwVal;
mbed_official 237:f3da66175598 246 pdwVal = (uint16_t *)(wPMABufAddr + (uint32_t)USBx + 0x400);
mbed_official 237:f3da66175598 247 for (i = n; i != 0; i--)
mbed_official 237:f3da66175598 248 {
mbed_official 237:f3da66175598 249 *(uint16_t*)pbUsrBuf++ = *pdwVal++;
mbed_official 237:f3da66175598 250 pbUsrBuf++;
mbed_official 237:f3da66175598 251 }
mbed_official 237:f3da66175598 252 }
mbed_official 375:3d36234a1087 253 #endif /* STM32F302xE || STM32F303xE || */
mbed_official 375:3d36234a1087 254 /* STM32F302xC || */
mbed_official 375:3d36234a1087 255 /* STM32F302x8 */
mbed_official 375:3d36234a1087 256
mbed_official 375:3d36234a1087 257 /**
mbed_official 375:3d36234a1087 258 * @}
mbed_official 375:3d36234a1087 259 */
mbed_official 237:f3da66175598 260
mbed_official 375:3d36234a1087 261 /** @addtogroup PCDEx_Exported_Functions PCD Extended Exported Functions
mbed_official 375:3d36234a1087 262 * @{
mbed_official 375:3d36234a1087 263 */
mbed_official 375:3d36234a1087 264
mbed_official 375:3d36234a1087 265 /** @addtogroup PCDEx_Exported_Functions_Group1 Extended Initialization and de-initialization functions
mbed_official 375:3d36234a1087 266 * @{
mbed_official 375:3d36234a1087 267 */
mbed_official 237:f3da66175598 268 /**
mbed_official 237:f3da66175598 269 * @brief Software Device Connection
mbed_official 237:f3da66175598 270 * @param hpcd: PCD handle
mbed_official 237:f3da66175598 271 * @param state: Device state
mbed_official 237:f3da66175598 272 * @retval None
mbed_official 237:f3da66175598 273 */
mbed_official 237:f3da66175598 274 __weak void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state)
mbed_official 237:f3da66175598 275 {
mbed_official 237:f3da66175598 276 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 237:f3da66175598 277 the HAL_PCDEx_SetConnectionState could be implenetd in the user file
mbed_official 237:f3da66175598 278 */
mbed_official 237:f3da66175598 279 }
mbed_official 375:3d36234a1087 280 /**
mbed_official 375:3d36234a1087 281 * @}
mbed_official 375:3d36234a1087 282 */
mbed_official 237:f3da66175598 283
mbed_official 237:f3da66175598 284 /**
mbed_official 237:f3da66175598 285 * @}
mbed_official 237:f3da66175598 286 */
mbed_official 375:3d36234a1087 287 #endif /* STM32F302xE || STM32F303xE || */
mbed_official 375:3d36234a1087 288 /* STM32F302xC || STM32F303xC || */
mbed_official 375:3d36234a1087 289 /* STM32F302x8 || */
mbed_official 375:3d36234a1087 290 /* STM32F373xC */
mbed_official 237:f3da66175598 291
mbed_official 237:f3da66175598 292 #endif /* HAL_PCD_MODULE_ENABLED */
mbed_official 237:f3da66175598 293 /**
mbed_official 237:f3da66175598 294 * @}
mbed_official 237:f3da66175598 295 */
mbed_official 237:f3da66175598 296
mbed_official 237:f3da66175598 297 /**
mbed_official 237:f3da66175598 298 * @}
mbed_official 237:f3da66175598 299 */
mbed_official 237:f3da66175598 300
mbed_official 237:f3da66175598 301 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/