mbed library sources

Dependents:   frdm_kl05z_gpio_test

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Fri May 30 15:30:09 2014 +0100
Revision:
218:44081b78fdc2
Parent:
205:c41fc65bcfb4
Synchronized with git revision d854859072d318241476ccc5f335965444d4c1d8

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

[NUCLEO_F072RB] Update CubeF0 HAL driver

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 205:c41fc65bcfb4 1 /**
mbed_official 205:c41fc65bcfb4 2 ******************************************************************************
mbed_official 205:c41fc65bcfb4 3 * @file stm32f0xx_hal_pcd.c
mbed_official 205:c41fc65bcfb4 4 * @author MCD Application Team
mbed_official 205:c41fc65bcfb4 5 * @version V1.0.0
mbed_official 218:44081b78fdc2 6 * @date 28-May-2014
mbed_official 205:c41fc65bcfb4 7 * @brief PCD HAL module driver.
mbed_official 205:c41fc65bcfb4 8 * This file provides firmware functions to manage the following
mbed_official 205:c41fc65bcfb4 9 * functionalities of the USB Peripheral Controller:
mbed_official 205:c41fc65bcfb4 10 * + Initialization and de-initialization functions
mbed_official 205:c41fc65bcfb4 11 * + IO operation functions
mbed_official 205:c41fc65bcfb4 12 * + Peripheral Control functions
mbed_official 205:c41fc65bcfb4 13 * + Peripheral State functions
mbed_official 205:c41fc65bcfb4 14 *
mbed_official 205:c41fc65bcfb4 15 @verbatim
mbed_official 205:c41fc65bcfb4 16 ==============================================================================
mbed_official 205:c41fc65bcfb4 17 ##### How to use this driver #####
mbed_official 205:c41fc65bcfb4 18 ==============================================================================
mbed_official 205:c41fc65bcfb4 19 [..]
mbed_official 205:c41fc65bcfb4 20 The PCD HAL driver can be used as follows:
mbed_official 205:c41fc65bcfb4 21
mbed_official 205:c41fc65bcfb4 22 (#) Declare a PCD_HandleTypeDef handle structure, for example:
mbed_official 205:c41fc65bcfb4 23 PCD_HandleTypeDef hpcd;
mbed_official 205:c41fc65bcfb4 24
mbed_official 205:c41fc65bcfb4 25 (#) Fill parameters of Init structure in HCD handle
mbed_official 205:c41fc65bcfb4 26
mbed_official 205:c41fc65bcfb4 27 (#) Call HAL_PCD_Init() API to initialize the HCD peripheral (Core, Device core, ...)
mbed_official 205:c41fc65bcfb4 28
mbed_official 205:c41fc65bcfb4 29 (#) Initialize the PCD low level resources through the HAL_PCD_MspInit() API:
mbed_official 205:c41fc65bcfb4 30 (##) Enable the PCD/USB Low Level interface clock using
mbed_official 205:c41fc65bcfb4 31 (+++) __USB_CLK_ENABLE);
mbed_official 205:c41fc65bcfb4 32
mbed_official 205:c41fc65bcfb4 33 (##) Initialize the related GPIO clocks
mbed_official 205:c41fc65bcfb4 34 (##) Configure PCD pin-out
mbed_official 205:c41fc65bcfb4 35 (##) Configure PCD NVIC interrupt
mbed_official 205:c41fc65bcfb4 36
mbed_official 205:c41fc65bcfb4 37 (#)Associate the Upper USB device stack to the HAL PCD Driver:
mbed_official 205:c41fc65bcfb4 38 (##) hpcd.pData = pdev;
mbed_official 205:c41fc65bcfb4 39
mbed_official 205:c41fc65bcfb4 40 (#)Enable HCD transmission and reception:
mbed_official 205:c41fc65bcfb4 41 (##) HAL_PCD_Start();
mbed_official 205:c41fc65bcfb4 42
mbed_official 205:c41fc65bcfb4 43 @endverbatim
mbed_official 205:c41fc65bcfb4 44 ******************************************************************************
mbed_official 205:c41fc65bcfb4 45 * @attention
mbed_official 205:c41fc65bcfb4 46 *
mbed_official 205:c41fc65bcfb4 47 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
mbed_official 205:c41fc65bcfb4 48 *
mbed_official 205:c41fc65bcfb4 49 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 205:c41fc65bcfb4 50 * are permitted provided that the following conditions are met:
mbed_official 205:c41fc65bcfb4 51 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 205:c41fc65bcfb4 52 * this list of conditions and the following disclaimer.
mbed_official 205:c41fc65bcfb4 53 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 205:c41fc65bcfb4 54 * this list of conditions and the following disclaimer in the documentation
mbed_official 205:c41fc65bcfb4 55 * and/or other materials provided with the distribution.
mbed_official 205:c41fc65bcfb4 56 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 205:c41fc65bcfb4 57 * may be used to endorse or promote products derived from this software
mbed_official 205:c41fc65bcfb4 58 * without specific prior written permission.
mbed_official 205:c41fc65bcfb4 59 *
mbed_official 205:c41fc65bcfb4 60 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 205:c41fc65bcfb4 61 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 205:c41fc65bcfb4 62 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 205:c41fc65bcfb4 63 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 205:c41fc65bcfb4 64 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 205:c41fc65bcfb4 65 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 205:c41fc65bcfb4 66 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 205:c41fc65bcfb4 67 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 205:c41fc65bcfb4 68 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 205:c41fc65bcfb4 69 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 205:c41fc65bcfb4 70 *
mbed_official 205:c41fc65bcfb4 71 ******************************************************************************
mbed_official 205:c41fc65bcfb4 72 */
mbed_official 205:c41fc65bcfb4 73
mbed_official 205:c41fc65bcfb4 74 /* Includes ------------------------------------------------------------------*/
mbed_official 205:c41fc65bcfb4 75 #include "stm32f0xx_hal.h"
mbed_official 205:c41fc65bcfb4 76
mbed_official 205:c41fc65bcfb4 77 /** @addtogroup STM32F0xx_HAL_Driver
mbed_official 205:c41fc65bcfb4 78 * @{
mbed_official 205:c41fc65bcfb4 79 */
mbed_official 205:c41fc65bcfb4 80
mbed_official 205:c41fc65bcfb4 81 /** @defgroup PCD
mbed_official 205:c41fc65bcfb4 82 * @brief PCD HAL module driver
mbed_official 205:c41fc65bcfb4 83 * @{
mbed_official 205:c41fc65bcfb4 84 */
mbed_official 205:c41fc65bcfb4 85
mbed_official 205:c41fc65bcfb4 86 #ifdef HAL_PCD_MODULE_ENABLED
mbed_official 205:c41fc65bcfb4 87
mbed_official 205:c41fc65bcfb4 88 #if defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F072xB) || defined(STM32F078xx)
mbed_official 205:c41fc65bcfb4 89
mbed_official 205:c41fc65bcfb4 90 /* Private typedef -----------------------------------------------------------*/
mbed_official 205:c41fc65bcfb4 91 /* Private define ------------------------------------------------------------*/
mbed_official 205:c41fc65bcfb4 92 #define BTABLE_ADDRESS (0x000)
mbed_official 205:c41fc65bcfb4 93 /* Private macro -------------------------------------------------------------*/
mbed_official 205:c41fc65bcfb4 94 /* Private variables ---------------------------------------------------------*/
mbed_official 205:c41fc65bcfb4 95 /* Private function prototypes -----------------------------------------------*/
mbed_official 205:c41fc65bcfb4 96 static HAL_StatusTypeDef PCD_EP_ISR_Handler(PCD_HandleTypeDef *hpcd);
mbed_official 205:c41fc65bcfb4 97 void PCD_WritePMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes);
mbed_official 205:c41fc65bcfb4 98 void PCD_ReadPMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes);
mbed_official 205:c41fc65bcfb4 99 /* Private functions ---------------------------------------------------------*/
mbed_official 205:c41fc65bcfb4 100
mbed_official 205:c41fc65bcfb4 101
mbed_official 205:c41fc65bcfb4 102 /** @defgroup PCD_Private_Functions
mbed_official 205:c41fc65bcfb4 103 * @{
mbed_official 205:c41fc65bcfb4 104 */
mbed_official 205:c41fc65bcfb4 105
mbed_official 205:c41fc65bcfb4 106 /** @defgroup PCD_Group1 Initialization and de-initialization functions
mbed_official 205:c41fc65bcfb4 107 * @brief Initialization and Configuration functions
mbed_official 205:c41fc65bcfb4 108 *
mbed_official 205:c41fc65bcfb4 109 @verbatim
mbed_official 205:c41fc65bcfb4 110 ===============================================================================
mbed_official 205:c41fc65bcfb4 111 ##### Initialization and de-initialization functions #####
mbed_official 205:c41fc65bcfb4 112 ===============================================================================
mbed_official 205:c41fc65bcfb4 113 [..] This section provides functions allowing to:
mbed_official 205:c41fc65bcfb4 114
mbed_official 205:c41fc65bcfb4 115 @endverbatim
mbed_official 205:c41fc65bcfb4 116 * @{
mbed_official 205:c41fc65bcfb4 117 */
mbed_official 205:c41fc65bcfb4 118
mbed_official 205:c41fc65bcfb4 119 /**
mbed_official 205:c41fc65bcfb4 120 * @brief Initializes the PCD according to the specified
mbed_official 205:c41fc65bcfb4 121 * parameters in the PCD_InitTypeDef and create the associated handle.
mbed_official 205:c41fc65bcfb4 122 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 123 * @retval HAL status
mbed_official 205:c41fc65bcfb4 124 */
mbed_official 205:c41fc65bcfb4 125 HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd)
mbed_official 205:c41fc65bcfb4 126 {
mbed_official 205:c41fc65bcfb4 127 uint32_t i = 0;
mbed_official 205:c41fc65bcfb4 128
mbed_official 205:c41fc65bcfb4 129 uint32_t wInterrupt_Mask = 0;
mbed_official 205:c41fc65bcfb4 130
mbed_official 205:c41fc65bcfb4 131 /* Check the PCD handle allocation */
mbed_official 205:c41fc65bcfb4 132 if(hpcd == NULL)
mbed_official 205:c41fc65bcfb4 133 {
mbed_official 205:c41fc65bcfb4 134 return HAL_ERROR;
mbed_official 205:c41fc65bcfb4 135 }
mbed_official 205:c41fc65bcfb4 136
mbed_official 205:c41fc65bcfb4 137 /* Check the parameters */
mbed_official 205:c41fc65bcfb4 138 assert_param(IS_PCD_ALL_INSTANCE(hpcd->Instance));
mbed_official 205:c41fc65bcfb4 139
mbed_official 205:c41fc65bcfb4 140 hpcd->State = PCD_BUSY;
mbed_official 205:c41fc65bcfb4 141
mbed_official 205:c41fc65bcfb4 142 /* Init the low level hardware : GPIO, CLOCK, NVIC... */
mbed_official 205:c41fc65bcfb4 143 HAL_PCD_MspInit(hpcd);
mbed_official 205:c41fc65bcfb4 144
mbed_official 205:c41fc65bcfb4 145 /* Init endpoints structures */
mbed_official 205:c41fc65bcfb4 146 for (i = 0; i < hpcd->Init.dev_endpoints ; i++)
mbed_official 205:c41fc65bcfb4 147 {
mbed_official 205:c41fc65bcfb4 148 /* Init ep structure */
mbed_official 205:c41fc65bcfb4 149 hpcd->IN_ep[i].is_in = 1;
mbed_official 205:c41fc65bcfb4 150 hpcd->IN_ep[i].num = i;
mbed_official 205:c41fc65bcfb4 151 /* Control until ep is actvated */
mbed_official 205:c41fc65bcfb4 152 hpcd->IN_ep[i].type = PCD_EP_TYPE_CTRL;
mbed_official 205:c41fc65bcfb4 153 hpcd->IN_ep[i].maxpacket = 0;
mbed_official 205:c41fc65bcfb4 154 hpcd->IN_ep[i].xfer_buff = 0;
mbed_official 205:c41fc65bcfb4 155 hpcd->IN_ep[i].xfer_len = 0;
mbed_official 205:c41fc65bcfb4 156 }
mbed_official 205:c41fc65bcfb4 157
mbed_official 205:c41fc65bcfb4 158 for (i = 0; i < hpcd->Init.dev_endpoints ; i++)
mbed_official 205:c41fc65bcfb4 159 {
mbed_official 205:c41fc65bcfb4 160 hpcd->OUT_ep[i].is_in = 0;
mbed_official 205:c41fc65bcfb4 161 hpcd->OUT_ep[i].num = i;
mbed_official 205:c41fc65bcfb4 162 /* Control until ep is activated */
mbed_official 205:c41fc65bcfb4 163 hpcd->OUT_ep[i].type = PCD_EP_TYPE_CTRL;
mbed_official 205:c41fc65bcfb4 164 hpcd->OUT_ep[i].maxpacket = 0;
mbed_official 205:c41fc65bcfb4 165 hpcd->OUT_ep[i].xfer_buff = 0;
mbed_official 205:c41fc65bcfb4 166 hpcd->OUT_ep[i].xfer_len = 0;
mbed_official 205:c41fc65bcfb4 167 }
mbed_official 205:c41fc65bcfb4 168
mbed_official 205:c41fc65bcfb4 169 /* Init Device */
mbed_official 205:c41fc65bcfb4 170 /*CNTR_FRES = 1*/
mbed_official 205:c41fc65bcfb4 171 hpcd->Instance->CNTR = USB_CNTR_FRES;
mbed_official 205:c41fc65bcfb4 172
mbed_official 205:c41fc65bcfb4 173 /*CNTR_FRES = 0*/
mbed_official 205:c41fc65bcfb4 174 hpcd->Instance->CNTR = 0;
mbed_official 205:c41fc65bcfb4 175
mbed_official 205:c41fc65bcfb4 176 /*Clear pending interrupts*/
mbed_official 205:c41fc65bcfb4 177 hpcd->Instance->ISTR = 0;
mbed_official 205:c41fc65bcfb4 178
mbed_official 205:c41fc65bcfb4 179 /*Set Btable Adress*/
mbed_official 205:c41fc65bcfb4 180 hpcd->Instance->BTABLE = BTABLE_ADDRESS;
mbed_official 205:c41fc65bcfb4 181
mbed_official 205:c41fc65bcfb4 182 /*set wInterrupt_Mask global variable*/
mbed_official 205:c41fc65bcfb4 183 wInterrupt_Mask = USB_CNTR_CTRM | USB_CNTR_WKUPM | USB_CNTR_SUSPM | USB_CNTR_ERRM \
mbed_official 205:c41fc65bcfb4 184 | USB_CNTR_ESOFM | USB_CNTR_RESETM;
mbed_official 205:c41fc65bcfb4 185
mbed_official 205:c41fc65bcfb4 186 /*Set interrupt mask*/
mbed_official 205:c41fc65bcfb4 187 hpcd->Instance->CNTR = wInterrupt_Mask;
mbed_official 205:c41fc65bcfb4 188
mbed_official 205:c41fc65bcfb4 189 hpcd->USB_Address = 0;
mbed_official 205:c41fc65bcfb4 190 hpcd->State= PCD_READY;
mbed_official 205:c41fc65bcfb4 191
mbed_official 205:c41fc65bcfb4 192 return HAL_OK;
mbed_official 205:c41fc65bcfb4 193 }
mbed_official 205:c41fc65bcfb4 194
mbed_official 205:c41fc65bcfb4 195 /**
mbed_official 205:c41fc65bcfb4 196 * @brief DeInitializes the PCD peripheral
mbed_official 205:c41fc65bcfb4 197 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 198 * @retval HAL status
mbed_official 205:c41fc65bcfb4 199 */
mbed_official 205:c41fc65bcfb4 200 HAL_StatusTypeDef HAL_PCD_DeInit(PCD_HandleTypeDef *hpcd)
mbed_official 205:c41fc65bcfb4 201 {
mbed_official 205:c41fc65bcfb4 202 /* Check the PCD handle allocation */
mbed_official 205:c41fc65bcfb4 203 if(hpcd == NULL)
mbed_official 205:c41fc65bcfb4 204 {
mbed_official 205:c41fc65bcfb4 205 return HAL_ERROR;
mbed_official 205:c41fc65bcfb4 206 }
mbed_official 205:c41fc65bcfb4 207
mbed_official 205:c41fc65bcfb4 208 hpcd->State = PCD_BUSY;
mbed_official 205:c41fc65bcfb4 209
mbed_official 205:c41fc65bcfb4 210 /* Stop Device */
mbed_official 205:c41fc65bcfb4 211 HAL_PCD_Stop(hpcd);
mbed_official 205:c41fc65bcfb4 212
mbed_official 205:c41fc65bcfb4 213 /* DeInit the low level hardware */
mbed_official 205:c41fc65bcfb4 214 HAL_PCD_MspDeInit(hpcd);
mbed_official 205:c41fc65bcfb4 215
mbed_official 205:c41fc65bcfb4 216 hpcd->State = PCD_READY;
mbed_official 205:c41fc65bcfb4 217
mbed_official 205:c41fc65bcfb4 218 return HAL_OK;
mbed_official 205:c41fc65bcfb4 219 }
mbed_official 205:c41fc65bcfb4 220
mbed_official 205:c41fc65bcfb4 221 /**
mbed_official 205:c41fc65bcfb4 222 * @brief Initializes the PCD MSP.
mbed_official 205:c41fc65bcfb4 223 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 224 * @retval None
mbed_official 205:c41fc65bcfb4 225 */
mbed_official 205:c41fc65bcfb4 226 __weak void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
mbed_official 205:c41fc65bcfb4 227 {
mbed_official 205:c41fc65bcfb4 228 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 205:c41fc65bcfb4 229 the HAL_PCD_MspInit could be implemented in the user file
mbed_official 205:c41fc65bcfb4 230 */
mbed_official 205:c41fc65bcfb4 231 }
mbed_official 205:c41fc65bcfb4 232
mbed_official 205:c41fc65bcfb4 233 /**
mbed_official 205:c41fc65bcfb4 234 * @brief DeInitializes PCD MSP.
mbed_official 205:c41fc65bcfb4 235 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 236 * @retval None
mbed_official 205:c41fc65bcfb4 237 */
mbed_official 205:c41fc65bcfb4 238 __weak void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd)
mbed_official 205:c41fc65bcfb4 239 {
mbed_official 205:c41fc65bcfb4 240 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 205:c41fc65bcfb4 241 the HAL_PCD_MspDeInit could be implemented in the user file
mbed_official 205:c41fc65bcfb4 242 */
mbed_official 205:c41fc65bcfb4 243 }
mbed_official 205:c41fc65bcfb4 244
mbed_official 205:c41fc65bcfb4 245 /**
mbed_official 205:c41fc65bcfb4 246 * @}
mbed_official 205:c41fc65bcfb4 247 */
mbed_official 205:c41fc65bcfb4 248
mbed_official 205:c41fc65bcfb4 249 /** @defgroup PCD_Group2 IO operation functions
mbed_official 205:c41fc65bcfb4 250 * @brief Data transfers functions
mbed_official 205:c41fc65bcfb4 251 *
mbed_official 205:c41fc65bcfb4 252 @verbatim
mbed_official 205:c41fc65bcfb4 253 ===============================================================================
mbed_official 205:c41fc65bcfb4 254 ##### IO operation functions #####
mbed_official 205:c41fc65bcfb4 255 ===============================================================================
mbed_official 205:c41fc65bcfb4 256 [..]
mbed_official 205:c41fc65bcfb4 257 This subsection provides a set of functions allowing to manage the PCD data
mbed_official 205:c41fc65bcfb4 258 transfers.
mbed_official 205:c41fc65bcfb4 259
mbed_official 205:c41fc65bcfb4 260 @endverbatim
mbed_official 205:c41fc65bcfb4 261 * @{
mbed_official 205:c41fc65bcfb4 262 */
mbed_official 205:c41fc65bcfb4 263
mbed_official 205:c41fc65bcfb4 264 /**
mbed_official 205:c41fc65bcfb4 265 * @brief Start The USB OTG Device.
mbed_official 205:c41fc65bcfb4 266 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 267 * @retval HAL status
mbed_official 205:c41fc65bcfb4 268 */
mbed_official 205:c41fc65bcfb4 269 HAL_StatusTypeDef HAL_PCD_Start(PCD_HandleTypeDef *hpcd)
mbed_official 205:c41fc65bcfb4 270 {
mbed_official 205:c41fc65bcfb4 271 /* Enabling DP Pull-Down bit to Connect internal pull-up on USB DP line */
mbed_official 205:c41fc65bcfb4 272 hpcd->Instance->BCDR |= USB_BCDR_DPPU;
mbed_official 205:c41fc65bcfb4 273
mbed_official 205:c41fc65bcfb4 274 return HAL_OK;
mbed_official 205:c41fc65bcfb4 275 }
mbed_official 205:c41fc65bcfb4 276
mbed_official 205:c41fc65bcfb4 277 /**
mbed_official 205:c41fc65bcfb4 278 * @brief Stop The USB OTG Device.
mbed_official 205:c41fc65bcfb4 279 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 280 * @retval HAL status
mbed_official 205:c41fc65bcfb4 281 */
mbed_official 205:c41fc65bcfb4 282 HAL_StatusTypeDef HAL_PCD_Stop(PCD_HandleTypeDef *hpcd)
mbed_official 205:c41fc65bcfb4 283 {
mbed_official 205:c41fc65bcfb4 284 __HAL_LOCK(hpcd);
mbed_official 205:c41fc65bcfb4 285
mbed_official 205:c41fc65bcfb4 286 /* disable all interrupts and force USB reset */
mbed_official 205:c41fc65bcfb4 287 hpcd->Instance->CNTR = USB_CNTR_FRES;
mbed_official 205:c41fc65bcfb4 288
mbed_official 205:c41fc65bcfb4 289 /* clear interrupt status register */
mbed_official 205:c41fc65bcfb4 290 hpcd->Instance->ISTR = 0;
mbed_official 205:c41fc65bcfb4 291
mbed_official 205:c41fc65bcfb4 292 /* switch-off device */
mbed_official 205:c41fc65bcfb4 293 hpcd->Instance->CNTR = (USB_CNTR_FRES | USB_CNTR_PDWN);
mbed_official 205:c41fc65bcfb4 294
mbed_official 205:c41fc65bcfb4 295 __HAL_UNLOCK(hpcd);
mbed_official 205:c41fc65bcfb4 296 return HAL_OK;
mbed_official 205:c41fc65bcfb4 297 }
mbed_official 205:c41fc65bcfb4 298
mbed_official 205:c41fc65bcfb4 299 /**
mbed_official 205:c41fc65bcfb4 300 * @brief This function handles PCD Endpoint interrupt request.
mbed_official 205:c41fc65bcfb4 301 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 302 * @retval HAL status
mbed_official 205:c41fc65bcfb4 303 */
mbed_official 205:c41fc65bcfb4 304 static HAL_StatusTypeDef PCD_EP_ISR_Handler(PCD_HandleTypeDef *hpcd)
mbed_official 205:c41fc65bcfb4 305 {
mbed_official 205:c41fc65bcfb4 306 PCD_EPTypeDef *ep;
mbed_official 205:c41fc65bcfb4 307 uint16_t count=0;
mbed_official 205:c41fc65bcfb4 308 uint8_t EPindex;
mbed_official 205:c41fc65bcfb4 309 __IO uint16_t wIstr;
mbed_official 205:c41fc65bcfb4 310 __IO uint16_t wEPVal = 0;
mbed_official 205:c41fc65bcfb4 311
mbed_official 205:c41fc65bcfb4 312 /* stay in loop while pending interrupts */
mbed_official 205:c41fc65bcfb4 313 while (((wIstr = hpcd->Instance->ISTR) & USB_ISTR_CTR) != 0)
mbed_official 205:c41fc65bcfb4 314 {
mbed_official 205:c41fc65bcfb4 315 /* extract highest priority endpoint number */
mbed_official 205:c41fc65bcfb4 316 EPindex = (uint8_t)(wIstr & USB_ISTR_EP_ID);
mbed_official 205:c41fc65bcfb4 317
mbed_official 205:c41fc65bcfb4 318 if (EPindex == 0)
mbed_official 205:c41fc65bcfb4 319 {
mbed_official 205:c41fc65bcfb4 320 /* Decode and service control endpoint interrupt */
mbed_official 205:c41fc65bcfb4 321
mbed_official 205:c41fc65bcfb4 322 /* DIR bit = origin of the interrupt */
mbed_official 205:c41fc65bcfb4 323 if ((wIstr & USB_ISTR_DIR) == 0)
mbed_official 205:c41fc65bcfb4 324 {
mbed_official 205:c41fc65bcfb4 325 /* DIR = 0 */
mbed_official 205:c41fc65bcfb4 326
mbed_official 205:c41fc65bcfb4 327 /* DIR = 0 => IN int */
mbed_official 205:c41fc65bcfb4 328 /* DIR = 0 implies that (EP_CTR_TX = 1) always */
mbed_official 205:c41fc65bcfb4 329 PCD_CLEAR_TX_EP_CTR(hpcd->Instance, PCD_ENDP0);
mbed_official 205:c41fc65bcfb4 330 ep = &hpcd->IN_ep[0];
mbed_official 205:c41fc65bcfb4 331
mbed_official 205:c41fc65bcfb4 332 ep->xfer_count = PCD_GET_EP_TX_CNT(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 333 ep->xfer_buff += ep->xfer_count;
mbed_official 205:c41fc65bcfb4 334
mbed_official 205:c41fc65bcfb4 335 /* TX COMPLETE */
mbed_official 205:c41fc65bcfb4 336 HAL_PCD_DataInStageCallback(hpcd, 0);
mbed_official 205:c41fc65bcfb4 337
mbed_official 205:c41fc65bcfb4 338
mbed_official 205:c41fc65bcfb4 339 if((hpcd->USB_Address > 0)&& ( ep->xfer_len == 0))
mbed_official 205:c41fc65bcfb4 340 {
mbed_official 205:c41fc65bcfb4 341 hpcd->Instance->DADDR = (hpcd->USB_Address | USB_DADDR_EF);
mbed_official 205:c41fc65bcfb4 342 hpcd->USB_Address = 0;
mbed_official 205:c41fc65bcfb4 343 }
mbed_official 205:c41fc65bcfb4 344
mbed_official 205:c41fc65bcfb4 345 }
mbed_official 205:c41fc65bcfb4 346 else
mbed_official 205:c41fc65bcfb4 347 {
mbed_official 205:c41fc65bcfb4 348 /* DIR = 1 */
mbed_official 205:c41fc65bcfb4 349
mbed_official 205:c41fc65bcfb4 350 /* DIR = 1 & CTR_RX => SETUP or OUT int */
mbed_official 205:c41fc65bcfb4 351 /* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */
mbed_official 205:c41fc65bcfb4 352 ep = &hpcd->OUT_ep[0];
mbed_official 205:c41fc65bcfb4 353 wEPVal = PCD_GET_ENDPOINT(hpcd->Instance, PCD_ENDP0);
mbed_official 205:c41fc65bcfb4 354
mbed_official 205:c41fc65bcfb4 355 if ((wEPVal & USB_EP_SETUP) != 0)
mbed_official 205:c41fc65bcfb4 356 {
mbed_official 205:c41fc65bcfb4 357 /* Get SETUP Packet*/
mbed_official 205:c41fc65bcfb4 358 ep->xfer_count = PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 359 PCD_ReadPMA(hpcd->Instance, (uint8_t*)hpcd->Setup ,ep->pmaadress , ep->xfer_count);
mbed_official 205:c41fc65bcfb4 360 /* SETUP bit kept frozen while CTR_RX = 1*/
mbed_official 205:c41fc65bcfb4 361 PCD_CLEAR_RX_EP_CTR(hpcd->Instance, PCD_ENDP0);
mbed_official 205:c41fc65bcfb4 362
mbed_official 205:c41fc65bcfb4 363 /* Process SETUP Packet*/
mbed_official 205:c41fc65bcfb4 364 HAL_PCD_SetupStageCallback(hpcd);
mbed_official 205:c41fc65bcfb4 365 }
mbed_official 205:c41fc65bcfb4 366
mbed_official 205:c41fc65bcfb4 367 else if ((wEPVal & USB_EP_CTR_RX) != 0)
mbed_official 205:c41fc65bcfb4 368 {
mbed_official 205:c41fc65bcfb4 369 PCD_CLEAR_RX_EP_CTR(hpcd->Instance, PCD_ENDP0);
mbed_official 205:c41fc65bcfb4 370 /* Get Control Data OUT Packet*/
mbed_official 205:c41fc65bcfb4 371 ep->xfer_count = PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 372
mbed_official 205:c41fc65bcfb4 373 if (ep->xfer_count != 0)
mbed_official 205:c41fc65bcfb4 374 {
mbed_official 205:c41fc65bcfb4 375 PCD_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaadress, ep->xfer_count);
mbed_official 205:c41fc65bcfb4 376 ep->xfer_buff+=ep->xfer_count;
mbed_official 205:c41fc65bcfb4 377 }
mbed_official 205:c41fc65bcfb4 378
mbed_official 205:c41fc65bcfb4 379 /* Process Control Data OUT Packet*/
mbed_official 205:c41fc65bcfb4 380 HAL_PCD_DataOutStageCallback(hpcd, 0);
mbed_official 205:c41fc65bcfb4 381
mbed_official 205:c41fc65bcfb4 382 PCD_SET_EP_RX_CNT(hpcd->Instance, PCD_ENDP0, ep->maxpacket);
mbed_official 205:c41fc65bcfb4 383 PCD_SET_EP_RX_STATUS(hpcd->Instance, PCD_ENDP0, USB_EP_RX_VALID);
mbed_official 205:c41fc65bcfb4 384 }
mbed_official 205:c41fc65bcfb4 385 }
mbed_official 205:c41fc65bcfb4 386 }
mbed_official 205:c41fc65bcfb4 387 else
mbed_official 205:c41fc65bcfb4 388 {
mbed_official 205:c41fc65bcfb4 389
mbed_official 205:c41fc65bcfb4 390 /* Decode and service non control endpoints interrupt */
mbed_official 205:c41fc65bcfb4 391
mbed_official 205:c41fc65bcfb4 392 /* process related endpoint register */
mbed_official 205:c41fc65bcfb4 393 wEPVal = PCD_GET_ENDPOINT(hpcd->Instance, EPindex);
mbed_official 205:c41fc65bcfb4 394 if ((wEPVal & USB_EP_CTR_RX) != 0)
mbed_official 205:c41fc65bcfb4 395 {
mbed_official 205:c41fc65bcfb4 396 /* clear int flag */
mbed_official 205:c41fc65bcfb4 397 PCD_CLEAR_RX_EP_CTR(hpcd->Instance, EPindex);
mbed_official 205:c41fc65bcfb4 398 ep = &hpcd->OUT_ep[EPindex];
mbed_official 205:c41fc65bcfb4 399
mbed_official 205:c41fc65bcfb4 400 /* OUT double Buffering*/
mbed_official 205:c41fc65bcfb4 401 if (ep->doublebuffer == 0)
mbed_official 205:c41fc65bcfb4 402 {
mbed_official 205:c41fc65bcfb4 403 count = PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 404 if (count != 0)
mbed_official 205:c41fc65bcfb4 405 {
mbed_official 205:c41fc65bcfb4 406 PCD_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaadress, count);
mbed_official 205:c41fc65bcfb4 407 }
mbed_official 205:c41fc65bcfb4 408 }
mbed_official 205:c41fc65bcfb4 409 else
mbed_official 205:c41fc65bcfb4 410 {
mbed_official 205:c41fc65bcfb4 411 if (PCD_GET_ENDPOINT(hpcd->Instance, ep->num) & USB_EP_DTOG_RX)
mbed_official 205:c41fc65bcfb4 412 {
mbed_official 205:c41fc65bcfb4 413 /*read from endpoint BUF0Addr buffer*/
mbed_official 205:c41fc65bcfb4 414 count = PCD_GET_EP_DBUF0_CNT(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 415 if (count != 0)
mbed_official 205:c41fc65bcfb4 416 {
mbed_official 205:c41fc65bcfb4 417 PCD_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr0, count);
mbed_official 205:c41fc65bcfb4 418 }
mbed_official 205:c41fc65bcfb4 419 }
mbed_official 205:c41fc65bcfb4 420 else
mbed_official 205:c41fc65bcfb4 421 {
mbed_official 205:c41fc65bcfb4 422 /*read from endpoint BUF1Addr buffer*/
mbed_official 205:c41fc65bcfb4 423 count = PCD_GET_EP_DBUF1_CNT(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 424 if (count != 0)
mbed_official 205:c41fc65bcfb4 425 {
mbed_official 205:c41fc65bcfb4 426 PCD_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr1, count);
mbed_official 205:c41fc65bcfb4 427 }
mbed_official 205:c41fc65bcfb4 428 }
mbed_official 205:c41fc65bcfb4 429 PCD_FreeUserBuffer(hpcd->Instance, ep->num, PCD_EP_DBUF_OUT);
mbed_official 205:c41fc65bcfb4 430 }
mbed_official 205:c41fc65bcfb4 431 /*multi-packet on the NON control OUT endpoint*/
mbed_official 205:c41fc65bcfb4 432 ep->xfer_count+=count;
mbed_official 205:c41fc65bcfb4 433 ep->xfer_buff+=count;
mbed_official 205:c41fc65bcfb4 434
mbed_official 205:c41fc65bcfb4 435 if ((ep->xfer_len == 0) || (count < ep->maxpacket))
mbed_official 205:c41fc65bcfb4 436 {
mbed_official 205:c41fc65bcfb4 437 /* RX COMPLETE */
mbed_official 205:c41fc65bcfb4 438 HAL_PCD_DataOutStageCallback(hpcd, ep->num);
mbed_official 205:c41fc65bcfb4 439 }
mbed_official 205:c41fc65bcfb4 440 else
mbed_official 205:c41fc65bcfb4 441 {
mbed_official 205:c41fc65bcfb4 442 HAL_PCD_EP_Receive(hpcd, ep->num, ep->xfer_buff, ep->xfer_len);
mbed_official 205:c41fc65bcfb4 443 }
mbed_official 205:c41fc65bcfb4 444
mbed_official 205:c41fc65bcfb4 445 } /* if((wEPVal & EP_CTR_RX) */
mbed_official 205:c41fc65bcfb4 446
mbed_official 205:c41fc65bcfb4 447 if ((wEPVal & USB_EP_CTR_TX) != 0)
mbed_official 205:c41fc65bcfb4 448 {
mbed_official 205:c41fc65bcfb4 449 ep = &hpcd->IN_ep[EPindex];
mbed_official 205:c41fc65bcfb4 450
mbed_official 205:c41fc65bcfb4 451 /* clear int flag */
mbed_official 205:c41fc65bcfb4 452 PCD_CLEAR_TX_EP_CTR(hpcd->Instance, EPindex);
mbed_official 205:c41fc65bcfb4 453
mbed_official 205:c41fc65bcfb4 454 /* IN double Buffering*/
mbed_official 205:c41fc65bcfb4 455 if (ep->doublebuffer == 0)
mbed_official 205:c41fc65bcfb4 456 {
mbed_official 205:c41fc65bcfb4 457 ep->xfer_count = PCD_GET_EP_TX_CNT(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 458 if (ep->xfer_count != 0)
mbed_official 205:c41fc65bcfb4 459 {
mbed_official 205:c41fc65bcfb4 460 PCD_WritePMA(hpcd->Instance, ep->xfer_buff, ep->pmaadress, ep->xfer_count);
mbed_official 205:c41fc65bcfb4 461 }
mbed_official 205:c41fc65bcfb4 462 }
mbed_official 205:c41fc65bcfb4 463 else
mbed_official 205:c41fc65bcfb4 464 {
mbed_official 205:c41fc65bcfb4 465 if (PCD_GET_ENDPOINT(hpcd->Instance, ep->num) & USB_EP_DTOG_TX)
mbed_official 205:c41fc65bcfb4 466 {
mbed_official 205:c41fc65bcfb4 467 /*read from endpoint BUF0Addr buffer*/
mbed_official 205:c41fc65bcfb4 468 ep->xfer_count = PCD_GET_EP_DBUF0_CNT(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 469 if (ep->xfer_count != 0)
mbed_official 205:c41fc65bcfb4 470 {
mbed_official 205:c41fc65bcfb4 471 PCD_WritePMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr0, ep->xfer_count);
mbed_official 205:c41fc65bcfb4 472 }
mbed_official 205:c41fc65bcfb4 473 }
mbed_official 205:c41fc65bcfb4 474 else
mbed_official 205:c41fc65bcfb4 475 {
mbed_official 205:c41fc65bcfb4 476 /*read from endpoint BUF1Addr buffer*/
mbed_official 205:c41fc65bcfb4 477 ep->xfer_count = PCD_GET_EP_DBUF1_CNT(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 478 if (ep->xfer_count != 0)
mbed_official 205:c41fc65bcfb4 479 {
mbed_official 205:c41fc65bcfb4 480 PCD_WritePMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr1, ep->xfer_count);
mbed_official 205:c41fc65bcfb4 481 }
mbed_official 205:c41fc65bcfb4 482 }
mbed_official 205:c41fc65bcfb4 483 PCD_FreeUserBuffer(hpcd->Instance, ep->num, PCD_EP_DBUF_IN);
mbed_official 205:c41fc65bcfb4 484 }
mbed_official 205:c41fc65bcfb4 485 /*multi-packet on the NON control IN endpoint*/
mbed_official 205:c41fc65bcfb4 486 ep->xfer_count = PCD_GET_EP_TX_CNT(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 487 ep->xfer_buff+=ep->xfer_count;
mbed_official 205:c41fc65bcfb4 488
mbed_official 205:c41fc65bcfb4 489 /* Zero Length Packet? */
mbed_official 205:c41fc65bcfb4 490 if (ep->xfer_len == 0)
mbed_official 205:c41fc65bcfb4 491 {
mbed_official 205:c41fc65bcfb4 492 /* TX COMPLETE */
mbed_official 205:c41fc65bcfb4 493 HAL_PCD_DataInStageCallback(hpcd, ep->num);
mbed_official 205:c41fc65bcfb4 494 }
mbed_official 205:c41fc65bcfb4 495 else
mbed_official 205:c41fc65bcfb4 496 {
mbed_official 205:c41fc65bcfb4 497 HAL_PCD_EP_Transmit(hpcd, ep->num, ep->xfer_buff, ep->xfer_len);
mbed_official 205:c41fc65bcfb4 498 }
mbed_official 205:c41fc65bcfb4 499 }
mbed_official 205:c41fc65bcfb4 500 }
mbed_official 205:c41fc65bcfb4 501 }
mbed_official 205:c41fc65bcfb4 502 return HAL_OK;
mbed_official 205:c41fc65bcfb4 503 }
mbed_official 205:c41fc65bcfb4 504 /**
mbed_official 205:c41fc65bcfb4 505 * @brief This function handles PCD interrupt request.
mbed_official 205:c41fc65bcfb4 506 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 507 * @retval HAL status
mbed_official 205:c41fc65bcfb4 508 */
mbed_official 205:c41fc65bcfb4 509 void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd)
mbed_official 205:c41fc65bcfb4 510 {
mbed_official 205:c41fc65bcfb4 511 uint32_t wInterrupt_Mask = 0;
mbed_official 205:c41fc65bcfb4 512
mbed_official 205:c41fc65bcfb4 513 if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_CTR))
mbed_official 205:c41fc65bcfb4 514 {
mbed_official 205:c41fc65bcfb4 515 /* servicing of the endpoint correct transfer interrupt */
mbed_official 205:c41fc65bcfb4 516 /* clear of the CTR flag into the sub */
mbed_official 205:c41fc65bcfb4 517 PCD_EP_ISR_Handler(hpcd);
mbed_official 205:c41fc65bcfb4 518 }
mbed_official 205:c41fc65bcfb4 519
mbed_official 205:c41fc65bcfb4 520 if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_RESET))
mbed_official 205:c41fc65bcfb4 521 {
mbed_official 205:c41fc65bcfb4 522 __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_RESET);
mbed_official 205:c41fc65bcfb4 523 HAL_PCD_ResetCallback(hpcd);
mbed_official 205:c41fc65bcfb4 524 HAL_PCD_SetAddress(hpcd, 0);
mbed_official 205:c41fc65bcfb4 525 }
mbed_official 205:c41fc65bcfb4 526
mbed_official 205:c41fc65bcfb4 527 if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_PMAOVR))
mbed_official 205:c41fc65bcfb4 528 {
mbed_official 205:c41fc65bcfb4 529 __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_PMAOVR);
mbed_official 205:c41fc65bcfb4 530 }
mbed_official 205:c41fc65bcfb4 531
mbed_official 205:c41fc65bcfb4 532 if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_ERR))
mbed_official 205:c41fc65bcfb4 533 {
mbed_official 205:c41fc65bcfb4 534 __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_ERR);
mbed_official 205:c41fc65bcfb4 535 }
mbed_official 205:c41fc65bcfb4 536
mbed_official 205:c41fc65bcfb4 537 if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_WKUP))
mbed_official 205:c41fc65bcfb4 538 {
mbed_official 205:c41fc65bcfb4 539
mbed_official 205:c41fc65bcfb4 540 hpcd->Instance->CNTR &= ~(USB_CNTR_LPMODE);
mbed_official 205:c41fc65bcfb4 541
mbed_official 205:c41fc65bcfb4 542 /*set wInterrupt_Mask global variable*/
mbed_official 205:c41fc65bcfb4 543 wInterrupt_Mask = USB_CNTR_CTRM | USB_CNTR_WKUPM | USB_CNTR_SUSPM | USB_CNTR_ERRM \
mbed_official 205:c41fc65bcfb4 544 | USB_CNTR_ESOFM | USB_CNTR_RESETM;
mbed_official 205:c41fc65bcfb4 545
mbed_official 205:c41fc65bcfb4 546 /*Set interrupt mask*/
mbed_official 205:c41fc65bcfb4 547 hpcd->Instance->CNTR = wInterrupt_Mask;
mbed_official 205:c41fc65bcfb4 548
mbed_official 205:c41fc65bcfb4 549 HAL_PCD_ResumeCallback(hpcd);
mbed_official 205:c41fc65bcfb4 550
mbed_official 205:c41fc65bcfb4 551 __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_WKUP);
mbed_official 205:c41fc65bcfb4 552 }
mbed_official 205:c41fc65bcfb4 553
mbed_official 205:c41fc65bcfb4 554 if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_SUSP))
mbed_official 205:c41fc65bcfb4 555 {
mbed_official 205:c41fc65bcfb4 556 /* clear of the ISTR bit must be done after setting of CNTR_FSUSP */
mbed_official 205:c41fc65bcfb4 557 __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_SUSP);
mbed_official 205:c41fc65bcfb4 558
mbed_official 205:c41fc65bcfb4 559 /* Force low-power mode in the macrocell */
mbed_official 205:c41fc65bcfb4 560 hpcd->Instance->CNTR |= USB_CNTR_FSUSP;
mbed_official 205:c41fc65bcfb4 561 hpcd->Instance->CNTR |= USB_CNTR_LPMODE;
mbed_official 205:c41fc65bcfb4 562
mbed_official 205:c41fc65bcfb4 563 if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_WKUP) == 0)
mbed_official 205:c41fc65bcfb4 564 {
mbed_official 205:c41fc65bcfb4 565 HAL_PCD_SuspendCallback(hpcd);
mbed_official 205:c41fc65bcfb4 566 }
mbed_official 205:c41fc65bcfb4 567 }
mbed_official 205:c41fc65bcfb4 568
mbed_official 205:c41fc65bcfb4 569 if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_SOF))
mbed_official 205:c41fc65bcfb4 570 {
mbed_official 205:c41fc65bcfb4 571 __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_SOF);
mbed_official 205:c41fc65bcfb4 572 HAL_PCD_SOFCallback(hpcd);
mbed_official 205:c41fc65bcfb4 573 }
mbed_official 205:c41fc65bcfb4 574
mbed_official 205:c41fc65bcfb4 575 if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_ESOF))
mbed_official 205:c41fc65bcfb4 576 {
mbed_official 205:c41fc65bcfb4 577 /* clear ESOF flag in ISTR */
mbed_official 205:c41fc65bcfb4 578 __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_ESOF);
mbed_official 205:c41fc65bcfb4 579 }
mbed_official 205:c41fc65bcfb4 580 }
mbed_official 205:c41fc65bcfb4 581
mbed_official 205:c41fc65bcfb4 582 /**
mbed_official 205:c41fc65bcfb4 583 * @brief Data out stage callbacks
mbed_official 205:c41fc65bcfb4 584 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 585 * @param epnum: endpoint number
mbed_official 205:c41fc65bcfb4 586 * @retval None
mbed_official 205:c41fc65bcfb4 587 */
mbed_official 205:c41fc65bcfb4 588 __weak void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
mbed_official 205:c41fc65bcfb4 589 {
mbed_official 205:c41fc65bcfb4 590 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 205:c41fc65bcfb4 591 the HAL_PCD_DataOutStageCallback could be implemented in the user file
mbed_official 205:c41fc65bcfb4 592 */
mbed_official 205:c41fc65bcfb4 593 }
mbed_official 205:c41fc65bcfb4 594
mbed_official 205:c41fc65bcfb4 595 /**
mbed_official 205:c41fc65bcfb4 596 * @brief Data IN stage callbacks
mbed_official 205:c41fc65bcfb4 597 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 598 * @param epnum: endpoint number
mbed_official 205:c41fc65bcfb4 599 * @retval None
mbed_official 205:c41fc65bcfb4 600 */
mbed_official 205:c41fc65bcfb4 601 __weak void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
mbed_official 205:c41fc65bcfb4 602 {
mbed_official 205:c41fc65bcfb4 603 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 205:c41fc65bcfb4 604 the HAL_PCD_DataInStageCallback could be implemented in the user file
mbed_official 205:c41fc65bcfb4 605 */
mbed_official 205:c41fc65bcfb4 606 }
mbed_official 205:c41fc65bcfb4 607 /**
mbed_official 205:c41fc65bcfb4 608 * @brief Setup stage callback
mbed_official 205:c41fc65bcfb4 609 * @param hpcd: ppp handle
mbed_official 205:c41fc65bcfb4 610 * @retval None
mbed_official 205:c41fc65bcfb4 611 */
mbed_official 205:c41fc65bcfb4 612 __weak void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd)
mbed_official 205:c41fc65bcfb4 613 {
mbed_official 205:c41fc65bcfb4 614 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 205:c41fc65bcfb4 615 the HAL_PCD_SetupStageCallback could be implemented in the user file
mbed_official 205:c41fc65bcfb4 616 */
mbed_official 205:c41fc65bcfb4 617 }
mbed_official 205:c41fc65bcfb4 618
mbed_official 205:c41fc65bcfb4 619 /**
mbed_official 205:c41fc65bcfb4 620 * @brief USB Start Of Frame callbacks
mbed_official 205:c41fc65bcfb4 621 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 622 * @retval None
mbed_official 205:c41fc65bcfb4 623 */
mbed_official 205:c41fc65bcfb4 624 __weak void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd)
mbed_official 205:c41fc65bcfb4 625 {
mbed_official 205:c41fc65bcfb4 626 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 205:c41fc65bcfb4 627 the HAL_PCD_SOFCallback could be implemented in the user file
mbed_official 205:c41fc65bcfb4 628 */
mbed_official 205:c41fc65bcfb4 629 }
mbed_official 205:c41fc65bcfb4 630
mbed_official 205:c41fc65bcfb4 631 /**
mbed_official 205:c41fc65bcfb4 632 * @brief USB Reset callbacks
mbed_official 205:c41fc65bcfb4 633 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 634 * @retval None
mbed_official 205:c41fc65bcfb4 635 */
mbed_official 205:c41fc65bcfb4 636 __weak void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
mbed_official 205:c41fc65bcfb4 637 {
mbed_official 205:c41fc65bcfb4 638 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 205:c41fc65bcfb4 639 the HAL_PCD_ResetCallback could be implemented in the user file
mbed_official 205:c41fc65bcfb4 640 */
mbed_official 205:c41fc65bcfb4 641 }
mbed_official 205:c41fc65bcfb4 642
mbed_official 205:c41fc65bcfb4 643
mbed_official 205:c41fc65bcfb4 644 /**
mbed_official 205:c41fc65bcfb4 645 * @brief Suspend event callbacks
mbed_official 205:c41fc65bcfb4 646 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 647 * @retval None
mbed_official 205:c41fc65bcfb4 648 */
mbed_official 205:c41fc65bcfb4 649 __weak void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
mbed_official 205:c41fc65bcfb4 650 {
mbed_official 205:c41fc65bcfb4 651 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 205:c41fc65bcfb4 652 the HAL_PCD_SuspendCallback could be implemented in the user file
mbed_official 205:c41fc65bcfb4 653 */
mbed_official 205:c41fc65bcfb4 654 }
mbed_official 205:c41fc65bcfb4 655
mbed_official 205:c41fc65bcfb4 656 /**
mbed_official 205:c41fc65bcfb4 657 * @brief Resume event callbacks
mbed_official 205:c41fc65bcfb4 658 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 659 * @retval None
mbed_official 205:c41fc65bcfb4 660 */
mbed_official 205:c41fc65bcfb4 661 __weak void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
mbed_official 205:c41fc65bcfb4 662 {
mbed_official 205:c41fc65bcfb4 663 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 205:c41fc65bcfb4 664 the HAL_PCD_ResumeCallback could be implemented in the user file
mbed_official 205:c41fc65bcfb4 665 */
mbed_official 205:c41fc65bcfb4 666 }
mbed_official 205:c41fc65bcfb4 667
mbed_official 205:c41fc65bcfb4 668 /**
mbed_official 205:c41fc65bcfb4 669 * @brief Incomplete ISO OUT callbacks
mbed_official 205:c41fc65bcfb4 670 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 671 * @param epnum: endpoint number
mbed_official 205:c41fc65bcfb4 672 * @retval None
mbed_official 205:c41fc65bcfb4 673 */
mbed_official 205:c41fc65bcfb4 674 __weak void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
mbed_official 205:c41fc65bcfb4 675 {
mbed_official 205:c41fc65bcfb4 676 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 205:c41fc65bcfb4 677 the HAL_PCD_ISOOUTIncompleteCallback could be implemented in the user file
mbed_official 205:c41fc65bcfb4 678 */
mbed_official 205:c41fc65bcfb4 679 }
mbed_official 205:c41fc65bcfb4 680
mbed_official 205:c41fc65bcfb4 681 /**
mbed_official 205:c41fc65bcfb4 682 * @brief Incomplete ISO IN callbacks
mbed_official 205:c41fc65bcfb4 683 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 684 * @param epnum: endpoint number
mbed_official 205:c41fc65bcfb4 685 * @retval None
mbed_official 205:c41fc65bcfb4 686 */
mbed_official 205:c41fc65bcfb4 687 __weak void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
mbed_official 205:c41fc65bcfb4 688 {
mbed_official 205:c41fc65bcfb4 689 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 205:c41fc65bcfb4 690 the HAL_PCD_ISOINIncompleteCallback could be implemented in the user file
mbed_official 205:c41fc65bcfb4 691 */
mbed_official 205:c41fc65bcfb4 692 }
mbed_official 205:c41fc65bcfb4 693
mbed_official 205:c41fc65bcfb4 694 /**
mbed_official 205:c41fc65bcfb4 695 * @brief Connection event callbacks
mbed_official 205:c41fc65bcfb4 696 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 697 * @retval None
mbed_official 205:c41fc65bcfb4 698 */
mbed_official 205:c41fc65bcfb4 699 __weak void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
mbed_official 205:c41fc65bcfb4 700 {
mbed_official 205:c41fc65bcfb4 701 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 205:c41fc65bcfb4 702 the HAL_PCD_ConnectCallback could be implemented in the user file
mbed_official 205:c41fc65bcfb4 703 */
mbed_official 205:c41fc65bcfb4 704 }
mbed_official 205:c41fc65bcfb4 705
mbed_official 205:c41fc65bcfb4 706 /**
mbed_official 205:c41fc65bcfb4 707 * @brief Disconnection event callbacks
mbed_official 205:c41fc65bcfb4 708 * @param hpcd: ppp handle
mbed_official 205:c41fc65bcfb4 709 * @retval None
mbed_official 205:c41fc65bcfb4 710 */
mbed_official 205:c41fc65bcfb4 711 __weak void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
mbed_official 205:c41fc65bcfb4 712 {
mbed_official 205:c41fc65bcfb4 713 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 205:c41fc65bcfb4 714 the HAL_PCD_DisconnectCallback could be implemented in the user file
mbed_official 205:c41fc65bcfb4 715 */
mbed_official 205:c41fc65bcfb4 716 }
mbed_official 205:c41fc65bcfb4 717
mbed_official 205:c41fc65bcfb4 718 /**
mbed_official 205:c41fc65bcfb4 719 * @}
mbed_official 205:c41fc65bcfb4 720 */
mbed_official 205:c41fc65bcfb4 721
mbed_official 205:c41fc65bcfb4 722 /** @defgroup PCD_Group3 Peripheral Control functions
mbed_official 205:c41fc65bcfb4 723 * @brief management functions
mbed_official 205:c41fc65bcfb4 724 *
mbed_official 205:c41fc65bcfb4 725 @verbatim
mbed_official 205:c41fc65bcfb4 726 ===============================================================================
mbed_official 205:c41fc65bcfb4 727 ##### Peripheral Control functions #####
mbed_official 205:c41fc65bcfb4 728 ===============================================================================
mbed_official 205:c41fc65bcfb4 729 [..]
mbed_official 205:c41fc65bcfb4 730 This subsection provides a set of functions allowing to control the PCD data
mbed_official 205:c41fc65bcfb4 731 transfers.
mbed_official 205:c41fc65bcfb4 732
mbed_official 205:c41fc65bcfb4 733 @endverbatim
mbed_official 205:c41fc65bcfb4 734 * @{
mbed_official 205:c41fc65bcfb4 735 */
mbed_official 205:c41fc65bcfb4 736
mbed_official 205:c41fc65bcfb4 737 /**
mbed_official 205:c41fc65bcfb4 738 * @brief Send an amount of data in blocking mode
mbed_official 205:c41fc65bcfb4 739 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 740 * @retval HAL status
mbed_official 205:c41fc65bcfb4 741 */
mbed_official 205:c41fc65bcfb4 742 HAL_StatusTypeDef HAL_PCD_DevConnect(PCD_HandleTypeDef *hpcd)
mbed_official 205:c41fc65bcfb4 743 {
mbed_official 205:c41fc65bcfb4 744 __HAL_LOCK(hpcd);
mbed_official 205:c41fc65bcfb4 745
mbed_official 205:c41fc65bcfb4 746 /* Enabling DP Pull-Down bit to Connect internal pull-up on USB DP line */
mbed_official 205:c41fc65bcfb4 747 hpcd->Instance->BCDR |= USB_BCDR_DPPU;
mbed_official 205:c41fc65bcfb4 748
mbed_official 205:c41fc65bcfb4 749 __HAL_UNLOCK(hpcd);
mbed_official 205:c41fc65bcfb4 750 return HAL_OK;
mbed_official 205:c41fc65bcfb4 751 }
mbed_official 205:c41fc65bcfb4 752
mbed_official 205:c41fc65bcfb4 753 /**
mbed_official 205:c41fc65bcfb4 754 * @brief Send an amount of data in blocking mode
mbed_official 205:c41fc65bcfb4 755 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 756 * @retval HAL status
mbed_official 205:c41fc65bcfb4 757 */
mbed_official 205:c41fc65bcfb4 758 HAL_StatusTypeDef HAL_PCD_DevDisconnect(PCD_HandleTypeDef *hpcd)
mbed_official 205:c41fc65bcfb4 759 {
mbed_official 205:c41fc65bcfb4 760 __HAL_LOCK(hpcd);
mbed_official 205:c41fc65bcfb4 761
mbed_official 205:c41fc65bcfb4 762 /* Disable DP Pull-Down bit*/
mbed_official 205:c41fc65bcfb4 763 hpcd->Instance->BCDR &= ~(USB_BCDR_DPPU);
mbed_official 205:c41fc65bcfb4 764
mbed_official 205:c41fc65bcfb4 765 __HAL_UNLOCK(hpcd);
mbed_official 205:c41fc65bcfb4 766 return HAL_OK;
mbed_official 205:c41fc65bcfb4 767 }
mbed_official 205:c41fc65bcfb4 768
mbed_official 205:c41fc65bcfb4 769 /**
mbed_official 205:c41fc65bcfb4 770 * @brief Set the USB Device address
mbed_official 205:c41fc65bcfb4 771 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 772 * @param address: new device address
mbed_official 205:c41fc65bcfb4 773 * @retval HAL status
mbed_official 205:c41fc65bcfb4 774 */
mbed_official 205:c41fc65bcfb4 775 HAL_StatusTypeDef HAL_PCD_SetAddress(PCD_HandleTypeDef *hpcd, uint8_t address)
mbed_official 205:c41fc65bcfb4 776 {
mbed_official 205:c41fc65bcfb4 777 __HAL_LOCK(hpcd);
mbed_official 205:c41fc65bcfb4 778
mbed_official 205:c41fc65bcfb4 779 if(address == 0)
mbed_official 205:c41fc65bcfb4 780 {
mbed_official 205:c41fc65bcfb4 781 /* set device address and enable function */
mbed_official 205:c41fc65bcfb4 782 hpcd->Instance->DADDR = USB_DADDR_EF;
mbed_official 205:c41fc65bcfb4 783 }
mbed_official 205:c41fc65bcfb4 784 else /* USB Address will be applied later */
mbed_official 205:c41fc65bcfb4 785 {
mbed_official 205:c41fc65bcfb4 786 hpcd->USB_Address = address;
mbed_official 205:c41fc65bcfb4 787 }
mbed_official 205:c41fc65bcfb4 788
mbed_official 205:c41fc65bcfb4 789 __HAL_UNLOCK(hpcd);
mbed_official 205:c41fc65bcfb4 790 return HAL_OK;
mbed_official 205:c41fc65bcfb4 791 }
mbed_official 205:c41fc65bcfb4 792 /**
mbed_official 205:c41fc65bcfb4 793 * @brief Open and configure an endpoint
mbed_official 205:c41fc65bcfb4 794 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 795 * @param ep_addr: endpoint address
mbed_official 205:c41fc65bcfb4 796 * @param ep_mps: endpoint max packert size
mbed_official 205:c41fc65bcfb4 797 * @param ep_type: endpoint type
mbed_official 205:c41fc65bcfb4 798 * @retval HAL status
mbed_official 205:c41fc65bcfb4 799 */
mbed_official 205:c41fc65bcfb4 800 HAL_StatusTypeDef HAL_PCD_EP_Open(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type)
mbed_official 205:c41fc65bcfb4 801 {
mbed_official 205:c41fc65bcfb4 802 HAL_StatusTypeDef ret = HAL_OK;
mbed_official 205:c41fc65bcfb4 803 PCD_EPTypeDef *ep;
mbed_official 205:c41fc65bcfb4 804
mbed_official 205:c41fc65bcfb4 805 if ((ep_addr & 0x80) == 0x80)
mbed_official 205:c41fc65bcfb4 806 {
mbed_official 205:c41fc65bcfb4 807 ep = &hpcd->IN_ep[ep_addr & 0x7F];
mbed_official 205:c41fc65bcfb4 808 }
mbed_official 205:c41fc65bcfb4 809 else
mbed_official 205:c41fc65bcfb4 810 {
mbed_official 205:c41fc65bcfb4 811 ep = &hpcd->OUT_ep[ep_addr & 0x7F];
mbed_official 205:c41fc65bcfb4 812 }
mbed_official 205:c41fc65bcfb4 813 ep->num = ep_addr & 0x7F;
mbed_official 205:c41fc65bcfb4 814
mbed_official 205:c41fc65bcfb4 815 ep->is_in = (0x80 & ep_addr) != 0;
mbed_official 205:c41fc65bcfb4 816 ep->maxpacket = ep_mps;
mbed_official 205:c41fc65bcfb4 817 ep->type = ep_type;
mbed_official 205:c41fc65bcfb4 818
mbed_official 205:c41fc65bcfb4 819 __HAL_LOCK(hpcd);
mbed_official 205:c41fc65bcfb4 820
mbed_official 205:c41fc65bcfb4 821 /* initialize Endpoint */
mbed_official 205:c41fc65bcfb4 822 switch (ep->type)
mbed_official 205:c41fc65bcfb4 823 {
mbed_official 205:c41fc65bcfb4 824 case PCD_EP_TYPE_CTRL:
mbed_official 205:c41fc65bcfb4 825 PCD_SET_EPTYPE(hpcd->Instance, ep->num, USB_EP_CONTROL);
mbed_official 205:c41fc65bcfb4 826 break;
mbed_official 205:c41fc65bcfb4 827 case PCD_EP_TYPE_BULK:
mbed_official 205:c41fc65bcfb4 828 PCD_SET_EPTYPE(hpcd->Instance, ep->num, USB_EP_BULK);
mbed_official 205:c41fc65bcfb4 829 break;
mbed_official 205:c41fc65bcfb4 830 case PCD_EP_TYPE_INTR:
mbed_official 205:c41fc65bcfb4 831 PCD_SET_EPTYPE(hpcd->Instance, ep->num, USB_EP_INTERRUPT);
mbed_official 205:c41fc65bcfb4 832 break;
mbed_official 205:c41fc65bcfb4 833 case PCD_EP_TYPE_ISOC:
mbed_official 205:c41fc65bcfb4 834 PCD_SET_EPTYPE(hpcd->Instance, ep->num, USB_EP_ISOCHRONOUS);
mbed_official 205:c41fc65bcfb4 835 break;
mbed_official 205:c41fc65bcfb4 836 }
mbed_official 205:c41fc65bcfb4 837
mbed_official 205:c41fc65bcfb4 838 PCD_SET_EP_ADDRESS(hpcd->Instance, ep->num, ep->num);
mbed_official 205:c41fc65bcfb4 839
mbed_official 205:c41fc65bcfb4 840 if (ep->doublebuffer == 0)
mbed_official 205:c41fc65bcfb4 841 {
mbed_official 205:c41fc65bcfb4 842 if (ep->is_in)
mbed_official 205:c41fc65bcfb4 843 {
mbed_official 205:c41fc65bcfb4 844 /*Set the endpoint Transmit buffer address */
mbed_official 205:c41fc65bcfb4 845 PCD_SET_EP_TX_ADDRESS(hpcd->Instance, ep->num, ep->pmaadress);
mbed_official 205:c41fc65bcfb4 846 PCD_CLEAR_TX_DTOG(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 847 /* Configure NAK status for the Endpoint*/
mbed_official 205:c41fc65bcfb4 848 PCD_SET_EP_TX_STATUS(hpcd->Instance, ep->num, USB_EP_TX_NAK);
mbed_official 205:c41fc65bcfb4 849 }
mbed_official 205:c41fc65bcfb4 850 else
mbed_official 205:c41fc65bcfb4 851 {
mbed_official 205:c41fc65bcfb4 852 /*Set the endpoint Receive buffer address */
mbed_official 205:c41fc65bcfb4 853 PCD_SET_EP_RX_ADDRESS(hpcd->Instance, ep->num, ep->pmaadress);
mbed_official 205:c41fc65bcfb4 854 /*Set the endpoint Receive buffer counter*/
mbed_official 205:c41fc65bcfb4 855 PCD_SET_EP_RX_CNT(hpcd->Instance, ep->num, ep->maxpacket);
mbed_official 205:c41fc65bcfb4 856 PCD_CLEAR_RX_DTOG(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 857 /* Configure VALID status for the Endpoint*/
mbed_official 205:c41fc65bcfb4 858 PCD_SET_EP_RX_STATUS(hpcd->Instance, ep->num, USB_EP_RX_VALID);
mbed_official 205:c41fc65bcfb4 859 }
mbed_official 205:c41fc65bcfb4 860 }
mbed_official 205:c41fc65bcfb4 861 /*Double Buffer*/
mbed_official 205:c41fc65bcfb4 862 else
mbed_official 205:c41fc65bcfb4 863 {
mbed_official 205:c41fc65bcfb4 864 /*Set the endpoint as double buffered*/
mbed_official 205:c41fc65bcfb4 865 PCD_SET_EP_DBUF(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 866 /*Set buffer address for double buffered mode*/
mbed_official 205:c41fc65bcfb4 867 PCD_SET_EP_DBUF_ADDR(hpcd->Instance, ep->num,ep->pmaaddr0, ep->pmaaddr1);
mbed_official 205:c41fc65bcfb4 868
mbed_official 205:c41fc65bcfb4 869 if (ep->is_in==0)
mbed_official 205:c41fc65bcfb4 870 {
mbed_official 205:c41fc65bcfb4 871 /* Clear the data toggle bits for the endpoint IN/OUT*/
mbed_official 205:c41fc65bcfb4 872 PCD_CLEAR_RX_DTOG(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 873 PCD_CLEAR_TX_DTOG(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 874
mbed_official 205:c41fc65bcfb4 875 /* Reset value of the data toggle bits for the endpoint out*/
mbed_official 205:c41fc65bcfb4 876 PCD_TX_DTOG(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 877
mbed_official 205:c41fc65bcfb4 878 PCD_SET_EP_RX_STATUS(hpcd->Instance, ep->num, USB_EP_RX_VALID);
mbed_official 205:c41fc65bcfb4 879 PCD_SET_EP_TX_STATUS(hpcd->Instance, ep->num, USB_EP_TX_DIS);
mbed_official 205:c41fc65bcfb4 880 }
mbed_official 205:c41fc65bcfb4 881 else
mbed_official 205:c41fc65bcfb4 882 {
mbed_official 205:c41fc65bcfb4 883 /* Clear the data toggle bits for the endpoint IN/OUT*/
mbed_official 205:c41fc65bcfb4 884 PCD_CLEAR_RX_DTOG(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 885 PCD_CLEAR_TX_DTOG(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 886 PCD_RX_DTOG(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 887 /* Configure DISABLE status for the Endpoint*/
mbed_official 205:c41fc65bcfb4 888 PCD_SET_EP_TX_STATUS(hpcd->Instance, ep->num, USB_EP_TX_DIS);
mbed_official 205:c41fc65bcfb4 889 PCD_SET_EP_RX_STATUS(hpcd->Instance, ep->num, USB_EP_RX_DIS);
mbed_official 205:c41fc65bcfb4 890 }
mbed_official 205:c41fc65bcfb4 891 }
mbed_official 205:c41fc65bcfb4 892
mbed_official 205:c41fc65bcfb4 893 __HAL_UNLOCK(hpcd);
mbed_official 205:c41fc65bcfb4 894 return ret;
mbed_official 205:c41fc65bcfb4 895 }
mbed_official 205:c41fc65bcfb4 896
mbed_official 205:c41fc65bcfb4 897
mbed_official 205:c41fc65bcfb4 898 /**
mbed_official 205:c41fc65bcfb4 899 * @brief Deactivate an endpoint
mbed_official 205:c41fc65bcfb4 900 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 901 * @param ep_addr: endpoint address
mbed_official 205:c41fc65bcfb4 902 * @retval HAL status
mbed_official 205:c41fc65bcfb4 903 */
mbed_official 205:c41fc65bcfb4 904 HAL_StatusTypeDef HAL_PCD_EP_Close(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
mbed_official 205:c41fc65bcfb4 905 {
mbed_official 205:c41fc65bcfb4 906 PCD_EPTypeDef *ep;
mbed_official 205:c41fc65bcfb4 907
mbed_official 205:c41fc65bcfb4 908 if ((ep_addr & 0x80) == 0x80)
mbed_official 205:c41fc65bcfb4 909 {
mbed_official 205:c41fc65bcfb4 910 ep = &hpcd->IN_ep[ep_addr & 0x7F];
mbed_official 205:c41fc65bcfb4 911 }
mbed_official 205:c41fc65bcfb4 912 else
mbed_official 205:c41fc65bcfb4 913 {
mbed_official 205:c41fc65bcfb4 914 ep = &hpcd->OUT_ep[ep_addr & 0x7F];
mbed_official 205:c41fc65bcfb4 915 }
mbed_official 205:c41fc65bcfb4 916 ep->num = ep_addr & 0x7F;
mbed_official 205:c41fc65bcfb4 917
mbed_official 205:c41fc65bcfb4 918 ep->is_in = (0x80 & ep_addr) != 0;
mbed_official 205:c41fc65bcfb4 919
mbed_official 205:c41fc65bcfb4 920 __HAL_LOCK(hpcd);
mbed_official 205:c41fc65bcfb4 921
mbed_official 205:c41fc65bcfb4 922 if (ep->doublebuffer == 0)
mbed_official 205:c41fc65bcfb4 923 {
mbed_official 205:c41fc65bcfb4 924 if (ep->is_in)
mbed_official 205:c41fc65bcfb4 925 {
mbed_official 205:c41fc65bcfb4 926 PCD_CLEAR_TX_DTOG(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 927 /* Configure DISABLE status for the Endpoint*/
mbed_official 205:c41fc65bcfb4 928 PCD_SET_EP_TX_STATUS(hpcd->Instance, ep->num, USB_EP_TX_DIS);
mbed_official 205:c41fc65bcfb4 929 }
mbed_official 205:c41fc65bcfb4 930 else
mbed_official 205:c41fc65bcfb4 931 {
mbed_official 205:c41fc65bcfb4 932 PCD_CLEAR_RX_DTOG(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 933 /* Configure DISABLE status for the Endpoint*/
mbed_official 205:c41fc65bcfb4 934 PCD_SET_EP_RX_STATUS(hpcd->Instance, ep->num, USB_EP_RX_DIS);
mbed_official 205:c41fc65bcfb4 935 }
mbed_official 205:c41fc65bcfb4 936 }
mbed_official 205:c41fc65bcfb4 937 /*Double Buffer*/
mbed_official 205:c41fc65bcfb4 938 else
mbed_official 205:c41fc65bcfb4 939 {
mbed_official 205:c41fc65bcfb4 940 if (ep->is_in==0)
mbed_official 205:c41fc65bcfb4 941 {
mbed_official 205:c41fc65bcfb4 942 /* Clear the data toggle bits for the endpoint IN/OUT*/
mbed_official 205:c41fc65bcfb4 943 PCD_CLEAR_RX_DTOG(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 944 PCD_CLEAR_TX_DTOG(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 945
mbed_official 205:c41fc65bcfb4 946 /* Reset value of the data toggle bits for the endpoint out*/
mbed_official 205:c41fc65bcfb4 947 PCD_TX_DTOG(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 948
mbed_official 205:c41fc65bcfb4 949 PCD_SET_EP_RX_STATUS(hpcd->Instance, ep->num, USB_EP_RX_DIS);
mbed_official 205:c41fc65bcfb4 950 PCD_SET_EP_TX_STATUS(hpcd->Instance, ep->num, USB_EP_TX_DIS);
mbed_official 205:c41fc65bcfb4 951 }
mbed_official 205:c41fc65bcfb4 952 else
mbed_official 205:c41fc65bcfb4 953 {
mbed_official 205:c41fc65bcfb4 954 /* Clear the data toggle bits for the endpoint IN/OUT*/
mbed_official 205:c41fc65bcfb4 955 PCD_CLEAR_RX_DTOG(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 956 PCD_CLEAR_TX_DTOG(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 957 PCD_RX_DTOG(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 958 /* Configure DISABLE status for the Endpoint*/
mbed_official 205:c41fc65bcfb4 959 PCD_SET_EP_TX_STATUS(hpcd->Instance, ep->num, USB_EP_TX_DIS);
mbed_official 205:c41fc65bcfb4 960 PCD_SET_EP_RX_STATUS(hpcd->Instance, ep->num, USB_EP_RX_DIS);
mbed_official 205:c41fc65bcfb4 961 }
mbed_official 205:c41fc65bcfb4 962 }
mbed_official 205:c41fc65bcfb4 963
mbed_official 205:c41fc65bcfb4 964 __HAL_UNLOCK(hpcd);
mbed_official 205:c41fc65bcfb4 965 return HAL_OK;
mbed_official 205:c41fc65bcfb4 966 }
mbed_official 205:c41fc65bcfb4 967
mbed_official 205:c41fc65bcfb4 968
mbed_official 205:c41fc65bcfb4 969 /**
mbed_official 205:c41fc65bcfb4 970 * @brief Receive an amount of data
mbed_official 205:c41fc65bcfb4 971 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 972 * @param ep_addr: endpoint address
mbed_official 205:c41fc65bcfb4 973 * @param pBuf: pointer to the reception buffer
mbed_official 205:c41fc65bcfb4 974 * @param len: amount of data to be received
mbed_official 205:c41fc65bcfb4 975 * @retval HAL status
mbed_official 205:c41fc65bcfb4 976 */
mbed_official 205:c41fc65bcfb4 977 HAL_StatusTypeDef HAL_PCD_EP_Receive(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len)
mbed_official 205:c41fc65bcfb4 978 {
mbed_official 205:c41fc65bcfb4 979
mbed_official 205:c41fc65bcfb4 980 PCD_EPTypeDef *ep;
mbed_official 205:c41fc65bcfb4 981
mbed_official 205:c41fc65bcfb4 982 ep = &hpcd->OUT_ep[ep_addr & 0x7F];
mbed_official 205:c41fc65bcfb4 983
mbed_official 205:c41fc65bcfb4 984 /*setup and start the Xfer */
mbed_official 205:c41fc65bcfb4 985 ep->xfer_buff = pBuf;
mbed_official 205:c41fc65bcfb4 986 ep->xfer_len = len;
mbed_official 205:c41fc65bcfb4 987 ep->xfer_count = 0;
mbed_official 205:c41fc65bcfb4 988 ep->is_in = 0;
mbed_official 205:c41fc65bcfb4 989 ep->num = ep_addr & 0x7F;
mbed_official 205:c41fc65bcfb4 990
mbed_official 205:c41fc65bcfb4 991 __HAL_LOCK(hpcd);
mbed_official 205:c41fc65bcfb4 992
mbed_official 205:c41fc65bcfb4 993 /* Multi packet transfer*/
mbed_official 205:c41fc65bcfb4 994 if (ep->xfer_len > ep->maxpacket)
mbed_official 205:c41fc65bcfb4 995 {
mbed_official 205:c41fc65bcfb4 996 len=ep->maxpacket;
mbed_official 205:c41fc65bcfb4 997 ep->xfer_len-=len;
mbed_official 205:c41fc65bcfb4 998 }
mbed_official 205:c41fc65bcfb4 999 else
mbed_official 205:c41fc65bcfb4 1000 {
mbed_official 205:c41fc65bcfb4 1001 len=ep->xfer_len;
mbed_official 205:c41fc65bcfb4 1002 ep->xfer_len =0;
mbed_official 205:c41fc65bcfb4 1003 }
mbed_official 205:c41fc65bcfb4 1004
mbed_official 205:c41fc65bcfb4 1005 /* configure and validate Rx endpoint */
mbed_official 205:c41fc65bcfb4 1006 if (ep->doublebuffer == 0)
mbed_official 205:c41fc65bcfb4 1007 {
mbed_official 205:c41fc65bcfb4 1008 /*Set RX buffer count*/
mbed_official 205:c41fc65bcfb4 1009 PCD_SET_EP_RX_CNT(hpcd->Instance, ep->num, len);
mbed_official 205:c41fc65bcfb4 1010 }
mbed_official 205:c41fc65bcfb4 1011 else
mbed_official 205:c41fc65bcfb4 1012 {
mbed_official 205:c41fc65bcfb4 1013 /*Set the Double buffer counter*/
mbed_official 205:c41fc65bcfb4 1014 PCD_SET_EP_DBUF1_CNT(hpcd->Instance, ep->num, ep->is_in, len);
mbed_official 205:c41fc65bcfb4 1015 }
mbed_official 205:c41fc65bcfb4 1016
mbed_official 205:c41fc65bcfb4 1017 PCD_SET_EP_RX_STATUS(hpcd->Instance, ep->num, USB_EP_RX_VALID);
mbed_official 205:c41fc65bcfb4 1018
mbed_official 205:c41fc65bcfb4 1019 __HAL_UNLOCK(hpcd);
mbed_official 205:c41fc65bcfb4 1020
mbed_official 205:c41fc65bcfb4 1021 return HAL_OK;
mbed_official 205:c41fc65bcfb4 1022 }
mbed_official 205:c41fc65bcfb4 1023
mbed_official 205:c41fc65bcfb4 1024 /**
mbed_official 205:c41fc65bcfb4 1025 * @brief Get Received Data Size
mbed_official 205:c41fc65bcfb4 1026 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 1027 * @param ep_addr: endpoint address
mbed_official 205:c41fc65bcfb4 1028 * @retval Data Size
mbed_official 205:c41fc65bcfb4 1029 */
mbed_official 205:c41fc65bcfb4 1030 uint16_t HAL_PCD_EP_GetRxCount(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
mbed_official 205:c41fc65bcfb4 1031 {
mbed_official 205:c41fc65bcfb4 1032 return hpcd->OUT_ep[ep_addr & 0x7F].xfer_count;
mbed_official 205:c41fc65bcfb4 1033 }
mbed_official 205:c41fc65bcfb4 1034 /**
mbed_official 205:c41fc65bcfb4 1035 * @brief Send an amount of data
mbed_official 205:c41fc65bcfb4 1036 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 1037 * @param ep_addr: endpoint address
mbed_official 205:c41fc65bcfb4 1038 * @param pBuf: pointer to the transmission buffer
mbed_official 205:c41fc65bcfb4 1039 * @param len: amount of data to be sent
mbed_official 205:c41fc65bcfb4 1040 * @retval HAL status
mbed_official 205:c41fc65bcfb4 1041 */
mbed_official 205:c41fc65bcfb4 1042 HAL_StatusTypeDef HAL_PCD_EP_Transmit(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len)
mbed_official 205:c41fc65bcfb4 1043 {
mbed_official 205:c41fc65bcfb4 1044 PCD_EPTypeDef *ep;
mbed_official 205:c41fc65bcfb4 1045 uint16_t pmabuffer = 0;
mbed_official 205:c41fc65bcfb4 1046
mbed_official 205:c41fc65bcfb4 1047 ep = &hpcd->IN_ep[ep_addr & 0x7F];
mbed_official 205:c41fc65bcfb4 1048
mbed_official 205:c41fc65bcfb4 1049 /*setup and start the Xfer */
mbed_official 205:c41fc65bcfb4 1050 ep->xfer_buff = pBuf;
mbed_official 205:c41fc65bcfb4 1051 ep->xfer_len = len;
mbed_official 205:c41fc65bcfb4 1052 ep->xfer_count = 0;
mbed_official 205:c41fc65bcfb4 1053 ep->is_in = 1;
mbed_official 205:c41fc65bcfb4 1054 ep->num = ep_addr & 0x7F;
mbed_official 205:c41fc65bcfb4 1055
mbed_official 205:c41fc65bcfb4 1056 __HAL_LOCK(hpcd);
mbed_official 205:c41fc65bcfb4 1057
mbed_official 205:c41fc65bcfb4 1058 /*Multi packet transfer*/
mbed_official 205:c41fc65bcfb4 1059 if (ep->xfer_len > ep->maxpacket)
mbed_official 205:c41fc65bcfb4 1060 {
mbed_official 205:c41fc65bcfb4 1061 len=ep->maxpacket;
mbed_official 205:c41fc65bcfb4 1062 ep->xfer_len-=len;
mbed_official 205:c41fc65bcfb4 1063 }
mbed_official 205:c41fc65bcfb4 1064 else
mbed_official 205:c41fc65bcfb4 1065 {
mbed_official 205:c41fc65bcfb4 1066 len=ep->xfer_len;
mbed_official 205:c41fc65bcfb4 1067 ep->xfer_len =0;
mbed_official 205:c41fc65bcfb4 1068 }
mbed_official 205:c41fc65bcfb4 1069
mbed_official 205:c41fc65bcfb4 1070 /* configure and validate Tx endpoint */
mbed_official 205:c41fc65bcfb4 1071 if (ep->doublebuffer == 0)
mbed_official 205:c41fc65bcfb4 1072 {
mbed_official 205:c41fc65bcfb4 1073 PCD_WritePMA(hpcd->Instance, ep->xfer_buff, ep->pmaadress, len);
mbed_official 205:c41fc65bcfb4 1074 PCD_SET_EP_TX_CNT(hpcd->Instance, ep->num, len);
mbed_official 205:c41fc65bcfb4 1075 }
mbed_official 205:c41fc65bcfb4 1076 else
mbed_official 205:c41fc65bcfb4 1077 {
mbed_official 205:c41fc65bcfb4 1078 /*Set the Double buffer counter*/
mbed_official 205:c41fc65bcfb4 1079 PCD_SET_EP_DBUF1_CNT(hpcd->Instance, ep->num, ep->is_in, len);
mbed_official 205:c41fc65bcfb4 1080
mbed_official 205:c41fc65bcfb4 1081 /*Write the data to the USB endpoint*/
mbed_official 205:c41fc65bcfb4 1082 if (PCD_GET_ENDPOINT(hpcd->Instance, ep->num)& USB_EP_DTOG_TX)
mbed_official 205:c41fc65bcfb4 1083 {
mbed_official 205:c41fc65bcfb4 1084 pmabuffer = ep->pmaaddr1;
mbed_official 205:c41fc65bcfb4 1085 }
mbed_official 205:c41fc65bcfb4 1086 else
mbed_official 205:c41fc65bcfb4 1087 {
mbed_official 205:c41fc65bcfb4 1088 pmabuffer = ep->pmaaddr0;
mbed_official 205:c41fc65bcfb4 1089 }
mbed_official 205:c41fc65bcfb4 1090 PCD_WritePMA(hpcd->Instance, ep->xfer_buff, pmabuffer, len);
mbed_official 205:c41fc65bcfb4 1091 PCD_FreeUserBuffer(hpcd->Instance, ep->num, ep->is_in);
mbed_official 205:c41fc65bcfb4 1092 }
mbed_official 205:c41fc65bcfb4 1093
mbed_official 205:c41fc65bcfb4 1094 PCD_SET_EP_TX_STATUS(hpcd->Instance, ep->num, USB_EP_TX_VALID);
mbed_official 205:c41fc65bcfb4 1095
mbed_official 205:c41fc65bcfb4 1096 __HAL_UNLOCK(hpcd);
mbed_official 205:c41fc65bcfb4 1097
mbed_official 205:c41fc65bcfb4 1098 return HAL_OK;
mbed_official 205:c41fc65bcfb4 1099 }
mbed_official 205:c41fc65bcfb4 1100
mbed_official 205:c41fc65bcfb4 1101 /**
mbed_official 205:c41fc65bcfb4 1102 * @brief Set a STALL condition over an endpoint
mbed_official 205:c41fc65bcfb4 1103 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 1104 * @param ep_addr: endpoint address
mbed_official 205:c41fc65bcfb4 1105 * @retval HAL status
mbed_official 205:c41fc65bcfb4 1106 */
mbed_official 205:c41fc65bcfb4 1107 HAL_StatusTypeDef HAL_PCD_EP_SetStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
mbed_official 205:c41fc65bcfb4 1108 {
mbed_official 205:c41fc65bcfb4 1109 PCD_EPTypeDef *ep;
mbed_official 205:c41fc65bcfb4 1110
mbed_official 205:c41fc65bcfb4 1111 __HAL_LOCK(hpcd);
mbed_official 205:c41fc65bcfb4 1112
mbed_official 205:c41fc65bcfb4 1113 if ((0x80 & ep_addr) == 0x80)
mbed_official 205:c41fc65bcfb4 1114 {
mbed_official 205:c41fc65bcfb4 1115 ep = &hpcd->IN_ep[ep_addr & 0x7F];
mbed_official 205:c41fc65bcfb4 1116 }
mbed_official 205:c41fc65bcfb4 1117 else
mbed_official 205:c41fc65bcfb4 1118 {
mbed_official 205:c41fc65bcfb4 1119 ep = &hpcd->OUT_ep[ep_addr];
mbed_official 205:c41fc65bcfb4 1120 }
mbed_official 205:c41fc65bcfb4 1121
mbed_official 205:c41fc65bcfb4 1122 ep->is_stall = 1;
mbed_official 205:c41fc65bcfb4 1123 ep->num = ep_addr & 0x7F;
mbed_official 205:c41fc65bcfb4 1124 ep->is_in = ((ep_addr & 0x80) == 0x80);
mbed_official 205:c41fc65bcfb4 1125
mbed_official 205:c41fc65bcfb4 1126 if (ep->num == 0)
mbed_official 205:c41fc65bcfb4 1127 {
mbed_official 205:c41fc65bcfb4 1128 /* This macro sets STALL status for RX & TX*/
mbed_official 205:c41fc65bcfb4 1129 PCD_SET_EP_TXRX_STATUS(hpcd->Instance, ep->num, USB_EP_RX_STALL, USB_EP_TX_STALL);
mbed_official 205:c41fc65bcfb4 1130 }
mbed_official 205:c41fc65bcfb4 1131 else
mbed_official 205:c41fc65bcfb4 1132 {
mbed_official 205:c41fc65bcfb4 1133 if (ep->is_in)
mbed_official 205:c41fc65bcfb4 1134 {
mbed_official 205:c41fc65bcfb4 1135 PCD_SET_EP_TX_STATUS(hpcd->Instance, ep->num , USB_EP_TX_STALL);
mbed_official 205:c41fc65bcfb4 1136 }
mbed_official 205:c41fc65bcfb4 1137 else
mbed_official 205:c41fc65bcfb4 1138 {
mbed_official 205:c41fc65bcfb4 1139 PCD_SET_EP_RX_STATUS(hpcd->Instance, ep->num , USB_EP_RX_STALL);
mbed_official 205:c41fc65bcfb4 1140 }
mbed_official 205:c41fc65bcfb4 1141 }
mbed_official 205:c41fc65bcfb4 1142 __HAL_UNLOCK(hpcd);
mbed_official 205:c41fc65bcfb4 1143
mbed_official 205:c41fc65bcfb4 1144 return HAL_OK;
mbed_official 205:c41fc65bcfb4 1145 }
mbed_official 205:c41fc65bcfb4 1146
mbed_official 205:c41fc65bcfb4 1147 /**
mbed_official 205:c41fc65bcfb4 1148 * @brief Clear a STALL condition over in an endpoint
mbed_official 205:c41fc65bcfb4 1149 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 1150 * @param ep_addr: endpoint address
mbed_official 205:c41fc65bcfb4 1151 * @retval HAL status
mbed_official 205:c41fc65bcfb4 1152 */
mbed_official 205:c41fc65bcfb4 1153 HAL_StatusTypeDef HAL_PCD_EP_ClrStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
mbed_official 205:c41fc65bcfb4 1154 {
mbed_official 205:c41fc65bcfb4 1155 PCD_EPTypeDef *ep;
mbed_official 205:c41fc65bcfb4 1156
mbed_official 205:c41fc65bcfb4 1157 if ((0x80 & ep_addr) == 0x80)
mbed_official 205:c41fc65bcfb4 1158 {
mbed_official 205:c41fc65bcfb4 1159 ep = &hpcd->IN_ep[ep_addr & 0x7F];
mbed_official 205:c41fc65bcfb4 1160 }
mbed_official 205:c41fc65bcfb4 1161 else
mbed_official 205:c41fc65bcfb4 1162 {
mbed_official 205:c41fc65bcfb4 1163 ep = &hpcd->OUT_ep[ep_addr];
mbed_official 205:c41fc65bcfb4 1164 }
mbed_official 205:c41fc65bcfb4 1165
mbed_official 205:c41fc65bcfb4 1166 ep->is_stall = 0;
mbed_official 205:c41fc65bcfb4 1167 ep->num = ep_addr & 0x7F;
mbed_official 205:c41fc65bcfb4 1168 ep->is_in = ((ep_addr & 0x80) == 0x80);
mbed_official 205:c41fc65bcfb4 1169
mbed_official 205:c41fc65bcfb4 1170 __HAL_LOCK(hpcd);
mbed_official 205:c41fc65bcfb4 1171
mbed_official 205:c41fc65bcfb4 1172 if (ep->is_in)
mbed_official 205:c41fc65bcfb4 1173 {
mbed_official 205:c41fc65bcfb4 1174 PCD_CLEAR_TX_DTOG(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 1175 PCD_SET_EP_TX_STATUS(hpcd->Instance, ep->num, USB_EP_TX_VALID);
mbed_official 205:c41fc65bcfb4 1176 }
mbed_official 205:c41fc65bcfb4 1177 else
mbed_official 205:c41fc65bcfb4 1178 {
mbed_official 205:c41fc65bcfb4 1179 PCD_CLEAR_RX_DTOG(hpcd->Instance, ep->num);
mbed_official 205:c41fc65bcfb4 1180 PCD_SET_EP_RX_STATUS(hpcd->Instance, ep->num, USB_EP_RX_VALID);
mbed_official 205:c41fc65bcfb4 1181 }
mbed_official 205:c41fc65bcfb4 1182 __HAL_UNLOCK(hpcd);
mbed_official 205:c41fc65bcfb4 1183
mbed_official 205:c41fc65bcfb4 1184 return HAL_OK;
mbed_official 205:c41fc65bcfb4 1185 }
mbed_official 205:c41fc65bcfb4 1186
mbed_official 205:c41fc65bcfb4 1187 /**
mbed_official 205:c41fc65bcfb4 1188 * @brief Flush an endpoint
mbed_official 205:c41fc65bcfb4 1189 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 1190 * @param ep_addr: endpoint address
mbed_official 205:c41fc65bcfb4 1191 * @retval HAL status
mbed_official 205:c41fc65bcfb4 1192 */
mbed_official 205:c41fc65bcfb4 1193 HAL_StatusTypeDef HAL_PCD_EP_Flush(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
mbed_official 205:c41fc65bcfb4 1194 {
mbed_official 205:c41fc65bcfb4 1195 return HAL_OK;
mbed_official 205:c41fc65bcfb4 1196 }
mbed_official 205:c41fc65bcfb4 1197
mbed_official 205:c41fc65bcfb4 1198 /**
mbed_official 205:c41fc65bcfb4 1199 * @brief HAL_PCD_ActiveRemoteWakeup : active remote wakeup signalling
mbed_official 205:c41fc65bcfb4 1200 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 1201 * @retval status
mbed_official 205:c41fc65bcfb4 1202 */
mbed_official 205:c41fc65bcfb4 1203 HAL_StatusTypeDef HAL_PCD_ActiveRemoteWakeup(PCD_HandleTypeDef *hpcd)
mbed_official 205:c41fc65bcfb4 1204 {
mbed_official 205:c41fc65bcfb4 1205 hpcd->Instance->CNTR |= USB_CNTR_RESUME;
mbed_official 205:c41fc65bcfb4 1206 return HAL_OK;
mbed_official 205:c41fc65bcfb4 1207 }
mbed_official 205:c41fc65bcfb4 1208
mbed_official 205:c41fc65bcfb4 1209 /**
mbed_official 205:c41fc65bcfb4 1210 * @brief HAL_PCD_DeActiveRemoteWakeup : de-active remote wakeup signalling
mbed_official 205:c41fc65bcfb4 1211 * @param hpcd: PCD handle
mbed_official 205:c41fc65bcfb4 1212 * @retval status
mbed_official 205:c41fc65bcfb4 1213 */
mbed_official 205:c41fc65bcfb4 1214 HAL_StatusTypeDef HAL_PCD_DeActiveRemoteWakeup(PCD_HandleTypeDef *hpcd)
mbed_official 205:c41fc65bcfb4 1215 {
mbed_official 205:c41fc65bcfb4 1216 hpcd->Instance->CNTR &= ~(USB_CNTR_RESUME);
mbed_official 205:c41fc65bcfb4 1217 return HAL_OK;
mbed_official 205:c41fc65bcfb4 1218 }
mbed_official 205:c41fc65bcfb4 1219 /**
mbed_official 205:c41fc65bcfb4 1220 * @brief Copy a buffer from user memory area to packet memory area (PMA)
mbed_official 205:c41fc65bcfb4 1221 * @param USBx: USB peripheral instance register address.
mbed_official 205:c41fc65bcfb4 1222 * @param pbUsrBuf: pointer to user memory area.
mbed_official 205:c41fc65bcfb4 1223 * @param wPMABufAddr: address into PMA.
mbed_official 205:c41fc65bcfb4 1224 * @param wNBytes: no. of bytes to be copied.
mbed_official 205:c41fc65bcfb4 1225 * @retval None
mbed_official 205:c41fc65bcfb4 1226 */
mbed_official 205:c41fc65bcfb4 1227 void PCD_WritePMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
mbed_official 205:c41fc65bcfb4 1228 {
mbed_official 205:c41fc65bcfb4 1229 uint32_t n = (wNBytes + 1) >> 1;
mbed_official 205:c41fc65bcfb4 1230 uint32_t i;
mbed_official 205:c41fc65bcfb4 1231 uint16_t temp1, temp2;
mbed_official 205:c41fc65bcfb4 1232 uint16_t *pdwVal;
mbed_official 205:c41fc65bcfb4 1233 pdwVal = (uint16_t *)(wPMABufAddr + (uint32_t)USBx + 0x400);
mbed_official 205:c41fc65bcfb4 1234
mbed_official 205:c41fc65bcfb4 1235 for (i = n; i != 0; i--)
mbed_official 205:c41fc65bcfb4 1236 {
mbed_official 205:c41fc65bcfb4 1237 temp1 = (uint16_t) * pbUsrBuf;
mbed_official 205:c41fc65bcfb4 1238 pbUsrBuf++;
mbed_official 205:c41fc65bcfb4 1239 temp2 = temp1 | (uint16_t) * pbUsrBuf << 8;
mbed_official 205:c41fc65bcfb4 1240 *pdwVal++ = temp2;
mbed_official 205:c41fc65bcfb4 1241 pbUsrBuf++;
mbed_official 205:c41fc65bcfb4 1242 }
mbed_official 205:c41fc65bcfb4 1243 }
mbed_official 205:c41fc65bcfb4 1244
mbed_official 205:c41fc65bcfb4 1245 /**
mbed_official 205:c41fc65bcfb4 1246 * @brief Copy a buffer from user memory area to packet memory area (PMA)
mbed_official 205:c41fc65bcfb4 1247 * @param USBx: USB peripheral instance register address.
mbed_official 205:c41fc65bcfb4 1248 * @param pbUsrBuf = pointer to user memory area.
mbed_official 205:c41fc65bcfb4 1249 * @param wPMABufAddr: address into PMA.
mbed_official 205:c41fc65bcfb4 1250 * @param wNBytes: no. of bytes to be copied.
mbed_official 205:c41fc65bcfb4 1251 * @retval None
mbed_official 205:c41fc65bcfb4 1252 */
mbed_official 205:c41fc65bcfb4 1253 void PCD_ReadPMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
mbed_official 205:c41fc65bcfb4 1254 {
mbed_official 205:c41fc65bcfb4 1255 uint32_t n = (wNBytes + 1) >> 1;
mbed_official 205:c41fc65bcfb4 1256 uint32_t i;
mbed_official 205:c41fc65bcfb4 1257 uint16_t *pdwVal;
mbed_official 205:c41fc65bcfb4 1258 pdwVal = (uint16_t *)(wPMABufAddr + (uint32_t)USBx + 0x400);
mbed_official 205:c41fc65bcfb4 1259 for (i = n; i != 0; i--)
mbed_official 205:c41fc65bcfb4 1260 {
mbed_official 205:c41fc65bcfb4 1261 *(uint16_t*)pbUsrBuf++ = *pdwVal++;
mbed_official 205:c41fc65bcfb4 1262 pbUsrBuf++;
mbed_official 205:c41fc65bcfb4 1263 }
mbed_official 205:c41fc65bcfb4 1264 }
mbed_official 205:c41fc65bcfb4 1265 /**
mbed_official 205:c41fc65bcfb4 1266 * @}
mbed_official 205:c41fc65bcfb4 1267 */
mbed_official 205:c41fc65bcfb4 1268
mbed_official 205:c41fc65bcfb4 1269 /** @defgroup PCD_Group4 Peripheral State functions
mbed_official 205:c41fc65bcfb4 1270 * @brief Peripheral State functions
mbed_official 205:c41fc65bcfb4 1271 *
mbed_official 205:c41fc65bcfb4 1272 @verbatim
mbed_official 205:c41fc65bcfb4 1273 ===============================================================================
mbed_official 205:c41fc65bcfb4 1274 ##### Peripheral State functions #####
mbed_official 205:c41fc65bcfb4 1275 ===============================================================================
mbed_official 205:c41fc65bcfb4 1276 [..]
mbed_official 205:c41fc65bcfb4 1277 This subsection permit to get in run-time the status of the peripheral
mbed_official 205:c41fc65bcfb4 1278 and the data flow.
mbed_official 205:c41fc65bcfb4 1279
mbed_official 205:c41fc65bcfb4 1280 @endverbatim
mbed_official 205:c41fc65bcfb4 1281 * @{
mbed_official 205:c41fc65bcfb4 1282 */
mbed_official 205:c41fc65bcfb4 1283
mbed_official 205:c41fc65bcfb4 1284 /**
mbed_official 205:c41fc65bcfb4 1285 * @brief Return the PCD state
mbed_official 205:c41fc65bcfb4 1286 * @param hpcd : PCD handle
mbed_official 205:c41fc65bcfb4 1287 * @retval HAL state
mbed_official 205:c41fc65bcfb4 1288 */
mbed_official 205:c41fc65bcfb4 1289 PCD_StateTypeDef HAL_PCD_GetState(PCD_HandleTypeDef *hpcd)
mbed_official 205:c41fc65bcfb4 1290 {
mbed_official 205:c41fc65bcfb4 1291 return hpcd->State;
mbed_official 205:c41fc65bcfb4 1292 }
mbed_official 205:c41fc65bcfb4 1293 /**
mbed_official 205:c41fc65bcfb4 1294 * @}
mbed_official 205:c41fc65bcfb4 1295 */
mbed_official 205:c41fc65bcfb4 1296
mbed_official 205:c41fc65bcfb4 1297 /**
mbed_official 205:c41fc65bcfb4 1298 * @}
mbed_official 205:c41fc65bcfb4 1299 */
mbed_official 205:c41fc65bcfb4 1300
mbed_official 205:c41fc65bcfb4 1301 #endif /* STM32F042x6 || STM32F072xB || STM32F078xx */
mbed_official 205:c41fc65bcfb4 1302
mbed_official 205:c41fc65bcfb4 1303 #endif /* HAL_PCD_MODULE_ENABLED */
mbed_official 205:c41fc65bcfb4 1304 /**
mbed_official 205:c41fc65bcfb4 1305 * @}
mbed_official 205:c41fc65bcfb4 1306 */
mbed_official 205:c41fc65bcfb4 1307
mbed_official 205:c41fc65bcfb4 1308 /**
mbed_official 205:c41fc65bcfb4 1309 * @}
mbed_official 205:c41fc65bcfb4 1310 */
mbed_official 205:c41fc65bcfb4 1311
mbed_official 205:c41fc65bcfb4 1312 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/