mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Fri Aug 14 13:15:17 2015 +0100
Revision:
610:813dcc80987e
Synchronized with git revision 6d84db41c6833e0b9b024741eb0616a5f62d5599

Full URL: https://github.com/mbedmicro/mbed/commit/6d84db41c6833e0b9b024741eb0616a5f62d5599/

DISCO_F746NG - Improvements

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 610:813dcc80987e 1 /**
mbed_official 610:813dcc80987e 2 ******************************************************************************
mbed_official 610:813dcc80987e 3 * @file stm32l4xx_hal_pcd.c
mbed_official 610:813dcc80987e 4 * @author MCD Application Team
mbed_official 610:813dcc80987e 5 * @version V1.0.0
mbed_official 610:813dcc80987e 6 * @date 26-June-2015
mbed_official 610:813dcc80987e 7 * @brief PCD HAL module driver.
mbed_official 610:813dcc80987e 8 * This file provides firmware functions to manage the following
mbed_official 610:813dcc80987e 9 * functionalities of the USB Peripheral Controller:
mbed_official 610:813dcc80987e 10 * + Initialization and de-initialization functions
mbed_official 610:813dcc80987e 11 * + IO operation functions
mbed_official 610:813dcc80987e 12 * + Peripheral Control functions
mbed_official 610:813dcc80987e 13 * + Peripheral State functions
mbed_official 610:813dcc80987e 14 *
mbed_official 610:813dcc80987e 15 @verbatim
mbed_official 610:813dcc80987e 16 ==============================================================================
mbed_official 610:813dcc80987e 17 ##### How to use this driver #####
mbed_official 610:813dcc80987e 18 ==============================================================================
mbed_official 610:813dcc80987e 19 [..]
mbed_official 610:813dcc80987e 20 The PCD HAL driver can be used as follows:
mbed_official 610:813dcc80987e 21
mbed_official 610:813dcc80987e 22 (#) Declare a PCD_HandleTypeDef handle structure, for example:
mbed_official 610:813dcc80987e 23 PCD_HandleTypeDef hpcd;
mbed_official 610:813dcc80987e 24
mbed_official 610:813dcc80987e 25 (#) Fill parameters of Init structure in HCD handle
mbed_official 610:813dcc80987e 26
mbed_official 610:813dcc80987e 27 (#) Call HAL_PCD_Init() API to initialize the PCD peripheral (Core, Device core, ...)
mbed_official 610:813dcc80987e 28
mbed_official 610:813dcc80987e 29 (#) Initialize the PCD low level resources through the HAL_PCD_MspInit() API:
mbed_official 610:813dcc80987e 30 (##) Enable the PCD/USB Low Level interface clock using
mbed_official 610:813dcc80987e 31 (+++) __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
mbed_official 610:813dcc80987e 32 (##) Initialize the related GPIO clocks
mbed_official 610:813dcc80987e 33 (##) Configure PCD pin-out
mbed_official 610:813dcc80987e 34 (##) Configure PCD NVIC interrupt
mbed_official 610:813dcc80987e 35
mbed_official 610:813dcc80987e 36 (#)Associate the Upper USB device stack to the HAL PCD Driver:
mbed_official 610:813dcc80987e 37 (##) hpcd.pData = pdev;
mbed_official 610:813dcc80987e 38
mbed_official 610:813dcc80987e 39 (#)Enable PCD transmission and reception:
mbed_official 610:813dcc80987e 40 (##) HAL_PCD_Start();
mbed_official 610:813dcc80987e 41
mbed_official 610:813dcc80987e 42 @endverbatim
mbed_official 610:813dcc80987e 43 ******************************************************************************
mbed_official 610:813dcc80987e 44 * @attention
mbed_official 610:813dcc80987e 45 *
mbed_official 610:813dcc80987e 46 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
mbed_official 610:813dcc80987e 47 *
mbed_official 610:813dcc80987e 48 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 610:813dcc80987e 49 * are permitted provided that the following conditions are met:
mbed_official 610:813dcc80987e 50 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 610:813dcc80987e 51 * this list of conditions and the following disclaimer.
mbed_official 610:813dcc80987e 52 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 610:813dcc80987e 53 * this list of conditions and the following disclaimer in the documentation
mbed_official 610:813dcc80987e 54 * and/or other materials provided with the distribution.
mbed_official 610:813dcc80987e 55 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 610:813dcc80987e 56 * may be used to endorse or promote products derived from this software
mbed_official 610:813dcc80987e 57 * without specific prior written permission.
mbed_official 610:813dcc80987e 58 *
mbed_official 610:813dcc80987e 59 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 610:813dcc80987e 60 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 610:813dcc80987e 61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 610:813dcc80987e 62 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 610:813dcc80987e 63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 610:813dcc80987e 64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 610:813dcc80987e 65 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 610:813dcc80987e 66 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 610:813dcc80987e 67 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 610:813dcc80987e 68 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 610:813dcc80987e 69 *
mbed_official 610:813dcc80987e 70 ******************************************************************************
mbed_official 610:813dcc80987e 71 */
mbed_official 610:813dcc80987e 72
mbed_official 610:813dcc80987e 73 /* Includes ------------------------------------------------------------------*/
mbed_official 610:813dcc80987e 74 #include "stm32l4xx_hal.h"
mbed_official 610:813dcc80987e 75
mbed_official 610:813dcc80987e 76 #if defined(STM32L475xx) || defined(STM32L476xx) || defined(STM32L485xx) || defined(STM32L486xx)
mbed_official 610:813dcc80987e 77
mbed_official 610:813dcc80987e 78 /** @addtogroup STM32L4xx_HAL_Driver
mbed_official 610:813dcc80987e 79 * @{
mbed_official 610:813dcc80987e 80 */
mbed_official 610:813dcc80987e 81
mbed_official 610:813dcc80987e 82 /** @defgroup PCD PCD
mbed_official 610:813dcc80987e 83 * @brief PCD HAL module driver
mbed_official 610:813dcc80987e 84 * @{
mbed_official 610:813dcc80987e 85 */
mbed_official 610:813dcc80987e 86
mbed_official 610:813dcc80987e 87 #ifdef HAL_PCD_MODULE_ENABLED
mbed_official 610:813dcc80987e 88
mbed_official 610:813dcc80987e 89 /* Private types -------------------------------------------------------------*/
mbed_official 610:813dcc80987e 90 /* Private variables ---------------------------------------------------------*/
mbed_official 610:813dcc80987e 91 /* Private constants ---------------------------------------------------------*/
mbed_official 610:813dcc80987e 92 /* Private macros ------------------------------------------------------------*/
mbed_official 610:813dcc80987e 93 /** @defgroup PCD_Private_Macros PCD Private Macros
mbed_official 610:813dcc80987e 94 * @{
mbed_official 610:813dcc80987e 95 */
mbed_official 610:813dcc80987e 96 #define PCD_MIN(a, b) (((a) < (b)) ? (a) : (b))
mbed_official 610:813dcc80987e 97 #define PCD_MAX(a, b) (((a) > (b)) ? (a) : (b))
mbed_official 610:813dcc80987e 98 /**
mbed_official 610:813dcc80987e 99 * @}
mbed_official 610:813dcc80987e 100 */
mbed_official 610:813dcc80987e 101
mbed_official 610:813dcc80987e 102 /* Private functions prototypes ----------------------------------------------*/
mbed_official 610:813dcc80987e 103 /** @defgroup PCD_Private_Functions PCD Private Functions
mbed_official 610:813dcc80987e 104 * @{
mbed_official 610:813dcc80987e 105 */
mbed_official 610:813dcc80987e 106 static HAL_StatusTypeDef PCD_WriteEmptyTxFifo(PCD_HandleTypeDef *hpcd, uint32_t epnum);
mbed_official 610:813dcc80987e 107 /**
mbed_official 610:813dcc80987e 108 * @}
mbed_official 610:813dcc80987e 109 */
mbed_official 610:813dcc80987e 110
mbed_official 610:813dcc80987e 111 /* Exported functions --------------------------------------------------------*/
mbed_official 610:813dcc80987e 112 /** @defgroup PCD_Exported_Functions PCD Exported Functions
mbed_official 610:813dcc80987e 113 * @{
mbed_official 610:813dcc80987e 114 */
mbed_official 610:813dcc80987e 115
mbed_official 610:813dcc80987e 116 /** @defgroup PCD_Exported_Functions_Group1 Initialization and de-initialization functions
mbed_official 610:813dcc80987e 117 * @brief Initialization and Configuration functions
mbed_official 610:813dcc80987e 118 *
mbed_official 610:813dcc80987e 119 @verbatim
mbed_official 610:813dcc80987e 120 ===============================================================================
mbed_official 610:813dcc80987e 121 ##### Initialization and de-initialization functions #####
mbed_official 610:813dcc80987e 122 ===============================================================================
mbed_official 610:813dcc80987e 123 [..] This section provides functions allowing to:
mbed_official 610:813dcc80987e 124
mbed_official 610:813dcc80987e 125 @endverbatim
mbed_official 610:813dcc80987e 126 * @{
mbed_official 610:813dcc80987e 127 */
mbed_official 610:813dcc80987e 128
mbed_official 610:813dcc80987e 129 /**
mbed_official 610:813dcc80987e 130 * @brief Initializes the PCD according to the specified
mbed_official 610:813dcc80987e 131 * parameters in the PCD_InitTypeDef and initialize the associated handle.
mbed_official 610:813dcc80987e 132 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 133 * @retval HAL status
mbed_official 610:813dcc80987e 134 */
mbed_official 610:813dcc80987e 135 HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd)
mbed_official 610:813dcc80987e 136 {
mbed_official 610:813dcc80987e 137 uint32_t i = 0;
mbed_official 610:813dcc80987e 138
mbed_official 610:813dcc80987e 139 /* Check the PCD handle allocation */
mbed_official 610:813dcc80987e 140 if(hpcd == NULL)
mbed_official 610:813dcc80987e 141 {
mbed_official 610:813dcc80987e 142 return HAL_ERROR;
mbed_official 610:813dcc80987e 143 }
mbed_official 610:813dcc80987e 144
mbed_official 610:813dcc80987e 145 /* Check the parameters */
mbed_official 610:813dcc80987e 146 assert_param(IS_PCD_ALL_INSTANCE(hpcd->Instance));
mbed_official 610:813dcc80987e 147
mbed_official 610:813dcc80987e 148 if(hpcd->State == HAL_PCD_STATE_RESET)
mbed_official 610:813dcc80987e 149 {
mbed_official 610:813dcc80987e 150 /* Allocate lock resource and initialize it */
mbed_official 610:813dcc80987e 151 hpcd->Lock = HAL_UNLOCKED;
mbed_official 610:813dcc80987e 152
mbed_official 610:813dcc80987e 153 /* Init the low level hardware : GPIO, CLOCK, NVIC... */
mbed_official 610:813dcc80987e 154 HAL_PCD_MspInit(hpcd);
mbed_official 610:813dcc80987e 155 }
mbed_official 610:813dcc80987e 156
mbed_official 610:813dcc80987e 157 hpcd->State = HAL_PCD_STATE_BUSY;
mbed_official 610:813dcc80987e 158
mbed_official 610:813dcc80987e 159 /* Disable the Interrupts */
mbed_official 610:813dcc80987e 160 __HAL_PCD_DISABLE(hpcd);
mbed_official 610:813dcc80987e 161
mbed_official 610:813dcc80987e 162 /*Init the Core (common init.) */
mbed_official 610:813dcc80987e 163 USB_CoreInit(hpcd->Instance, hpcd->Init);
mbed_official 610:813dcc80987e 164
mbed_official 610:813dcc80987e 165 /* Force Device Mode*/
mbed_official 610:813dcc80987e 166 USB_SetCurrentMode(hpcd->Instance , USB_OTG_DEVICE_MODE);
mbed_official 610:813dcc80987e 167
mbed_official 610:813dcc80987e 168 /* Init endpoints structures */
mbed_official 610:813dcc80987e 169 for (i = 0; i < hpcd->Init.dev_endpoints ; i++)
mbed_official 610:813dcc80987e 170 {
mbed_official 610:813dcc80987e 171 /* Init ep structure */
mbed_official 610:813dcc80987e 172 hpcd->IN_ep[i].is_in = 1;
mbed_official 610:813dcc80987e 173 hpcd->IN_ep[i].num = i;
mbed_official 610:813dcc80987e 174 hpcd->IN_ep[i].tx_fifo_num = i;
mbed_official 610:813dcc80987e 175 /* Control until ep is activated */
mbed_official 610:813dcc80987e 176 hpcd->IN_ep[i].type = EP_TYPE_CTRL;
mbed_official 610:813dcc80987e 177 hpcd->IN_ep[i].maxpacket = 0;
mbed_official 610:813dcc80987e 178 hpcd->IN_ep[i].xfer_buff = 0;
mbed_official 610:813dcc80987e 179 hpcd->IN_ep[i].xfer_len = 0;
mbed_official 610:813dcc80987e 180 }
mbed_official 610:813dcc80987e 181
mbed_official 610:813dcc80987e 182 for (i = 0; i < hpcd->Init.dev_endpoints ; i++)
mbed_official 610:813dcc80987e 183 {
mbed_official 610:813dcc80987e 184 hpcd->OUT_ep[i].is_in = 0;
mbed_official 610:813dcc80987e 185 hpcd->OUT_ep[i].num = i;
mbed_official 610:813dcc80987e 186 hpcd->IN_ep[i].tx_fifo_num = i;
mbed_official 610:813dcc80987e 187 /* Control until ep is activated */
mbed_official 610:813dcc80987e 188 hpcd->OUT_ep[i].type = EP_TYPE_CTRL;
mbed_official 610:813dcc80987e 189 hpcd->OUT_ep[i].maxpacket = 0;
mbed_official 610:813dcc80987e 190 hpcd->OUT_ep[i].xfer_buff = 0;
mbed_official 610:813dcc80987e 191 hpcd->OUT_ep[i].xfer_len = 0;
mbed_official 610:813dcc80987e 192
mbed_official 610:813dcc80987e 193 hpcd->Instance->DIEPTXF[i] = 0;
mbed_official 610:813dcc80987e 194 }
mbed_official 610:813dcc80987e 195
mbed_official 610:813dcc80987e 196 /* Init Device */
mbed_official 610:813dcc80987e 197 USB_DevInit(hpcd->Instance, hpcd->Init);
mbed_official 610:813dcc80987e 198
mbed_official 610:813dcc80987e 199 hpcd->State= HAL_PCD_STATE_READY;
mbed_official 610:813dcc80987e 200
mbed_official 610:813dcc80987e 201 /* Activate LPM */
mbed_official 610:813dcc80987e 202 if (hpcd->Init.lpm_enable ==1)
mbed_official 610:813dcc80987e 203 {
mbed_official 610:813dcc80987e 204 HAL_PCDEx_ActivateLPM(hpcd);
mbed_official 610:813dcc80987e 205 }
mbed_official 610:813dcc80987e 206 /* Activate Battery charging */
mbed_official 610:813dcc80987e 207 if (hpcd->Init.battery_charging_enable ==1)
mbed_official 610:813dcc80987e 208 {
mbed_official 610:813dcc80987e 209 HAL_PCDEx_ActivateBCD(hpcd);
mbed_official 610:813dcc80987e 210 }
mbed_official 610:813dcc80987e 211 USB_DevDisconnect (hpcd->Instance);
mbed_official 610:813dcc80987e 212 return HAL_OK;
mbed_official 610:813dcc80987e 213 }
mbed_official 610:813dcc80987e 214
mbed_official 610:813dcc80987e 215 /**
mbed_official 610:813dcc80987e 216 * @brief DeInitializes the PCD peripheral.
mbed_official 610:813dcc80987e 217 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 218 * @retval HAL status
mbed_official 610:813dcc80987e 219 */
mbed_official 610:813dcc80987e 220 HAL_StatusTypeDef HAL_PCD_DeInit(PCD_HandleTypeDef *hpcd)
mbed_official 610:813dcc80987e 221 {
mbed_official 610:813dcc80987e 222 /* Check the PCD handle allocation */
mbed_official 610:813dcc80987e 223 if(hpcd == NULL)
mbed_official 610:813dcc80987e 224 {
mbed_official 610:813dcc80987e 225 return HAL_ERROR;
mbed_official 610:813dcc80987e 226 }
mbed_official 610:813dcc80987e 227
mbed_official 610:813dcc80987e 228 hpcd->State = HAL_PCD_STATE_BUSY;
mbed_official 610:813dcc80987e 229
mbed_official 610:813dcc80987e 230 /* Stop Device */
mbed_official 610:813dcc80987e 231 HAL_PCD_Stop(hpcd);
mbed_official 610:813dcc80987e 232
mbed_official 610:813dcc80987e 233 /* DeInit the low level hardware */
mbed_official 610:813dcc80987e 234 HAL_PCD_MspDeInit(hpcd);
mbed_official 610:813dcc80987e 235
mbed_official 610:813dcc80987e 236 hpcd->State = HAL_PCD_STATE_RESET;
mbed_official 610:813dcc80987e 237
mbed_official 610:813dcc80987e 238 return HAL_OK;
mbed_official 610:813dcc80987e 239 }
mbed_official 610:813dcc80987e 240
mbed_official 610:813dcc80987e 241 /**
mbed_official 610:813dcc80987e 242 * @brief Initializes the PCD MSP.
mbed_official 610:813dcc80987e 243 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 244 * @retval None
mbed_official 610:813dcc80987e 245 */
mbed_official 610:813dcc80987e 246 __weak void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
mbed_official 610:813dcc80987e 247 {
mbed_official 610:813dcc80987e 248 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 610:813dcc80987e 249 the HAL_PCD_MspInit could be implemented in the user file
mbed_official 610:813dcc80987e 250 */
mbed_official 610:813dcc80987e 251 }
mbed_official 610:813dcc80987e 252
mbed_official 610:813dcc80987e 253 /**
mbed_official 610:813dcc80987e 254 * @brief DeInitializes PCD MSP.
mbed_official 610:813dcc80987e 255 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 256 * @retval None
mbed_official 610:813dcc80987e 257 */
mbed_official 610:813dcc80987e 258 __weak void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd)
mbed_official 610:813dcc80987e 259 {
mbed_official 610:813dcc80987e 260 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 610:813dcc80987e 261 the HAL_PCD_MspDeInit could be implemented in the user file
mbed_official 610:813dcc80987e 262 */
mbed_official 610:813dcc80987e 263 }
mbed_official 610:813dcc80987e 264
mbed_official 610:813dcc80987e 265 /**
mbed_official 610:813dcc80987e 266 * @}
mbed_official 610:813dcc80987e 267 */
mbed_official 610:813dcc80987e 268
mbed_official 610:813dcc80987e 269 /** @defgroup PCD_Exported_Functions_Group2 Input and Output operation functions
mbed_official 610:813dcc80987e 270 * @brief Data transfers functions
mbed_official 610:813dcc80987e 271 *
mbed_official 610:813dcc80987e 272 @verbatim
mbed_official 610:813dcc80987e 273 ===============================================================================
mbed_official 610:813dcc80987e 274 ##### IO operation functions #####
mbed_official 610:813dcc80987e 275 ===============================================================================
mbed_official 610:813dcc80987e 276 [..]
mbed_official 610:813dcc80987e 277 This subsection provides a set of functions allowing to manage the PCD data
mbed_official 610:813dcc80987e 278 transfers.
mbed_official 610:813dcc80987e 279
mbed_official 610:813dcc80987e 280 @endverbatim
mbed_official 610:813dcc80987e 281 * @{
mbed_official 610:813dcc80987e 282 */
mbed_official 610:813dcc80987e 283
mbed_official 610:813dcc80987e 284 /**
mbed_official 610:813dcc80987e 285 * @brief Start The USB OTG Device.
mbed_official 610:813dcc80987e 286 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 287 * @retval HAL status
mbed_official 610:813dcc80987e 288 */
mbed_official 610:813dcc80987e 289 HAL_StatusTypeDef HAL_PCD_Start(PCD_HandleTypeDef *hpcd)
mbed_official 610:813dcc80987e 290 {
mbed_official 610:813dcc80987e 291 __HAL_LOCK(hpcd);
mbed_official 610:813dcc80987e 292 USB_DevConnect (hpcd->Instance);
mbed_official 610:813dcc80987e 293 __HAL_PCD_ENABLE(hpcd);
mbed_official 610:813dcc80987e 294 __HAL_UNLOCK(hpcd);
mbed_official 610:813dcc80987e 295 return HAL_OK;
mbed_official 610:813dcc80987e 296 }
mbed_official 610:813dcc80987e 297
mbed_official 610:813dcc80987e 298 /**
mbed_official 610:813dcc80987e 299 * @brief Stop The USB OTG Device.
mbed_official 610:813dcc80987e 300 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 301 * @retval HAL status
mbed_official 610:813dcc80987e 302 */
mbed_official 610:813dcc80987e 303 HAL_StatusTypeDef HAL_PCD_Stop(PCD_HandleTypeDef *hpcd)
mbed_official 610:813dcc80987e 304 {
mbed_official 610:813dcc80987e 305 __HAL_LOCK(hpcd);
mbed_official 610:813dcc80987e 306 __HAL_PCD_DISABLE(hpcd);
mbed_official 610:813dcc80987e 307 USB_StopDevice(hpcd->Instance);
mbed_official 610:813dcc80987e 308 USB_DevDisconnect (hpcd->Instance);
mbed_official 610:813dcc80987e 309 __HAL_UNLOCK(hpcd);
mbed_official 610:813dcc80987e 310 return HAL_OK;
mbed_official 610:813dcc80987e 311 }
mbed_official 610:813dcc80987e 312
mbed_official 610:813dcc80987e 313 /**
mbed_official 610:813dcc80987e 314 * @brief Handles PCD interrupt request.
mbed_official 610:813dcc80987e 315 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 316 * @retval HAL status
mbed_official 610:813dcc80987e 317 */
mbed_official 610:813dcc80987e 318 void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd)
mbed_official 610:813dcc80987e 319 {
mbed_official 610:813dcc80987e 320 USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
mbed_official 610:813dcc80987e 321 uint32_t i = 0, ep_intr = 0, epint = 0, epnum = 0;
mbed_official 610:813dcc80987e 322 uint32_t fifoemptymsk = 0, temp = 0;
mbed_official 610:813dcc80987e 323 USB_OTG_EPTypeDef *ep;
mbed_official 610:813dcc80987e 324
mbed_official 610:813dcc80987e 325 /* ensure that we are in device mode */
mbed_official 610:813dcc80987e 326 if (USB_GetMode(hpcd->Instance) == USB_OTG_MODE_DEVICE)
mbed_official 610:813dcc80987e 327 {
mbed_official 610:813dcc80987e 328 /* avoid spurious interrupt */
mbed_official 610:813dcc80987e 329 if(__HAL_PCD_IS_INVALID_INTERRUPT(hpcd))
mbed_official 610:813dcc80987e 330 {
mbed_official 610:813dcc80987e 331 return;
mbed_official 610:813dcc80987e 332 }
mbed_official 610:813dcc80987e 333
mbed_official 610:813dcc80987e 334 if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_MMIS))
mbed_official 610:813dcc80987e 335 {
mbed_official 610:813dcc80987e 336 /* incorrect mode, acknowledge the interrupt */
mbed_official 610:813dcc80987e 337 __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_MMIS);
mbed_official 610:813dcc80987e 338 }
mbed_official 610:813dcc80987e 339
mbed_official 610:813dcc80987e 340 if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_OEPINT))
mbed_official 610:813dcc80987e 341 {
mbed_official 610:813dcc80987e 342 epnum = 0;
mbed_official 610:813dcc80987e 343
mbed_official 610:813dcc80987e 344 /* Read in the device interrupt bits */
mbed_official 610:813dcc80987e 345 ep_intr = USB_ReadDevAllOutEpInterrupt(hpcd->Instance);
mbed_official 610:813dcc80987e 346
mbed_official 610:813dcc80987e 347 while ( ep_intr )
mbed_official 610:813dcc80987e 348 {
mbed_official 610:813dcc80987e 349 if (ep_intr & 0x1)
mbed_official 610:813dcc80987e 350 {
mbed_official 610:813dcc80987e 351 epint = USB_ReadDevOutEPInterrupt(hpcd->Instance, epnum);
mbed_official 610:813dcc80987e 352
mbed_official 610:813dcc80987e 353 if(( epint & USB_OTG_DOEPINT_XFRC) == USB_OTG_DOEPINT_XFRC)
mbed_official 610:813dcc80987e 354 {
mbed_official 610:813dcc80987e 355 CLEAR_OUT_EP_INTR(epnum, USB_OTG_DOEPINT_XFRC);
mbed_official 610:813dcc80987e 356
mbed_official 610:813dcc80987e 357 if ((( (USBx_OUTEP(0)->DOEPINT & 0x8000) == 0)) )
mbed_official 610:813dcc80987e 358 {
mbed_official 610:813dcc80987e 359
mbed_official 610:813dcc80987e 360 if(hpcd->Init.dma_enable == 1)
mbed_official 610:813dcc80987e 361 {
mbed_official 610:813dcc80987e 362 hpcd->OUT_ep[epnum].xfer_count = hpcd->OUT_ep[epnum].maxpacket- (USBx_OUTEP(epnum)->DOEPTSIZ & USB_OTG_DOEPTSIZ_XFRSIZ);
mbed_official 610:813dcc80987e 363 hpcd->OUT_ep[epnum].xfer_buff += hpcd->OUT_ep[epnum].maxpacket;
mbed_official 610:813dcc80987e 364 }
mbed_official 610:813dcc80987e 365
mbed_official 610:813dcc80987e 366 HAL_PCD_DataOutStageCallback(hpcd, epnum);
mbed_official 610:813dcc80987e 367
mbed_official 610:813dcc80987e 368 if(hpcd->Init.dma_enable == 1)
mbed_official 610:813dcc80987e 369 {
mbed_official 610:813dcc80987e 370 if((epnum == 0) && (hpcd->OUT_ep[epnum].xfer_len == 0))
mbed_official 610:813dcc80987e 371 {
mbed_official 610:813dcc80987e 372 /* this is ZLP, so prepare EP0 for next setup */
mbed_official 610:813dcc80987e 373 USB_EP0_OutStart(hpcd->Instance, 1, (uint8_t *)hpcd->Setup);
mbed_official 610:813dcc80987e 374 }
mbed_official 610:813dcc80987e 375 }
mbed_official 610:813dcc80987e 376 }
mbed_official 610:813dcc80987e 377 /* Clear the SetPktRcvd flag*/
mbed_official 610:813dcc80987e 378 USBx_OUTEP(0)->DOEPINT |= 0x8020;
mbed_official 610:813dcc80987e 379 }
mbed_official 610:813dcc80987e 380
mbed_official 610:813dcc80987e 381 if(( epint & USB_OTG_DOEPINT_STUP) == USB_OTG_DOEPINT_STUP)
mbed_official 610:813dcc80987e 382 {
mbed_official 610:813dcc80987e 383 /* Inform the upper layer that a setup packet is available */
mbed_official 610:813dcc80987e 384 HAL_PCD_SetupStageCallback(hpcd);
mbed_official 610:813dcc80987e 385 CLEAR_OUT_EP_INTR(epnum, USB_OTG_DOEPINT_STUP);
mbed_official 610:813dcc80987e 386 }
mbed_official 610:813dcc80987e 387
mbed_official 610:813dcc80987e 388 if(( epint & USB_OTG_DOEPINT_OTEPDIS) == USB_OTG_DOEPINT_OTEPDIS)
mbed_official 610:813dcc80987e 389 {
mbed_official 610:813dcc80987e 390 CLEAR_OUT_EP_INTR(epnum, USB_OTG_DOEPINT_OTEPDIS);
mbed_official 610:813dcc80987e 391 }
mbed_official 610:813dcc80987e 392 }
mbed_official 610:813dcc80987e 393 epnum++;
mbed_official 610:813dcc80987e 394 ep_intr >>= 1;
mbed_official 610:813dcc80987e 395 }
mbed_official 610:813dcc80987e 396 }
mbed_official 610:813dcc80987e 397
mbed_official 610:813dcc80987e 398 if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_IEPINT))
mbed_official 610:813dcc80987e 399 {
mbed_official 610:813dcc80987e 400 /* Read in the device interrupt bits */
mbed_official 610:813dcc80987e 401 ep_intr = USB_ReadDevAllInEpInterrupt(hpcd->Instance);
mbed_official 610:813dcc80987e 402
mbed_official 610:813dcc80987e 403 epnum = 0;
mbed_official 610:813dcc80987e 404
mbed_official 610:813dcc80987e 405 while ( ep_intr )
mbed_official 610:813dcc80987e 406 {
mbed_official 610:813dcc80987e 407 if (ep_intr & 0x1) /* In ITR */
mbed_official 610:813dcc80987e 408 {
mbed_official 610:813dcc80987e 409 epint = USB_ReadDevInEPInterrupt(hpcd->Instance, epnum);
mbed_official 610:813dcc80987e 410
mbed_official 610:813dcc80987e 411 if(( epint & USB_OTG_DIEPINT_XFRC) == USB_OTG_DIEPINT_XFRC)
mbed_official 610:813dcc80987e 412 {
mbed_official 610:813dcc80987e 413 fifoemptymsk = 0x1 << epnum;
mbed_official 610:813dcc80987e 414 USBx_DEVICE->DIEPEMPMSK &= ~fifoemptymsk;
mbed_official 610:813dcc80987e 415
mbed_official 610:813dcc80987e 416 CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_XFRC);
mbed_official 610:813dcc80987e 417
mbed_official 610:813dcc80987e 418 if (hpcd->Init.dma_enable == 1)
mbed_official 610:813dcc80987e 419 {
mbed_official 610:813dcc80987e 420 hpcd->IN_ep[epnum].xfer_buff += hpcd->IN_ep[epnum].maxpacket;
mbed_official 610:813dcc80987e 421 }
mbed_official 610:813dcc80987e 422
mbed_official 610:813dcc80987e 423 HAL_PCD_DataInStageCallback(hpcd, epnum);
mbed_official 610:813dcc80987e 424
mbed_official 610:813dcc80987e 425 if (hpcd->Init.dma_enable == 1)
mbed_official 610:813dcc80987e 426 {
mbed_official 610:813dcc80987e 427 /* this is ZLP, so prepare EP0 for next setup */
mbed_official 610:813dcc80987e 428 if((epnum == 0) && (hpcd->IN_ep[epnum].xfer_len == 0))
mbed_official 610:813dcc80987e 429 {
mbed_official 610:813dcc80987e 430 /* prepare to rx more setup packets */
mbed_official 610:813dcc80987e 431 USB_EP0_OutStart(hpcd->Instance, 1, (uint8_t *)hpcd->Setup);
mbed_official 610:813dcc80987e 432 }
mbed_official 610:813dcc80987e 433 }
mbed_official 610:813dcc80987e 434 }
mbed_official 610:813dcc80987e 435 if(( epint & USB_OTG_DIEPINT_TOC) == USB_OTG_DIEPINT_TOC)
mbed_official 610:813dcc80987e 436 {
mbed_official 610:813dcc80987e 437 CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_TOC);
mbed_official 610:813dcc80987e 438 }
mbed_official 610:813dcc80987e 439 if(( epint & USB_OTG_DIEPINT_ITTXFE) == USB_OTG_DIEPINT_ITTXFE)
mbed_official 610:813dcc80987e 440 {
mbed_official 610:813dcc80987e 441 CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_ITTXFE);
mbed_official 610:813dcc80987e 442 }
mbed_official 610:813dcc80987e 443 if(( epint & USB_OTG_DIEPINT_INEPNE) == USB_OTG_DIEPINT_INEPNE)
mbed_official 610:813dcc80987e 444 {
mbed_official 610:813dcc80987e 445 CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_INEPNE);
mbed_official 610:813dcc80987e 446 }
mbed_official 610:813dcc80987e 447 if(( epint & USB_OTG_DIEPINT_EPDISD) == USB_OTG_DIEPINT_EPDISD)
mbed_official 610:813dcc80987e 448 {
mbed_official 610:813dcc80987e 449 CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_EPDISD);
mbed_official 610:813dcc80987e 450 }
mbed_official 610:813dcc80987e 451 if(( epint & USB_OTG_DIEPINT_TXFE) == USB_OTG_DIEPINT_TXFE)
mbed_official 610:813dcc80987e 452 {
mbed_official 610:813dcc80987e 453 PCD_WriteEmptyTxFifo(hpcd , epnum);
mbed_official 610:813dcc80987e 454 }
mbed_official 610:813dcc80987e 455 }
mbed_official 610:813dcc80987e 456 epnum++;
mbed_official 610:813dcc80987e 457 ep_intr >>= 1;
mbed_official 610:813dcc80987e 458 }
mbed_official 610:813dcc80987e 459 }
mbed_official 610:813dcc80987e 460
mbed_official 610:813dcc80987e 461 /* Handle Resume Interrupt */
mbed_official 610:813dcc80987e 462 if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_WKUINT))
mbed_official 610:813dcc80987e 463 {
mbed_official 610:813dcc80987e 464 /* Clear the Remote Wake-up Signaling */
mbed_official 610:813dcc80987e 465 USBx_DEVICE->DCTL &= ~USB_OTG_DCTL_RWUSIG;
mbed_official 610:813dcc80987e 466
mbed_official 610:813dcc80987e 467 if(hpcd->LPM_State == LPM_L1)
mbed_official 610:813dcc80987e 468 {
mbed_official 610:813dcc80987e 469 hpcd->LPM_State = LPM_L0;
mbed_official 610:813dcc80987e 470 HAL_PCDEx_LPM_Callback(hpcd, PCD_LPM_L0_ACTIVE);
mbed_official 610:813dcc80987e 471 }
mbed_official 610:813dcc80987e 472 else
mbed_official 610:813dcc80987e 473 {
mbed_official 610:813dcc80987e 474 HAL_PCD_ResumeCallback(hpcd);
mbed_official 610:813dcc80987e 475 }
mbed_official 610:813dcc80987e 476
mbed_official 610:813dcc80987e 477 __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_WKUINT);
mbed_official 610:813dcc80987e 478 }
mbed_official 610:813dcc80987e 479
mbed_official 610:813dcc80987e 480 /* Handle Suspend Interrupt */
mbed_official 610:813dcc80987e 481 if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_USBSUSP))
mbed_official 610:813dcc80987e 482 {
mbed_official 610:813dcc80987e 483 if((USBx_DEVICE->DSTS & USB_OTG_DSTS_SUSPSTS) == USB_OTG_DSTS_SUSPSTS)
mbed_official 610:813dcc80987e 484 {
mbed_official 610:813dcc80987e 485
mbed_official 610:813dcc80987e 486 HAL_PCD_SuspendCallback(hpcd);
mbed_official 610:813dcc80987e 487 }
mbed_official 610:813dcc80987e 488 __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_USBSUSP);
mbed_official 610:813dcc80987e 489 }
mbed_official 610:813dcc80987e 490
mbed_official 610:813dcc80987e 491 /* Handle LPM Interrupt */
mbed_official 610:813dcc80987e 492 if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_LPMINT))
mbed_official 610:813dcc80987e 493 {
mbed_official 610:813dcc80987e 494 __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_LPMINT);
mbed_official 610:813dcc80987e 495 if( hpcd->LPM_State == LPM_L0)
mbed_official 610:813dcc80987e 496 {
mbed_official 610:813dcc80987e 497 hpcd->LPM_State = LPM_L1;
mbed_official 610:813dcc80987e 498 hpcd->BESL = (hpcd->Instance->GLPMCFG & USB_OTG_GLPMCFG_BESL) >>2 ;
mbed_official 610:813dcc80987e 499 HAL_PCDEx_LPM_Callback(hpcd, PCD_LPM_L1_ACTIVE);
mbed_official 610:813dcc80987e 500 }
mbed_official 610:813dcc80987e 501 else
mbed_official 610:813dcc80987e 502 {
mbed_official 610:813dcc80987e 503 HAL_PCD_SuspendCallback(hpcd);
mbed_official 610:813dcc80987e 504 }
mbed_official 610:813dcc80987e 505 }
mbed_official 610:813dcc80987e 506
mbed_official 610:813dcc80987e 507 /* Handle Reset Interrupt */
mbed_official 610:813dcc80987e 508 if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_USBRST))
mbed_official 610:813dcc80987e 509 {
mbed_official 610:813dcc80987e 510 USBx_DEVICE->DCTL &= ~USB_OTG_DCTL_RWUSIG;
mbed_official 610:813dcc80987e 511 USB_FlushTxFifo(hpcd->Instance , 0 );
mbed_official 610:813dcc80987e 512
mbed_official 610:813dcc80987e 513 for (i = 0; i < hpcd->Init.dev_endpoints ; i++)
mbed_official 610:813dcc80987e 514 {
mbed_official 610:813dcc80987e 515 USBx_INEP(i)->DIEPINT = 0xFF;
mbed_official 610:813dcc80987e 516 USBx_OUTEP(i)->DOEPINT = 0xFF;
mbed_official 610:813dcc80987e 517 }
mbed_official 610:813dcc80987e 518 USBx_DEVICE->DAINT = 0xFFFFFFFF;
mbed_official 610:813dcc80987e 519 USBx_DEVICE->DAINTMSK |= 0x10001;
mbed_official 610:813dcc80987e 520
mbed_official 610:813dcc80987e 521 if(hpcd->Init.use_dedicated_ep1)
mbed_official 610:813dcc80987e 522 {
mbed_official 610:813dcc80987e 523 USBx_DEVICE->DOUTEP1MSK |= (USB_OTG_DOEPMSK_STUPM | USB_OTG_DOEPMSK_XFRCM | USB_OTG_DOEPMSK_EPDM);
mbed_official 610:813dcc80987e 524 USBx_DEVICE->DINEP1MSK |= (USB_OTG_DIEPMSK_TOM | USB_OTG_DIEPMSK_XFRCM | USB_OTG_DIEPMSK_EPDM);
mbed_official 610:813dcc80987e 525 }
mbed_official 610:813dcc80987e 526 else
mbed_official 610:813dcc80987e 527 {
mbed_official 610:813dcc80987e 528 USBx_DEVICE->DOEPMSK |= (USB_OTG_DOEPMSK_STUPM | USB_OTG_DOEPMSK_XFRCM | USB_OTG_DOEPMSK_EPDM);
mbed_official 610:813dcc80987e 529 USBx_DEVICE->DIEPMSK |= (USB_OTG_DIEPMSK_TOM | USB_OTG_DIEPMSK_XFRCM | USB_OTG_DIEPMSK_EPDM);
mbed_official 610:813dcc80987e 530 }
mbed_official 610:813dcc80987e 531
mbed_official 610:813dcc80987e 532 /* Set Default Address to 0 */
mbed_official 610:813dcc80987e 533 USBx_DEVICE->DCFG &= ~USB_OTG_DCFG_DAD;
mbed_official 610:813dcc80987e 534
mbed_official 610:813dcc80987e 535 /* setup EP0 to receive SETUP packets */
mbed_official 610:813dcc80987e 536 USB_EP0_OutStart(hpcd->Instance, hpcd->Init.dma_enable, (uint8_t *)hpcd->Setup);
mbed_official 610:813dcc80987e 537
mbed_official 610:813dcc80987e 538 __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_USBRST);
mbed_official 610:813dcc80987e 539 }
mbed_official 610:813dcc80987e 540
mbed_official 610:813dcc80987e 541 /* Handle Enumeration done Interrupt */
mbed_official 610:813dcc80987e 542 if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_ENUMDNE))
mbed_official 610:813dcc80987e 543 {
mbed_official 610:813dcc80987e 544 USB_ActivateSetup(hpcd->Instance);
mbed_official 610:813dcc80987e 545 hpcd->Instance->GUSBCFG &= ~USB_OTG_GUSBCFG_TRDT;
mbed_official 610:813dcc80987e 546
mbed_official 610:813dcc80987e 547 hpcd->Init.speed = USB_OTG_SPEED_FULL;
mbed_official 610:813dcc80987e 548 hpcd->Init.ep0_mps = USB_OTG_FS_MAX_PACKET_SIZE ;
mbed_official 610:813dcc80987e 549 hpcd->Instance->GUSBCFG |= (uint32_t)((USBD_FS_TRDT_VALUE << 10) & USB_OTG_GUSBCFG_TRDT);
mbed_official 610:813dcc80987e 550
mbed_official 610:813dcc80987e 551 HAL_PCD_ResetCallback(hpcd);
mbed_official 610:813dcc80987e 552
mbed_official 610:813dcc80987e 553 __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_ENUMDNE);
mbed_official 610:813dcc80987e 554 }
mbed_official 610:813dcc80987e 555
mbed_official 610:813dcc80987e 556 /* Handle RxQLevel Interrupt */
mbed_official 610:813dcc80987e 557 if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_RXFLVL))
mbed_official 610:813dcc80987e 558 {
mbed_official 610:813dcc80987e 559 USB_MASK_INTERRUPT(hpcd->Instance, USB_OTG_GINTSTS_RXFLVL);
mbed_official 610:813dcc80987e 560
mbed_official 610:813dcc80987e 561 temp = USBx->GRXSTSP;
mbed_official 610:813dcc80987e 562
mbed_official 610:813dcc80987e 563 ep = &hpcd->OUT_ep[temp & USB_OTG_GRXSTSP_EPNUM];
mbed_official 610:813dcc80987e 564
mbed_official 610:813dcc80987e 565 if(((temp & USB_OTG_GRXSTSP_PKTSTS) >> 17) == STS_DATA_UPDT)
mbed_official 610:813dcc80987e 566 {
mbed_official 610:813dcc80987e 567 if((temp & USB_OTG_GRXSTSP_BCNT) != 0)
mbed_official 610:813dcc80987e 568 {
mbed_official 610:813dcc80987e 569 USB_ReadPacket(USBx, ep->xfer_buff, (temp & USB_OTG_GRXSTSP_BCNT) >> 4);
mbed_official 610:813dcc80987e 570 ep->xfer_buff += (temp & USB_OTG_GRXSTSP_BCNT) >> 4;
mbed_official 610:813dcc80987e 571 ep->xfer_count += (temp & USB_OTG_GRXSTSP_BCNT) >> 4;
mbed_official 610:813dcc80987e 572 }
mbed_official 610:813dcc80987e 573 }
mbed_official 610:813dcc80987e 574 else if (((temp & USB_OTG_GRXSTSP_PKTSTS) >> 17) == STS_SETUP_UPDT)
mbed_official 610:813dcc80987e 575 {
mbed_official 610:813dcc80987e 576 USB_ReadPacket(USBx, (uint8_t *)hpcd->Setup, 8);
mbed_official 610:813dcc80987e 577 ep->xfer_count += (temp & USB_OTG_GRXSTSP_BCNT) >> 4;
mbed_official 610:813dcc80987e 578 }
mbed_official 610:813dcc80987e 579 USB_UNMASK_INTERRUPT(hpcd->Instance, USB_OTG_GINTSTS_RXFLVL);
mbed_official 610:813dcc80987e 580 }
mbed_official 610:813dcc80987e 581
mbed_official 610:813dcc80987e 582 /* Handle SOF Interrupt */
mbed_official 610:813dcc80987e 583 if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_SOF))
mbed_official 610:813dcc80987e 584 {
mbed_official 610:813dcc80987e 585 HAL_PCD_SOFCallback(hpcd);
mbed_official 610:813dcc80987e 586 __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_SOF);
mbed_official 610:813dcc80987e 587 }
mbed_official 610:813dcc80987e 588
mbed_official 610:813dcc80987e 589 /* Handle Incomplete ISO IN Interrupt */
mbed_official 610:813dcc80987e 590 if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_IISOIXFR))
mbed_official 610:813dcc80987e 591 {
mbed_official 610:813dcc80987e 592 HAL_PCD_ISOINIncompleteCallback(hpcd, epnum);
mbed_official 610:813dcc80987e 593 __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_IISOIXFR);
mbed_official 610:813dcc80987e 594 }
mbed_official 610:813dcc80987e 595
mbed_official 610:813dcc80987e 596 /* Handle Incomplete ISO OUT Interrupt */
mbed_official 610:813dcc80987e 597 if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_PXFR_INCOMPISOOUT))
mbed_official 610:813dcc80987e 598 {
mbed_official 610:813dcc80987e 599 HAL_PCD_ISOOUTIncompleteCallback(hpcd, epnum);
mbed_official 610:813dcc80987e 600 __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_PXFR_INCOMPISOOUT);
mbed_official 610:813dcc80987e 601 }
mbed_official 610:813dcc80987e 602
mbed_official 610:813dcc80987e 603 /* Handle Connection event Interrupt */
mbed_official 610:813dcc80987e 604 if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_SRQINT))
mbed_official 610:813dcc80987e 605 {
mbed_official 610:813dcc80987e 606 HAL_PCD_ConnectCallback(hpcd);
mbed_official 610:813dcc80987e 607 __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_SRQINT);
mbed_official 610:813dcc80987e 608 }
mbed_official 610:813dcc80987e 609
mbed_official 610:813dcc80987e 610 /* Handle Disconnection event Interrupt */
mbed_official 610:813dcc80987e 611 if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_OTGINT))
mbed_official 610:813dcc80987e 612 {
mbed_official 610:813dcc80987e 613 temp = hpcd->Instance->GOTGINT;
mbed_official 610:813dcc80987e 614
mbed_official 610:813dcc80987e 615 if((temp & USB_OTG_GOTGINT_SEDET) == USB_OTG_GOTGINT_SEDET)
mbed_official 610:813dcc80987e 616 {
mbed_official 610:813dcc80987e 617 HAL_PCD_DisconnectCallback(hpcd);
mbed_official 610:813dcc80987e 618 }
mbed_official 610:813dcc80987e 619 hpcd->Instance->GOTGINT |= temp;
mbed_official 610:813dcc80987e 620 }
mbed_official 610:813dcc80987e 621 }
mbed_official 610:813dcc80987e 622 }
mbed_official 610:813dcc80987e 623
mbed_official 610:813dcc80987e 624 /**
mbed_official 610:813dcc80987e 625 * @brief Data OUT stage callback.
mbed_official 610:813dcc80987e 626 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 627 * @param epnum: endpoint number
mbed_official 610:813dcc80987e 628 * @retval None
mbed_official 610:813dcc80987e 629 */
mbed_official 610:813dcc80987e 630 __weak void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
mbed_official 610:813dcc80987e 631 {
mbed_official 610:813dcc80987e 632 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 610:813dcc80987e 633 the HAL_PCD_DataOutStageCallback could be implemented in the user file
mbed_official 610:813dcc80987e 634 */
mbed_official 610:813dcc80987e 635 }
mbed_official 610:813dcc80987e 636
mbed_official 610:813dcc80987e 637 /**
mbed_official 610:813dcc80987e 638 * @brief Data IN stage callback.
mbed_official 610:813dcc80987e 639 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 640 * @param epnum: endpoint number
mbed_official 610:813dcc80987e 641 * @retval None
mbed_official 610:813dcc80987e 642 */
mbed_official 610:813dcc80987e 643 __weak void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
mbed_official 610:813dcc80987e 644 {
mbed_official 610:813dcc80987e 645 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 610:813dcc80987e 646 the HAL_PCD_DataInStageCallback could be implemented in the user file
mbed_official 610:813dcc80987e 647 */
mbed_official 610:813dcc80987e 648 }
mbed_official 610:813dcc80987e 649 /**
mbed_official 610:813dcc80987e 650 * @brief Setup stage callback.
mbed_official 610:813dcc80987e 651 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 652 * @retval None
mbed_official 610:813dcc80987e 653 */
mbed_official 610:813dcc80987e 654 __weak void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd)
mbed_official 610:813dcc80987e 655 {
mbed_official 610:813dcc80987e 656 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 610:813dcc80987e 657 the HAL_PCD_SetupStageCallback could be implemented in the user file
mbed_official 610:813dcc80987e 658 */
mbed_official 610:813dcc80987e 659 }
mbed_official 610:813dcc80987e 660
mbed_official 610:813dcc80987e 661 /**
mbed_official 610:813dcc80987e 662 * @brief USB Start Of Frame callback.
mbed_official 610:813dcc80987e 663 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 664 * @retval None
mbed_official 610:813dcc80987e 665 */
mbed_official 610:813dcc80987e 666 __weak void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd)
mbed_official 610:813dcc80987e 667 {
mbed_official 610:813dcc80987e 668 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 610:813dcc80987e 669 the HAL_PCD_SOFCallback could be implemented in the user file
mbed_official 610:813dcc80987e 670 */
mbed_official 610:813dcc80987e 671 }
mbed_official 610:813dcc80987e 672
mbed_official 610:813dcc80987e 673 /**
mbed_official 610:813dcc80987e 674 * @brief USB Reset callback.
mbed_official 610:813dcc80987e 675 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 676 * @retval None
mbed_official 610:813dcc80987e 677 */
mbed_official 610:813dcc80987e 678 __weak void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd)
mbed_official 610:813dcc80987e 679 {
mbed_official 610:813dcc80987e 680 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 610:813dcc80987e 681 the HAL_PCD_ResetCallback could be implemented in the user file
mbed_official 610:813dcc80987e 682 */
mbed_official 610:813dcc80987e 683 }
mbed_official 610:813dcc80987e 684
mbed_official 610:813dcc80987e 685 /**
mbed_official 610:813dcc80987e 686 * @brief Suspend event callback.
mbed_official 610:813dcc80987e 687 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 688 * @retval None
mbed_official 610:813dcc80987e 689 */
mbed_official 610:813dcc80987e 690 __weak void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd)
mbed_official 610:813dcc80987e 691 {
mbed_official 610:813dcc80987e 692 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 610:813dcc80987e 693 the HAL_PCD_SuspendCallback could be implemented in the user file
mbed_official 610:813dcc80987e 694 */
mbed_official 610:813dcc80987e 695 }
mbed_official 610:813dcc80987e 696
mbed_official 610:813dcc80987e 697 /**
mbed_official 610:813dcc80987e 698 * @brief Resume event callback.
mbed_official 610:813dcc80987e 699 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 700 * @retval None
mbed_official 610:813dcc80987e 701 */
mbed_official 610:813dcc80987e 702 __weak void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd)
mbed_official 610:813dcc80987e 703 {
mbed_official 610:813dcc80987e 704 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 610:813dcc80987e 705 the HAL_PCD_ResumeCallback could be implemented in the user file
mbed_official 610:813dcc80987e 706 */
mbed_official 610:813dcc80987e 707 }
mbed_official 610:813dcc80987e 708
mbed_official 610:813dcc80987e 709 /**
mbed_official 610:813dcc80987e 710 * @brief Incomplete ISO OUT callback.
mbed_official 610:813dcc80987e 711 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 712 * @param epnum: endpoint number
mbed_official 610:813dcc80987e 713 * @retval None
mbed_official 610:813dcc80987e 714 */
mbed_official 610:813dcc80987e 715 __weak void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
mbed_official 610:813dcc80987e 716 {
mbed_official 610:813dcc80987e 717 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 610:813dcc80987e 718 the HAL_PCD_ISOOUTIncompleteCallback could be implemented in the user file
mbed_official 610:813dcc80987e 719 */
mbed_official 610:813dcc80987e 720 }
mbed_official 610:813dcc80987e 721
mbed_official 610:813dcc80987e 722 /**
mbed_official 610:813dcc80987e 723 * @brief Incomplete ISO IN callback.
mbed_official 610:813dcc80987e 724 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 725 * @param epnum: endpoint number
mbed_official 610:813dcc80987e 726 * @retval None
mbed_official 610:813dcc80987e 727 */
mbed_official 610:813dcc80987e 728 __weak void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum)
mbed_official 610:813dcc80987e 729 {
mbed_official 610:813dcc80987e 730 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 610:813dcc80987e 731 the HAL_PCD_ISOINIncompleteCallback could be implemented in the user file
mbed_official 610:813dcc80987e 732 */
mbed_official 610:813dcc80987e 733 }
mbed_official 610:813dcc80987e 734
mbed_official 610:813dcc80987e 735 /**
mbed_official 610:813dcc80987e 736 * @brief Connection event callback.
mbed_official 610:813dcc80987e 737 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 738 * @retval None
mbed_official 610:813dcc80987e 739 */
mbed_official 610:813dcc80987e 740 __weak void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd)
mbed_official 610:813dcc80987e 741 {
mbed_official 610:813dcc80987e 742 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 610:813dcc80987e 743 the HAL_PCD_ConnectCallback could be implemented in the user file
mbed_official 610:813dcc80987e 744 */
mbed_official 610:813dcc80987e 745 }
mbed_official 610:813dcc80987e 746
mbed_official 610:813dcc80987e 747 /**
mbed_official 610:813dcc80987e 748 * @brief Disconnection event callback.
mbed_official 610:813dcc80987e 749 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 750 * @retval None
mbed_official 610:813dcc80987e 751 */
mbed_official 610:813dcc80987e 752 __weak void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd)
mbed_official 610:813dcc80987e 753 {
mbed_official 610:813dcc80987e 754 /* NOTE : This function should not be modified, when the callback is needed,
mbed_official 610:813dcc80987e 755 the HAL_PCD_DisconnectCallback could be implemented in the user file
mbed_official 610:813dcc80987e 756 */
mbed_official 610:813dcc80987e 757 }
mbed_official 610:813dcc80987e 758
mbed_official 610:813dcc80987e 759 /**
mbed_official 610:813dcc80987e 760 * @}
mbed_official 610:813dcc80987e 761 */
mbed_official 610:813dcc80987e 762
mbed_official 610:813dcc80987e 763 /** @defgroup PCD_Exported_Functions_Group3 Peripheral Control functions
mbed_official 610:813dcc80987e 764 * @brief management functions
mbed_official 610:813dcc80987e 765 *
mbed_official 610:813dcc80987e 766 @verbatim
mbed_official 610:813dcc80987e 767 ===============================================================================
mbed_official 610:813dcc80987e 768 ##### Peripheral Control functions #####
mbed_official 610:813dcc80987e 769 ===============================================================================
mbed_official 610:813dcc80987e 770 [..]
mbed_official 610:813dcc80987e 771 This subsection provides a set of functions allowing to control the PCD data
mbed_official 610:813dcc80987e 772 transfers.
mbed_official 610:813dcc80987e 773
mbed_official 610:813dcc80987e 774 @endverbatim
mbed_official 610:813dcc80987e 775 * @{
mbed_official 610:813dcc80987e 776 */
mbed_official 610:813dcc80987e 777
mbed_official 610:813dcc80987e 778 /**
mbed_official 610:813dcc80987e 779 * @brief Connect the USB device.
mbed_official 610:813dcc80987e 780 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 781 * @retval HAL status
mbed_official 610:813dcc80987e 782 */
mbed_official 610:813dcc80987e 783 HAL_StatusTypeDef HAL_PCD_DevConnect(PCD_HandleTypeDef *hpcd)
mbed_official 610:813dcc80987e 784 {
mbed_official 610:813dcc80987e 785 __HAL_LOCK(hpcd);
mbed_official 610:813dcc80987e 786 USB_DevConnect(hpcd->Instance);
mbed_official 610:813dcc80987e 787 __HAL_UNLOCK(hpcd);
mbed_official 610:813dcc80987e 788 return HAL_OK;
mbed_official 610:813dcc80987e 789 }
mbed_official 610:813dcc80987e 790
mbed_official 610:813dcc80987e 791 /**
mbed_official 610:813dcc80987e 792 * @brief Disconnect the USB device.
mbed_official 610:813dcc80987e 793 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 794 * @retval HAL status
mbed_official 610:813dcc80987e 795 */
mbed_official 610:813dcc80987e 796 HAL_StatusTypeDef HAL_PCD_DevDisconnect(PCD_HandleTypeDef *hpcd)
mbed_official 610:813dcc80987e 797 {
mbed_official 610:813dcc80987e 798 __HAL_LOCK(hpcd);
mbed_official 610:813dcc80987e 799 USB_DevDisconnect(hpcd->Instance);
mbed_official 610:813dcc80987e 800 __HAL_UNLOCK(hpcd);
mbed_official 610:813dcc80987e 801 return HAL_OK;
mbed_official 610:813dcc80987e 802 }
mbed_official 610:813dcc80987e 803
mbed_official 610:813dcc80987e 804 /**
mbed_official 610:813dcc80987e 805 * @brief Set the USB Device address.
mbed_official 610:813dcc80987e 806 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 807 * @param address: new device address
mbed_official 610:813dcc80987e 808 * @retval HAL status
mbed_official 610:813dcc80987e 809 */
mbed_official 610:813dcc80987e 810 HAL_StatusTypeDef HAL_PCD_SetAddress(PCD_HandleTypeDef *hpcd, uint8_t address)
mbed_official 610:813dcc80987e 811 {
mbed_official 610:813dcc80987e 812 __HAL_LOCK(hpcd);
mbed_official 610:813dcc80987e 813 USB_SetDevAddress(hpcd->Instance, address);
mbed_official 610:813dcc80987e 814 __HAL_UNLOCK(hpcd);
mbed_official 610:813dcc80987e 815 return HAL_OK;
mbed_official 610:813dcc80987e 816 }
mbed_official 610:813dcc80987e 817 /**
mbed_official 610:813dcc80987e 818 * @brief Open and configure an endpoint.
mbed_official 610:813dcc80987e 819 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 820 * @param ep_addr: endpoint address
mbed_official 610:813dcc80987e 821 * @param ep_mps: endpoint max packet size
mbed_official 610:813dcc80987e 822 * @param ep_type: endpoint type
mbed_official 610:813dcc80987e 823 * @retval HAL status
mbed_official 610:813dcc80987e 824 */
mbed_official 610:813dcc80987e 825 HAL_StatusTypeDef HAL_PCD_EP_Open(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type)
mbed_official 610:813dcc80987e 826 {
mbed_official 610:813dcc80987e 827 HAL_StatusTypeDef ret = HAL_OK;
mbed_official 610:813dcc80987e 828 USB_OTG_EPTypeDef *ep;
mbed_official 610:813dcc80987e 829
mbed_official 610:813dcc80987e 830 if ((ep_addr & 0x80) == 0x80)
mbed_official 610:813dcc80987e 831 {
mbed_official 610:813dcc80987e 832 ep = &hpcd->IN_ep[ep_addr & 0x7F];
mbed_official 610:813dcc80987e 833 }
mbed_official 610:813dcc80987e 834 else
mbed_official 610:813dcc80987e 835 {
mbed_official 610:813dcc80987e 836 ep = &hpcd->OUT_ep[ep_addr & 0x7F];
mbed_official 610:813dcc80987e 837 }
mbed_official 610:813dcc80987e 838 ep->num = ep_addr & 0x7F;
mbed_official 610:813dcc80987e 839
mbed_official 610:813dcc80987e 840 ep->is_in = (0x80 & ep_addr) != 0;
mbed_official 610:813dcc80987e 841 ep->maxpacket = ep_mps;
mbed_official 610:813dcc80987e 842 ep->type = ep_type;
mbed_official 610:813dcc80987e 843 if (ep->is_in)
mbed_official 610:813dcc80987e 844 {
mbed_official 610:813dcc80987e 845 /* Assign a Tx FIFO */
mbed_official 610:813dcc80987e 846 ep->tx_fifo_num = ep->num;
mbed_official 610:813dcc80987e 847 }
mbed_official 610:813dcc80987e 848 /* Set initial data PID. */
mbed_official 610:813dcc80987e 849 if (ep_type == EP_TYPE_BULK )
mbed_official 610:813dcc80987e 850 {
mbed_official 610:813dcc80987e 851 ep->data_pid_start = 0;
mbed_official 610:813dcc80987e 852 }
mbed_official 610:813dcc80987e 853
mbed_official 610:813dcc80987e 854 __HAL_LOCK(hpcd);
mbed_official 610:813dcc80987e 855 USB_ActivateEndpoint(hpcd->Instance , ep);
mbed_official 610:813dcc80987e 856 __HAL_UNLOCK(hpcd);
mbed_official 610:813dcc80987e 857 return ret;
mbed_official 610:813dcc80987e 858 }
mbed_official 610:813dcc80987e 859
mbed_official 610:813dcc80987e 860
mbed_official 610:813dcc80987e 861 /**
mbed_official 610:813dcc80987e 862 * @brief Deactivate an endpoint.
mbed_official 610:813dcc80987e 863 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 864 * @param ep_addr: endpoint address
mbed_official 610:813dcc80987e 865 * @retval HAL status
mbed_official 610:813dcc80987e 866 */
mbed_official 610:813dcc80987e 867 HAL_StatusTypeDef HAL_PCD_EP_Close(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
mbed_official 610:813dcc80987e 868 {
mbed_official 610:813dcc80987e 869 USB_OTG_EPTypeDef *ep;
mbed_official 610:813dcc80987e 870
mbed_official 610:813dcc80987e 871 if ((ep_addr & 0x80) == 0x80)
mbed_official 610:813dcc80987e 872 {
mbed_official 610:813dcc80987e 873 ep = &hpcd->IN_ep[ep_addr & 0x7F];
mbed_official 610:813dcc80987e 874 }
mbed_official 610:813dcc80987e 875 else
mbed_official 610:813dcc80987e 876 {
mbed_official 610:813dcc80987e 877 ep = &hpcd->OUT_ep[ep_addr & 0x7F];
mbed_official 610:813dcc80987e 878 }
mbed_official 610:813dcc80987e 879 ep->num = ep_addr & 0x7F;
mbed_official 610:813dcc80987e 880
mbed_official 610:813dcc80987e 881 ep->is_in = (0x80 & ep_addr) != 0;
mbed_official 610:813dcc80987e 882
mbed_official 610:813dcc80987e 883 __HAL_LOCK(hpcd);
mbed_official 610:813dcc80987e 884 USB_DeactivateEndpoint(hpcd->Instance , ep);
mbed_official 610:813dcc80987e 885 __HAL_UNLOCK(hpcd);
mbed_official 610:813dcc80987e 886 return HAL_OK;
mbed_official 610:813dcc80987e 887 }
mbed_official 610:813dcc80987e 888
mbed_official 610:813dcc80987e 889
mbed_official 610:813dcc80987e 890 /**
mbed_official 610:813dcc80987e 891 * @brief Receive an amount of data.
mbed_official 610:813dcc80987e 892 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 893 * @param ep_addr: endpoint address
mbed_official 610:813dcc80987e 894 * @param pBuf: pointer to the reception buffer
mbed_official 610:813dcc80987e 895 * @param len: amount of data to be received
mbed_official 610:813dcc80987e 896 * @retval HAL status
mbed_official 610:813dcc80987e 897 */
mbed_official 610:813dcc80987e 898 HAL_StatusTypeDef HAL_PCD_EP_Receive(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len)
mbed_official 610:813dcc80987e 899 {
mbed_official 610:813dcc80987e 900 USB_OTG_EPTypeDef *ep;
mbed_official 610:813dcc80987e 901
mbed_official 610:813dcc80987e 902 ep = &hpcd->OUT_ep[ep_addr & 0x7F];
mbed_official 610:813dcc80987e 903
mbed_official 610:813dcc80987e 904 /*setup and start the Xfer */
mbed_official 610:813dcc80987e 905 ep->xfer_buff = pBuf;
mbed_official 610:813dcc80987e 906 ep->xfer_len = len;
mbed_official 610:813dcc80987e 907 ep->xfer_count = 0;
mbed_official 610:813dcc80987e 908 ep->is_in = 0;
mbed_official 610:813dcc80987e 909 ep->num = ep_addr & 0x7F;
mbed_official 610:813dcc80987e 910
mbed_official 610:813dcc80987e 911 if (hpcd->Init.dma_enable == 1)
mbed_official 610:813dcc80987e 912 {
mbed_official 610:813dcc80987e 913 ep->dma_addr = (uint32_t)pBuf;
mbed_official 610:813dcc80987e 914 }
mbed_official 610:813dcc80987e 915
mbed_official 610:813dcc80987e 916 __HAL_LOCK(hpcd);
mbed_official 610:813dcc80987e 917
mbed_official 610:813dcc80987e 918 if ((ep_addr & 0x7F) == 0 )
mbed_official 610:813dcc80987e 919 {
mbed_official 610:813dcc80987e 920 USB_EP0StartXfer(hpcd->Instance , ep, hpcd->Init.dma_enable);
mbed_official 610:813dcc80987e 921 }
mbed_official 610:813dcc80987e 922 else
mbed_official 610:813dcc80987e 923 {
mbed_official 610:813dcc80987e 924 USB_EPStartXfer(hpcd->Instance , ep, hpcd->Init.dma_enable);
mbed_official 610:813dcc80987e 925 }
mbed_official 610:813dcc80987e 926 __HAL_UNLOCK(hpcd);
mbed_official 610:813dcc80987e 927
mbed_official 610:813dcc80987e 928 return HAL_OK;
mbed_official 610:813dcc80987e 929 }
mbed_official 610:813dcc80987e 930
mbed_official 610:813dcc80987e 931 /**
mbed_official 610:813dcc80987e 932 * @brief Get Received Data Size.
mbed_official 610:813dcc80987e 933 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 934 * @param ep_addr: endpoint address
mbed_official 610:813dcc80987e 935 * @retval Data Size
mbed_official 610:813dcc80987e 936 */
mbed_official 610:813dcc80987e 937 uint16_t HAL_PCD_EP_GetRxCount(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
mbed_official 610:813dcc80987e 938 {
mbed_official 610:813dcc80987e 939 return hpcd->OUT_ep[ep_addr & 0x7F].xfer_count;
mbed_official 610:813dcc80987e 940 }
mbed_official 610:813dcc80987e 941 /**
mbed_official 610:813dcc80987e 942 * @brief Send an amount of data.
mbed_official 610:813dcc80987e 943 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 944 * @param ep_addr: endpoint address
mbed_official 610:813dcc80987e 945 * @param pBuf: pointer to the transmission buffer
mbed_official 610:813dcc80987e 946 * @param len: amount of data to be sent
mbed_official 610:813dcc80987e 947 * @retval HAL status
mbed_official 610:813dcc80987e 948 */
mbed_official 610:813dcc80987e 949 HAL_StatusTypeDef HAL_PCD_EP_Transmit(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len)
mbed_official 610:813dcc80987e 950 {
mbed_official 610:813dcc80987e 951 USB_OTG_EPTypeDef *ep;
mbed_official 610:813dcc80987e 952
mbed_official 610:813dcc80987e 953 ep = &hpcd->IN_ep[ep_addr & 0x7F];
mbed_official 610:813dcc80987e 954
mbed_official 610:813dcc80987e 955 /*setup and start the Xfer */
mbed_official 610:813dcc80987e 956 ep->xfer_buff = pBuf;
mbed_official 610:813dcc80987e 957 ep->xfer_len = len;
mbed_official 610:813dcc80987e 958 ep->xfer_count = 0;
mbed_official 610:813dcc80987e 959 ep->is_in = 1;
mbed_official 610:813dcc80987e 960 ep->num = ep_addr & 0x7F;
mbed_official 610:813dcc80987e 961
mbed_official 610:813dcc80987e 962 if (hpcd->Init.dma_enable == 1)
mbed_official 610:813dcc80987e 963 {
mbed_official 610:813dcc80987e 964 ep->dma_addr = (uint32_t)pBuf;
mbed_official 610:813dcc80987e 965 }
mbed_official 610:813dcc80987e 966
mbed_official 610:813dcc80987e 967 __HAL_LOCK(hpcd);
mbed_official 610:813dcc80987e 968
mbed_official 610:813dcc80987e 969 if ((ep_addr & 0x7F) == 0 )
mbed_official 610:813dcc80987e 970 {
mbed_official 610:813dcc80987e 971 USB_EP0StartXfer(hpcd->Instance , ep, hpcd->Init.dma_enable);
mbed_official 610:813dcc80987e 972 }
mbed_official 610:813dcc80987e 973 else
mbed_official 610:813dcc80987e 974 {
mbed_official 610:813dcc80987e 975 USB_EPStartXfer(hpcd->Instance , ep, hpcd->Init.dma_enable);
mbed_official 610:813dcc80987e 976 }
mbed_official 610:813dcc80987e 977
mbed_official 610:813dcc80987e 978 __HAL_UNLOCK(hpcd);
mbed_official 610:813dcc80987e 979
mbed_official 610:813dcc80987e 980 return HAL_OK;
mbed_official 610:813dcc80987e 981 }
mbed_official 610:813dcc80987e 982
mbed_official 610:813dcc80987e 983 /**
mbed_official 610:813dcc80987e 984 * @brief Set a STALL condition over an endpoint.
mbed_official 610:813dcc80987e 985 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 986 * @param ep_addr: endpoint address
mbed_official 610:813dcc80987e 987 * @retval HAL status
mbed_official 610:813dcc80987e 988 */
mbed_official 610:813dcc80987e 989 HAL_StatusTypeDef HAL_PCD_EP_SetStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
mbed_official 610:813dcc80987e 990 {
mbed_official 610:813dcc80987e 991 USB_OTG_EPTypeDef *ep;
mbed_official 610:813dcc80987e 992
mbed_official 610:813dcc80987e 993 if ((0x80 & ep_addr) == 0x80)
mbed_official 610:813dcc80987e 994 {
mbed_official 610:813dcc80987e 995 ep = &hpcd->IN_ep[ep_addr & 0x7F];
mbed_official 610:813dcc80987e 996 }
mbed_official 610:813dcc80987e 997 else
mbed_official 610:813dcc80987e 998 {
mbed_official 610:813dcc80987e 999 ep = &hpcd->OUT_ep[ep_addr];
mbed_official 610:813dcc80987e 1000 }
mbed_official 610:813dcc80987e 1001
mbed_official 610:813dcc80987e 1002 ep->is_stall = 1;
mbed_official 610:813dcc80987e 1003 ep->num = ep_addr & 0x7F;
mbed_official 610:813dcc80987e 1004 ep->is_in = ((ep_addr & 0x80) == 0x80);
mbed_official 610:813dcc80987e 1005
mbed_official 610:813dcc80987e 1006
mbed_official 610:813dcc80987e 1007 __HAL_LOCK(hpcd);
mbed_official 610:813dcc80987e 1008 USB_EPSetStall(hpcd->Instance , ep);
mbed_official 610:813dcc80987e 1009 if((ep_addr & 0x7F) == 0)
mbed_official 610:813dcc80987e 1010 {
mbed_official 610:813dcc80987e 1011 USB_EP0_OutStart(hpcd->Instance, hpcd->Init.dma_enable, (uint8_t *)hpcd->Setup);
mbed_official 610:813dcc80987e 1012 }
mbed_official 610:813dcc80987e 1013 __HAL_UNLOCK(hpcd);
mbed_official 610:813dcc80987e 1014
mbed_official 610:813dcc80987e 1015 return HAL_OK;
mbed_official 610:813dcc80987e 1016 }
mbed_official 610:813dcc80987e 1017
mbed_official 610:813dcc80987e 1018 /**
mbed_official 610:813dcc80987e 1019 * @brief Clear a STALL condition over in an endpoint.
mbed_official 610:813dcc80987e 1020 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 1021 * @param ep_addr: endpoint address
mbed_official 610:813dcc80987e 1022 * @retval HAL status
mbed_official 610:813dcc80987e 1023 */
mbed_official 610:813dcc80987e 1024 HAL_StatusTypeDef HAL_PCD_EP_ClrStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
mbed_official 610:813dcc80987e 1025 {
mbed_official 610:813dcc80987e 1026 USB_OTG_EPTypeDef *ep;
mbed_official 610:813dcc80987e 1027
mbed_official 610:813dcc80987e 1028 if ((0x80 & ep_addr) == 0x80)
mbed_official 610:813dcc80987e 1029 {
mbed_official 610:813dcc80987e 1030 ep = &hpcd->IN_ep[ep_addr & 0x7F];
mbed_official 610:813dcc80987e 1031 }
mbed_official 610:813dcc80987e 1032 else
mbed_official 610:813dcc80987e 1033 {
mbed_official 610:813dcc80987e 1034 ep = &hpcd->OUT_ep[ep_addr];
mbed_official 610:813dcc80987e 1035 }
mbed_official 610:813dcc80987e 1036
mbed_official 610:813dcc80987e 1037 ep->is_stall = 0;
mbed_official 610:813dcc80987e 1038 ep->num = ep_addr & 0x7F;
mbed_official 610:813dcc80987e 1039 ep->is_in = ((ep_addr & 0x80) == 0x80);
mbed_official 610:813dcc80987e 1040
mbed_official 610:813dcc80987e 1041 __HAL_LOCK(hpcd);
mbed_official 610:813dcc80987e 1042 USB_EPClearStall(hpcd->Instance , ep);
mbed_official 610:813dcc80987e 1043 __HAL_UNLOCK(hpcd);
mbed_official 610:813dcc80987e 1044
mbed_official 610:813dcc80987e 1045 return HAL_OK;
mbed_official 610:813dcc80987e 1046 }
mbed_official 610:813dcc80987e 1047
mbed_official 610:813dcc80987e 1048 /**
mbed_official 610:813dcc80987e 1049 * @brief Flush an endpoint.
mbed_official 610:813dcc80987e 1050 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 1051 * @param ep_addr: endpoint address
mbed_official 610:813dcc80987e 1052 * @retval HAL status
mbed_official 610:813dcc80987e 1053 */
mbed_official 610:813dcc80987e 1054 HAL_StatusTypeDef HAL_PCD_EP_Flush(PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
mbed_official 610:813dcc80987e 1055 {
mbed_official 610:813dcc80987e 1056 __HAL_LOCK(hpcd);
mbed_official 610:813dcc80987e 1057
mbed_official 610:813dcc80987e 1058 if ((ep_addr & 0x80) == 0x80)
mbed_official 610:813dcc80987e 1059 {
mbed_official 610:813dcc80987e 1060 USB_FlushTxFifo(hpcd->Instance, ep_addr & 0x7F);
mbed_official 610:813dcc80987e 1061 }
mbed_official 610:813dcc80987e 1062 else
mbed_official 610:813dcc80987e 1063 {
mbed_official 610:813dcc80987e 1064 USB_FlushRxFifo(hpcd->Instance);
mbed_official 610:813dcc80987e 1065 }
mbed_official 610:813dcc80987e 1066
mbed_official 610:813dcc80987e 1067 __HAL_UNLOCK(hpcd);
mbed_official 610:813dcc80987e 1068
mbed_official 610:813dcc80987e 1069 return HAL_OK;
mbed_official 610:813dcc80987e 1070 }
mbed_official 610:813dcc80987e 1071
mbed_official 610:813dcc80987e 1072 /**
mbed_official 610:813dcc80987e 1073 * @brief Activate remote wakeup signalling.
mbed_official 610:813dcc80987e 1074 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 1075 * @retval HAL status
mbed_official 610:813dcc80987e 1076 */
mbed_official 610:813dcc80987e 1077 HAL_StatusTypeDef HAL_PCD_ActivateRemoteWakeup(PCD_HandleTypeDef *hpcd)
mbed_official 610:813dcc80987e 1078 {
mbed_official 610:813dcc80987e 1079 USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
mbed_official 610:813dcc80987e 1080
mbed_official 610:813dcc80987e 1081 if((USBx_DEVICE->DSTS & USB_OTG_DSTS_SUSPSTS) == USB_OTG_DSTS_SUSPSTS)
mbed_official 610:813dcc80987e 1082 {
mbed_official 610:813dcc80987e 1083 /* Activate Remote wakeup signaling */
mbed_official 610:813dcc80987e 1084 USBx_DEVICE->DCTL |= USB_OTG_DCTL_RWUSIG;
mbed_official 610:813dcc80987e 1085 }
mbed_official 610:813dcc80987e 1086 return HAL_OK;
mbed_official 610:813dcc80987e 1087 }
mbed_official 610:813dcc80987e 1088
mbed_official 610:813dcc80987e 1089 /**
mbed_official 610:813dcc80987e 1090 * @brief De-activate remote wakeup signalling.
mbed_official 610:813dcc80987e 1091 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 1092 * @retval HAL status
mbed_official 610:813dcc80987e 1093 */
mbed_official 610:813dcc80987e 1094 HAL_StatusTypeDef HAL_PCD_DeActivateRemoteWakeup(PCD_HandleTypeDef *hpcd)
mbed_official 610:813dcc80987e 1095 {
mbed_official 610:813dcc80987e 1096 USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
mbed_official 610:813dcc80987e 1097
mbed_official 610:813dcc80987e 1098 /* De-activate Remote wakeup signaling */
mbed_official 610:813dcc80987e 1099 USBx_DEVICE->DCTL &= ~(USB_OTG_DCTL_RWUSIG);
mbed_official 610:813dcc80987e 1100 return HAL_OK;
mbed_official 610:813dcc80987e 1101 }
mbed_official 610:813dcc80987e 1102 /**
mbed_official 610:813dcc80987e 1103 * @}
mbed_official 610:813dcc80987e 1104 */
mbed_official 610:813dcc80987e 1105
mbed_official 610:813dcc80987e 1106 /** @defgroup PCD_Exported_Functions_Group4 Peripheral State functions
mbed_official 610:813dcc80987e 1107 * @brief Peripheral State functions
mbed_official 610:813dcc80987e 1108 *
mbed_official 610:813dcc80987e 1109 @verbatim
mbed_official 610:813dcc80987e 1110 ===============================================================================
mbed_official 610:813dcc80987e 1111 ##### Peripheral State functions #####
mbed_official 610:813dcc80987e 1112 ===============================================================================
mbed_official 610:813dcc80987e 1113 [..]
mbed_official 610:813dcc80987e 1114 This subsection permits to get in run-time the status of the peripheral
mbed_official 610:813dcc80987e 1115 and the data flow.
mbed_official 610:813dcc80987e 1116
mbed_official 610:813dcc80987e 1117 @endverbatim
mbed_official 610:813dcc80987e 1118 * @{
mbed_official 610:813dcc80987e 1119 */
mbed_official 610:813dcc80987e 1120
mbed_official 610:813dcc80987e 1121 /**
mbed_official 610:813dcc80987e 1122 * @brief Return the PCD handle state.
mbed_official 610:813dcc80987e 1123 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 1124 * @retval HAL state
mbed_official 610:813dcc80987e 1125 */
mbed_official 610:813dcc80987e 1126 PCD_StateTypeDef HAL_PCD_GetState(PCD_HandleTypeDef *hpcd)
mbed_official 610:813dcc80987e 1127 {
mbed_official 610:813dcc80987e 1128 return hpcd->State;
mbed_official 610:813dcc80987e 1129 }
mbed_official 610:813dcc80987e 1130 /**
mbed_official 610:813dcc80987e 1131 * @}
mbed_official 610:813dcc80987e 1132 */
mbed_official 610:813dcc80987e 1133
mbed_official 610:813dcc80987e 1134 /**
mbed_official 610:813dcc80987e 1135 * @}
mbed_official 610:813dcc80987e 1136 */
mbed_official 610:813dcc80987e 1137
mbed_official 610:813dcc80987e 1138 /* Private functions ---------------------------------------------------------*/
mbed_official 610:813dcc80987e 1139 /** @addtogroup PCD_Private_Functions
mbed_official 610:813dcc80987e 1140 * @{
mbed_official 610:813dcc80987e 1141 */
mbed_official 610:813dcc80987e 1142
mbed_official 610:813dcc80987e 1143 /**
mbed_official 610:813dcc80987e 1144 * @brief Check FIFO for the next packet to be loaded.
mbed_official 610:813dcc80987e 1145 * @param hpcd: PCD handle
mbed_official 610:813dcc80987e 1146 * @param epnum: endpoint number
mbed_official 610:813dcc80987e 1147 * @retval HAL status
mbed_official 610:813dcc80987e 1148 */
mbed_official 610:813dcc80987e 1149 static HAL_StatusTypeDef PCD_WriteEmptyTxFifo(PCD_HandleTypeDef *hpcd, uint32_t epnum)
mbed_official 610:813dcc80987e 1150 {
mbed_official 610:813dcc80987e 1151 USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
mbed_official 610:813dcc80987e 1152 USB_OTG_EPTypeDef *ep;
mbed_official 610:813dcc80987e 1153 int32_t len = 0;
mbed_official 610:813dcc80987e 1154 uint32_t len32b;
mbed_official 610:813dcc80987e 1155 uint32_t fifoemptymsk = 0;
mbed_official 610:813dcc80987e 1156
mbed_official 610:813dcc80987e 1157 ep = &hpcd->IN_ep[epnum];
mbed_official 610:813dcc80987e 1158 len = ep->xfer_len - ep->xfer_count;
mbed_official 610:813dcc80987e 1159
mbed_official 610:813dcc80987e 1160 if (len > ep->maxpacket)
mbed_official 610:813dcc80987e 1161 {
mbed_official 610:813dcc80987e 1162 len = ep->maxpacket;
mbed_official 610:813dcc80987e 1163 }
mbed_official 610:813dcc80987e 1164
mbed_official 610:813dcc80987e 1165
mbed_official 610:813dcc80987e 1166 len32b = (len + 3) / 4;
mbed_official 610:813dcc80987e 1167
mbed_official 610:813dcc80987e 1168 while ( (USBx_INEP(epnum)->DTXFSTS & USB_OTG_DTXFSTS_INEPTFSAV) > len32b &&
mbed_official 610:813dcc80987e 1169 ep->xfer_count < ep->xfer_len &&
mbed_official 610:813dcc80987e 1170 ep->xfer_len != 0)
mbed_official 610:813dcc80987e 1171 {
mbed_official 610:813dcc80987e 1172 /* Write the FIFO */
mbed_official 610:813dcc80987e 1173 len = ep->xfer_len - ep->xfer_count;
mbed_official 610:813dcc80987e 1174
mbed_official 610:813dcc80987e 1175 if (len > ep->maxpacket)
mbed_official 610:813dcc80987e 1176 {
mbed_official 610:813dcc80987e 1177 len = ep->maxpacket;
mbed_official 610:813dcc80987e 1178 }
mbed_official 610:813dcc80987e 1179 len32b = (len + 3) / 4;
mbed_official 610:813dcc80987e 1180
mbed_official 610:813dcc80987e 1181 USB_WritePacket(USBx, ep->xfer_buff, epnum, len, hpcd->Init.dma_enable);
mbed_official 610:813dcc80987e 1182
mbed_official 610:813dcc80987e 1183 ep->xfer_buff += len;
mbed_official 610:813dcc80987e 1184 ep->xfer_count += len;
mbed_official 610:813dcc80987e 1185 }
mbed_official 610:813dcc80987e 1186
mbed_official 610:813dcc80987e 1187 if(len <= 0)
mbed_official 610:813dcc80987e 1188 {
mbed_official 610:813dcc80987e 1189 fifoemptymsk = 0x1 << epnum;
mbed_official 610:813dcc80987e 1190 USBx_DEVICE->DIEPEMPMSK &= ~fifoemptymsk;
mbed_official 610:813dcc80987e 1191
mbed_official 610:813dcc80987e 1192 }
mbed_official 610:813dcc80987e 1193
mbed_official 610:813dcc80987e 1194 return HAL_OK;
mbed_official 610:813dcc80987e 1195 }
mbed_official 610:813dcc80987e 1196
mbed_official 610:813dcc80987e 1197 /**
mbed_official 610:813dcc80987e 1198 * @}
mbed_official 610:813dcc80987e 1199 */
mbed_official 610:813dcc80987e 1200
mbed_official 610:813dcc80987e 1201 #endif /* HAL_PCD_MODULE_ENABLED */
mbed_official 610:813dcc80987e 1202 /**
mbed_official 610:813dcc80987e 1203 * @}
mbed_official 610:813dcc80987e 1204 */
mbed_official 610:813dcc80987e 1205
mbed_official 610:813dcc80987e 1206 /**
mbed_official 610:813dcc80987e 1207 * @}
mbed_official 610:813dcc80987e 1208 */
mbed_official 610:813dcc80987e 1209
mbed_official 610:813dcc80987e 1210 #endif /* STM32L475xx || STM32L476xx || STM32L485xx || STM32L486xx */
mbed_official 610:813dcc80987e 1211
mbed_official 610:813dcc80987e 1212 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/