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