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