mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Thu Aug 20 10:45:13 2015 +0100
Revision:
613:bc40b8d2aec4
Parent:
532:fe11edbda85c
Synchronized with git revision 92ca8c7b60a283b6bb60eb65b183dac1599f0ade

Full URL: https://github.com/mbedmicro/mbed/commit/92ca8c7b60a283b6bb60eb65b183dac1599f0ade/

Nordic: update application start address in GCC linker script

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 235:685d5f11838f 1 /**
mbed_official 235:685d5f11838f 2 ******************************************************************************
mbed_official 235:685d5f11838f 3 * @file stm32f4xx_hal_hcd.c
mbed_official 235:685d5f11838f 4 * @author MCD Application Team
mbed_official 613:bc40b8d2aec4 5 * @version V1.3.2
mbed_official 613:bc40b8d2aec4 6 * @date 26-June-2015
mbed_official 235:685d5f11838f 7 * @brief HCD 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 (#)Declare a HCD_HandleTypeDef handle structure, for example:
mbed_official 235:685d5f11838f 21 HCD_HandleTypeDef hhcd;
mbed_official 235:685d5f11838f 22
mbed_official 235:685d5f11838f 23 (#)Fill parameters of Init structure in HCD handle
mbed_official 235:685d5f11838f 24
mbed_official 235:685d5f11838f 25 (#)Call HAL_HCD_Init() API to initialize the HCD peripheral (Core, Host core, ...)
mbed_official 235:685d5f11838f 26
mbed_official 235:685d5f11838f 27 (#)Initialize the HCD low level resources through the HAL_HCD_MspInit() API:
mbed_official 235:685d5f11838f 28 (##) Enable the HCD/USB Low Level interface clock using the following macros
mbed_official 613:bc40b8d2aec4 29 (+++) __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
mbed_official 613:bc40b8d2aec4 30 (+++) __HAL_RCC_USB_OTG_HS_CLK_ENABLE(); (For High Speed Mode)
mbed_official 613:bc40b8d2aec4 31 (+++) __HAL_RCC_USB_OTG_HS_ULPI_CLK_ENABLE(); (For High Speed Mode)
mbed_official 235:685d5f11838f 32
mbed_official 235:685d5f11838f 33 (##) Initialize the related GPIO clocks
mbed_official 235:685d5f11838f 34 (##) Configure HCD pin-out
mbed_official 235:685d5f11838f 35 (##) Configure HCD NVIC interrupt
mbed_official 235:685d5f11838f 36
mbed_official 235:685d5f11838f 37 (#)Associate the Upper USB Host stack to the HAL HCD Driver:
mbed_official 235:685d5f11838f 38 (##) hhcd.pData = phost;
mbed_official 235:685d5f11838f 39
mbed_official 235:685d5f11838f 40 (#)Enable HCD transmission and reception:
mbed_official 235:685d5f11838f 41 (##) HAL_HCD_Start();
mbed_official 235:685d5f11838f 42
mbed_official 235:685d5f11838f 43 @endverbatim
mbed_official 235:685d5f11838f 44 ******************************************************************************
mbed_official 235:685d5f11838f 45 * @attention
mbed_official 235:685d5f11838f 46 *
mbed_official 532:fe11edbda85c 47 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
mbed_official 235:685d5f11838f 48 *
mbed_official 235:685d5f11838f 49 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 235:685d5f11838f 50 * are permitted provided that the following conditions are met:
mbed_official 235:685d5f11838f 51 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 235:685d5f11838f 52 * this list of conditions and the following disclaimer.
mbed_official 235:685d5f11838f 53 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 235:685d5f11838f 54 * this list of conditions and the following disclaimer in the documentation
mbed_official 235:685d5f11838f 55 * and/or other materials provided with the distribution.
mbed_official 235:685d5f11838f 56 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 235:685d5f11838f 57 * may be used to endorse or promote products derived from this software
mbed_official 235:685d5f11838f 58 * without specific prior written permission.
mbed_official 235:685d5f11838f 59 *
mbed_official 235:685d5f11838f 60 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 235:685d5f11838f 61 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 235:685d5f11838f 62 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 235:685d5f11838f 63 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 235:685d5f11838f 64 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 235:685d5f11838f 65 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 235:685d5f11838f 66 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 235:685d5f11838f 67 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 235:685d5f11838f 68 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 235:685d5f11838f 69 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 235:685d5f11838f 70 *
mbed_official 235:685d5f11838f 71 ******************************************************************************
mbed_official 235:685d5f11838f 72 */
mbed_official 235:685d5f11838f 73
mbed_official 235:685d5f11838f 74 /* Includes ------------------------------------------------------------------*/
mbed_official 235:685d5f11838f 75 #include "stm32f4xx_hal.h"
mbed_official 532:fe11edbda85c 76
mbed_official 235:685d5f11838f 77 /** @addtogroup STM32F4xx_HAL_Driver
mbed_official 235:685d5f11838f 78 * @{
mbed_official 235:685d5f11838f 79 */
mbed_official 235:685d5f11838f 80
mbed_official 613:bc40b8d2aec4 81 /** @defgroup HCD HCD
mbed_official 613:bc40b8d2aec4 82 * @brief HCD HAL module driver
mbed_official 235:685d5f11838f 83 * @{
mbed_official 235:685d5f11838f 84 */
mbed_official 235:685d5f11838f 85
mbed_official 235:685d5f11838f 86 #ifdef HAL_HCD_MODULE_ENABLED
mbed_official 235:685d5f11838f 87
mbed_official 235:685d5f11838f 88 /* Private typedef -----------------------------------------------------------*/
mbed_official 235:685d5f11838f 89 /* Private define ------------------------------------------------------------*/
mbed_official 235:685d5f11838f 90 /* Private macro -------------------------------------------------------------*/
mbed_official 235:685d5f11838f 91 /* Private variables ---------------------------------------------------------*/
mbed_official 613:bc40b8d2aec4 92 /* Private function prototypes -----------------------------------------------*/
mbed_official 613:bc40b8d2aec4 93 /** @defgroup HCD_Private_Functions HCD Private Functions
mbed_official 532:fe11edbda85c 94 * @{
mbed_official 532:fe11edbda85c 95 */
mbed_official 235:685d5f11838f 96 static void HCD_HC_IN_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum);
mbed_official 235:685d5f11838f 97 static void HCD_HC_OUT_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum);
mbed_official 235:685d5f11838f 98 static void HCD_RXQLVL_IRQHandler(HCD_HandleTypeDef *hhcd);
mbed_official 235:685d5f11838f 99 static void HCD_Port_IRQHandler(HCD_HandleTypeDef *hhcd);
mbed_official 532:fe11edbda85c 100 /**
mbed_official 532:fe11edbda85c 101 * @}
mbed_official 532:fe11edbda85c 102 */
mbed_official 235:685d5f11838f 103
mbed_official 532:fe11edbda85c 104 /* Exported functions --------------------------------------------------------*/
mbed_official 613:bc40b8d2aec4 105 /** @defgroup HCD_Exported_Functions HCD Exported Functions
mbed_official 235:685d5f11838f 106 * @{
mbed_official 235:685d5f11838f 107 */
mbed_official 235:685d5f11838f 108
mbed_official 613:bc40b8d2aec4 109 /** @defgroup HCD_Exported_Functions_Group1 Initialization and de-initialization functions
mbed_official 613:bc40b8d2aec4 110 * @brief Initialization and Configuration functions
mbed_official 235:685d5f11838f 111 *
mbed_official 532:fe11edbda85c 112 @verbatim
mbed_official 235:685d5f11838f 113 ===============================================================================
mbed_official 235:685d5f11838f 114 ##### Initialization and de-initialization functions #####
mbed_official 235:685d5f11838f 115 ===============================================================================
mbed_official 235:685d5f11838f 116 [..] This section provides functions allowing to:
mbed_official 235:685d5f11838f 117
mbed_official 235:685d5f11838f 118 @endverbatim
mbed_official 235:685d5f11838f 119 * @{
mbed_official 235:685d5f11838f 120 */
mbed_official 235:685d5f11838f 121
mbed_official 235:685d5f11838f 122 /**
mbed_official 613:bc40b8d2aec4 123 * @brief Initialize the host driver.
mbed_official 235:685d5f11838f 124 * @param hhcd: HCD handle
mbed_official 235:685d5f11838f 125 * @retval HAL status
mbed_official 235:685d5f11838f 126 */
mbed_official 235:685d5f11838f 127 HAL_StatusTypeDef HAL_HCD_Init(HCD_HandleTypeDef *hhcd)
mbed_official 235:685d5f11838f 128 {
mbed_official 235:685d5f11838f 129 /* Check the HCD handle allocation */
mbed_official 613:bc40b8d2aec4 130 if(hhcd == NULL)
mbed_official 235:685d5f11838f 131 {
mbed_official 235:685d5f11838f 132 return HAL_ERROR;
mbed_official 235:685d5f11838f 133 }
mbed_official 235:685d5f11838f 134
mbed_official 235:685d5f11838f 135 /* Check the parameters */
mbed_official 235:685d5f11838f 136 assert_param(IS_HCD_ALL_INSTANCE(hhcd->Instance));
mbed_official 532:fe11edbda85c 137
mbed_official 235:685d5f11838f 138 hhcd->State = HAL_HCD_STATE_BUSY;
mbed_official 235:685d5f11838f 139
mbed_official 235:685d5f11838f 140 /* Init the low level hardware : GPIO, CLOCK, NVIC... */
mbed_official 235:685d5f11838f 141 HAL_HCD_MspInit(hhcd);
mbed_official 532:fe11edbda85c 142
mbed_official 235:685d5f11838f 143 /* Disable the Interrupts */
mbed_official 532:fe11edbda85c 144 __HAL_HCD_DISABLE(hhcd);
mbed_official 532:fe11edbda85c 145
mbed_official 532:fe11edbda85c 146 /* Init the Core (common init.) */
mbed_official 532:fe11edbda85c 147 USB_CoreInit(hhcd->Instance, hhcd->Init);
mbed_official 532:fe11edbda85c 148
mbed_official 532:fe11edbda85c 149 /* Force Host Mode*/
mbed_official 532:fe11edbda85c 150 USB_SetCurrentMode(hhcd->Instance , USB_OTG_HOST_MODE);
mbed_official 532:fe11edbda85c 151
mbed_official 532:fe11edbda85c 152 /* Init Host */
mbed_official 532:fe11edbda85c 153 USB_HostInit(hhcd->Instance, hhcd->Init);
mbed_official 532:fe11edbda85c 154
mbed_official 532:fe11edbda85c 155 hhcd->State= HAL_HCD_STATE_READY;
mbed_official 532:fe11edbda85c 156
mbed_official 532:fe11edbda85c 157 return HAL_OK;
mbed_official 235:685d5f11838f 158 }
mbed_official 235:685d5f11838f 159
mbed_official 235:685d5f11838f 160 /**
mbed_official 613:bc40b8d2aec4 161 * @brief Initialize a host channel.
mbed_official 235:685d5f11838f 162 * @param hhcd: HCD handle
mbed_official 235:685d5f11838f 163 * @param ch_num: Channel number.
mbed_official 235:685d5f11838f 164 * This parameter can be a value from 1 to 15
mbed_official 235:685d5f11838f 165 * @param epnum: Endpoint number.
mbed_official 235:685d5f11838f 166 * This parameter can be a value from 1 to 15
mbed_official 235:685d5f11838f 167 * @param dev_address : Current device address
mbed_official 235:685d5f11838f 168 * This parameter can be a value from 0 to 255
mbed_official 235:685d5f11838f 169 * @param speed: Current device speed.
mbed_official 235:685d5f11838f 170 * This parameter can be one of these values:
mbed_official 235:685d5f11838f 171 * HCD_SPEED_HIGH: High speed mode,
mbed_official 235:685d5f11838f 172 * HCD_SPEED_FULL: Full speed mode,
mbed_official 235:685d5f11838f 173 * HCD_SPEED_LOW: Low speed mode
mbed_official 235:685d5f11838f 174 * @param ep_type: Endpoint Type.
mbed_official 235:685d5f11838f 175 * This parameter can be one of these values:
mbed_official 235:685d5f11838f 176 * EP_TYPE_CTRL: Control type,
mbed_official 532:fe11edbda85c 177 * EP_TYPE_ISOC: Isochronous type,
mbed_official 235:685d5f11838f 178 * EP_TYPE_BULK: Bulk type,
mbed_official 235:685d5f11838f 179 * EP_TYPE_INTR: Interrupt type
mbed_official 235:685d5f11838f 180 * @param mps: Max Packet Size.
mbed_official 235:685d5f11838f 181 * This parameter can be a value from 0 to32K
mbed_official 235:685d5f11838f 182 * @retval HAL status
mbed_official 235:685d5f11838f 183 */
mbed_official 235:685d5f11838f 184 HAL_StatusTypeDef HAL_HCD_HC_Init(HCD_HandleTypeDef *hhcd,
mbed_official 235:685d5f11838f 185 uint8_t ch_num,
mbed_official 235:685d5f11838f 186 uint8_t epnum,
mbed_official 235:685d5f11838f 187 uint8_t dev_address,
mbed_official 235:685d5f11838f 188 uint8_t speed,
mbed_official 235:685d5f11838f 189 uint8_t ep_type,
mbed_official 235:685d5f11838f 190 uint16_t mps)
mbed_official 235:685d5f11838f 191 {
mbed_official 235:685d5f11838f 192 HAL_StatusTypeDef status = HAL_OK;
mbed_official 235:685d5f11838f 193
mbed_official 235:685d5f11838f 194 __HAL_LOCK(hhcd);
mbed_official 235:685d5f11838f 195
mbed_official 235:685d5f11838f 196 hhcd->hc[ch_num].dev_addr = dev_address;
mbed_official 235:685d5f11838f 197 hhcd->hc[ch_num].max_packet = mps;
mbed_official 235:685d5f11838f 198 hhcd->hc[ch_num].ch_num = ch_num;
mbed_official 235:685d5f11838f 199 hhcd->hc[ch_num].ep_type = ep_type;
mbed_official 235:685d5f11838f 200 hhcd->hc[ch_num].ep_num = epnum & 0x7F;
mbed_official 235:685d5f11838f 201 hhcd->hc[ch_num].ep_is_in = ((epnum & 0x80) == 0x80);
mbed_official 235:685d5f11838f 202 hhcd->hc[ch_num].speed = speed;
mbed_official 532:fe11edbda85c 203
mbed_official 235:685d5f11838f 204 status = USB_HC_Init(hhcd->Instance,
mbed_official 235:685d5f11838f 205 ch_num,
mbed_official 235:685d5f11838f 206 epnum,
mbed_official 235:685d5f11838f 207 dev_address,
mbed_official 235:685d5f11838f 208 speed,
mbed_official 235:685d5f11838f 209 ep_type,
mbed_official 235:685d5f11838f 210 mps);
mbed_official 235:685d5f11838f 211 __HAL_UNLOCK(hhcd);
mbed_official 235:685d5f11838f 212
mbed_official 235:685d5f11838f 213 return status;
mbed_official 235:685d5f11838f 214 }
mbed_official 235:685d5f11838f 215
mbed_official 235:685d5f11838f 216 /**
mbed_official 613:bc40b8d2aec4 217 * @brief Halt a host channel.
mbed_official 235:685d5f11838f 218 * @param hhcd: HCD handle
mbed_official 235:685d5f11838f 219 * @param ch_num: Channel number.
mbed_official 235:685d5f11838f 220 * This parameter can be a value from 1 to 15
mbed_official 235:685d5f11838f 221 * @retval HAL status
mbed_official 235:685d5f11838f 222 */
mbed_official 532:fe11edbda85c 223 HAL_StatusTypeDef HAL_HCD_HC_Halt(HCD_HandleTypeDef *hhcd, uint8_t ch_num)
mbed_official 235:685d5f11838f 224 {
mbed_official 235:685d5f11838f 225 HAL_StatusTypeDef status = HAL_OK;
mbed_official 235:685d5f11838f 226
mbed_official 235:685d5f11838f 227 __HAL_LOCK(hhcd);
mbed_official 235:685d5f11838f 228 USB_HC_Halt(hhcd->Instance, ch_num);
mbed_official 235:685d5f11838f 229 __HAL_UNLOCK(hhcd);
mbed_official 235:685d5f11838f 230
mbed_official 235:685d5f11838f 231 return status;
mbed_official 235:685d5f11838f 232 }
mbed_official 532:fe11edbda85c 233
mbed_official 235:685d5f11838f 234 /**
mbed_official 613:bc40b8d2aec4 235 * @brief DeInitialize the host driver.
mbed_official 235:685d5f11838f 236 * @param hhcd: HCD handle
mbed_official 235:685d5f11838f 237 * @retval HAL status
mbed_official 235:685d5f11838f 238 */
mbed_official 235:685d5f11838f 239 HAL_StatusTypeDef HAL_HCD_DeInit(HCD_HandleTypeDef *hhcd)
mbed_official 235:685d5f11838f 240 {
mbed_official 235:685d5f11838f 241 /* Check the HCD handle allocation */
mbed_official 613:bc40b8d2aec4 242 if(hhcd == NULL)
mbed_official 235:685d5f11838f 243 {
mbed_official 235:685d5f11838f 244 return HAL_ERROR;
mbed_official 235:685d5f11838f 245 }
mbed_official 235:685d5f11838f 246
mbed_official 235:685d5f11838f 247 hhcd->State = HAL_HCD_STATE_BUSY;
mbed_official 235:685d5f11838f 248
mbed_official 235:685d5f11838f 249 /* DeInit the low level hardware */
mbed_official 235:685d5f11838f 250 HAL_HCD_MspDeInit(hhcd);
mbed_official 235:685d5f11838f 251
mbed_official 532:fe11edbda85c 252 __HAL_HCD_DISABLE(hhcd);
mbed_official 235:685d5f11838f 253
mbed_official 235:685d5f11838f 254 hhcd->State = HAL_HCD_STATE_RESET;
mbed_official 235:685d5f11838f 255
mbed_official 235:685d5f11838f 256 return HAL_OK;
mbed_official 235:685d5f11838f 257 }
mbed_official 235:685d5f11838f 258
mbed_official 235:685d5f11838f 259 /**
mbed_official 613:bc40b8d2aec4 260 * @brief Initialize the HCD MSP.
mbed_official 235:685d5f11838f 261 * @param hhcd: HCD handle
mbed_official 235:685d5f11838f 262 * @retval None
mbed_official 235:685d5f11838f 263 */
mbed_official 235:685d5f11838f 264 __weak void HAL_HCD_MspInit(HCD_HandleTypeDef *hhcd)
mbed_official 235:685d5f11838f 265 {
mbed_official 235:685d5f11838f 266 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 532:fe11edbda85c 267 the HAL_PCD_MspInit could be implemented in the user file
mbed_official 235:685d5f11838f 268 */
mbed_official 235:685d5f11838f 269 }
mbed_official 235:685d5f11838f 270
mbed_official 235:685d5f11838f 271 /**
mbed_official 613:bc40b8d2aec4 272 * @brief DeInitialize the HCD MSP.
mbed_official 235:685d5f11838f 273 * @param hhcd: HCD handle
mbed_official 235:685d5f11838f 274 * @retval None
mbed_official 235:685d5f11838f 275 */
mbed_official 532:fe11edbda85c 276 __weak void HAL_HCD_MspDeInit(HCD_HandleTypeDef *hhcd)
mbed_official 235:685d5f11838f 277 {
mbed_official 235:685d5f11838f 278 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 532:fe11edbda85c 279 the HAL_PCD_MspDeInit could be implemented in the user file
mbed_official 235:685d5f11838f 280 */
mbed_official 235:685d5f11838f 281 }
mbed_official 235:685d5f11838f 282
mbed_official 235:685d5f11838f 283 /**
mbed_official 235:685d5f11838f 284 * @}
mbed_official 235:685d5f11838f 285 */
mbed_official 235:685d5f11838f 286
mbed_official 613:bc40b8d2aec4 287 /** @defgroup HCD_Exported_Functions_Group2 Input and Output operation functions
mbed_official 235:685d5f11838f 288 * @brief HCD IO operation functions
mbed_official 235:685d5f11838f 289 *
mbed_official 235:685d5f11838f 290 @verbatim
mbed_official 235:685d5f11838f 291 ===============================================================================
mbed_official 235:685d5f11838f 292 ##### IO operation functions #####
mbed_official 235:685d5f11838f 293 ===============================================================================
mbed_official 613:bc40b8d2aec4 294 [..] This subsection provides a set of functions allowing to manage the USB Host Data
mbed_official 235:685d5f11838f 295 Transfer
mbed_official 235:685d5f11838f 296
mbed_official 235:685d5f11838f 297 @endverbatim
mbed_official 235:685d5f11838f 298 * @{
mbed_official 235:685d5f11838f 299 */
mbed_official 235:685d5f11838f 300
mbed_official 235:685d5f11838f 301 /**
mbed_official 613:bc40b8d2aec4 302 * @brief Submit a new URB for processing.
mbed_official 235:685d5f11838f 303 * @param hhcd: HCD handle
mbed_official 235:685d5f11838f 304 * @param ch_num: Channel number.
mbed_official 235:685d5f11838f 305 * This parameter can be a value from 1 to 15
mbed_official 235:685d5f11838f 306 * @param direction: Channel number.
mbed_official 235:685d5f11838f 307 * This parameter can be one of these values:
mbed_official 235:685d5f11838f 308 * 0 : Output / 1 : Input
mbed_official 235:685d5f11838f 309 * @param ep_type: Endpoint Type.
mbed_official 235:685d5f11838f 310 * This parameter can be one of these values:
mbed_official 235:685d5f11838f 311 * EP_TYPE_CTRL: Control type/
mbed_official 532:fe11edbda85c 312 * EP_TYPE_ISOC: Isochronous type/
mbed_official 235:685d5f11838f 313 * EP_TYPE_BULK: Bulk type/
mbed_official 235:685d5f11838f 314 * EP_TYPE_INTR: Interrupt type/
mbed_official 235:685d5f11838f 315 * @param token: Endpoint Type.
mbed_official 235:685d5f11838f 316 * This parameter can be one of these values:
mbed_official 235:685d5f11838f 317 * 0: HC_PID_SETUP / 1: HC_PID_DATA1
mbed_official 235:685d5f11838f 318 * @param pbuff: pointer to URB data
mbed_official 235:685d5f11838f 319 * @param length: Length of URB data
mbed_official 235:685d5f11838f 320 * @param do_ping: activate do ping protocol (for high speed only).
mbed_official 235:685d5f11838f 321 * This parameter can be one of these values:
mbed_official 235:685d5f11838f 322 * 0 : do ping inactive / 1 : do ping active
mbed_official 235:685d5f11838f 323 * @retval HAL status
mbed_official 235:685d5f11838f 324 */
mbed_official 235:685d5f11838f 325 HAL_StatusTypeDef HAL_HCD_HC_SubmitRequest(HCD_HandleTypeDef *hhcd,
mbed_official 532:fe11edbda85c 326 uint8_t ch_num,
mbed_official 532:fe11edbda85c 327 uint8_t direction,
mbed_official 532:fe11edbda85c 328 uint8_t ep_type,
mbed_official 532:fe11edbda85c 329 uint8_t token,
mbed_official 532:fe11edbda85c 330 uint8_t* pbuff,
mbed_official 532:fe11edbda85c 331 uint16_t length,
mbed_official 532:fe11edbda85c 332 uint8_t do_ping)
mbed_official 235:685d5f11838f 333 {
mbed_official 235:685d5f11838f 334 hhcd->hc[ch_num].ep_is_in = direction;
mbed_official 235:685d5f11838f 335 hhcd->hc[ch_num].ep_type = ep_type;
mbed_official 235:685d5f11838f 336
mbed_official 235:685d5f11838f 337 if(token == 0)
mbed_official 235:685d5f11838f 338 {
mbed_official 235:685d5f11838f 339 hhcd->hc[ch_num].data_pid = HC_PID_SETUP;
mbed_official 235:685d5f11838f 340 }
mbed_official 235:685d5f11838f 341 else
mbed_official 235:685d5f11838f 342 {
mbed_official 235:685d5f11838f 343 hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
mbed_official 235:685d5f11838f 344 }
mbed_official 235:685d5f11838f 345
mbed_official 235:685d5f11838f 346 /* Manage Data Toggle */
mbed_official 235:685d5f11838f 347 switch(ep_type)
mbed_official 235:685d5f11838f 348 {
mbed_official 235:685d5f11838f 349 case EP_TYPE_CTRL:
mbed_official 235:685d5f11838f 350 if((token == 1) && (direction == 0)) /*send data */
mbed_official 235:685d5f11838f 351 {
mbed_official 235:685d5f11838f 352 if ( length == 0 )
mbed_official 235:685d5f11838f 353 { /* For Status OUT stage, Length==0, Status Out PID = 1 */
mbed_official 235:685d5f11838f 354 hhcd->hc[ch_num].toggle_out = 1;
mbed_official 235:685d5f11838f 355 }
mbed_official 235:685d5f11838f 356
mbed_official 235:685d5f11838f 357 /* Set the Data Toggle bit as per the Flag */
mbed_official 235:685d5f11838f 358 if ( hhcd->hc[ch_num].toggle_out == 0)
mbed_official 235:685d5f11838f 359 { /* Put the PID 0 */
mbed_official 235:685d5f11838f 360 hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
mbed_official 235:685d5f11838f 361 }
mbed_official 235:685d5f11838f 362 else
mbed_official 235:685d5f11838f 363 { /* Put the PID 1 */
mbed_official 532:fe11edbda85c 364 hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
mbed_official 235:685d5f11838f 365 }
mbed_official 235:685d5f11838f 366 if(hhcd->hc[ch_num].urb_state != URB_NOTREADY)
mbed_official 235:685d5f11838f 367 {
mbed_official 235:685d5f11838f 368 hhcd->hc[ch_num].do_ping = do_ping;
mbed_official 235:685d5f11838f 369 }
mbed_official 235:685d5f11838f 370 }
mbed_official 235:685d5f11838f 371 break;
mbed_official 235:685d5f11838f 372
mbed_official 235:685d5f11838f 373 case EP_TYPE_BULK:
mbed_official 235:685d5f11838f 374 if(direction == 0)
mbed_official 235:685d5f11838f 375 {
mbed_official 235:685d5f11838f 376 /* Set the Data Toggle bit as per the Flag */
mbed_official 235:685d5f11838f 377 if ( hhcd->hc[ch_num].toggle_out == 0)
mbed_official 235:685d5f11838f 378 { /* Put the PID 0 */
mbed_official 235:685d5f11838f 379 hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
mbed_official 235:685d5f11838f 380 }
mbed_official 235:685d5f11838f 381 else
mbed_official 235:685d5f11838f 382 { /* Put the PID 1 */
mbed_official 532:fe11edbda85c 383 hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
mbed_official 235:685d5f11838f 384 }
mbed_official 235:685d5f11838f 385 if(hhcd->hc[ch_num].urb_state != URB_NOTREADY)
mbed_official 235:685d5f11838f 386 {
mbed_official 235:685d5f11838f 387 hhcd->hc[ch_num].do_ping = do_ping;
mbed_official 235:685d5f11838f 388 }
mbed_official 235:685d5f11838f 389 }
mbed_official 235:685d5f11838f 390 else
mbed_official 235:685d5f11838f 391 {
mbed_official 235:685d5f11838f 392 if( hhcd->hc[ch_num].toggle_in == 0)
mbed_official 235:685d5f11838f 393 {
mbed_official 235:685d5f11838f 394 hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
mbed_official 235:685d5f11838f 395 }
mbed_official 235:685d5f11838f 396 else
mbed_official 235:685d5f11838f 397 {
mbed_official 235:685d5f11838f 398 hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
mbed_official 235:685d5f11838f 399 }
mbed_official 235:685d5f11838f 400 }
mbed_official 235:685d5f11838f 401
mbed_official 235:685d5f11838f 402 break;
mbed_official 235:685d5f11838f 403 case EP_TYPE_INTR:
mbed_official 235:685d5f11838f 404 if(direction == 0)
mbed_official 235:685d5f11838f 405 {
mbed_official 235:685d5f11838f 406 /* Set the Data Toggle bit as per the Flag */
mbed_official 235:685d5f11838f 407 if ( hhcd->hc[ch_num].toggle_out == 0)
mbed_official 235:685d5f11838f 408 { /* Put the PID 0 */
mbed_official 235:685d5f11838f 409 hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
mbed_official 235:685d5f11838f 410 }
mbed_official 235:685d5f11838f 411 else
mbed_official 235:685d5f11838f 412 { /* Put the PID 1 */
mbed_official 532:fe11edbda85c 413 hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
mbed_official 235:685d5f11838f 414 }
mbed_official 235:685d5f11838f 415 }
mbed_official 235:685d5f11838f 416 else
mbed_official 235:685d5f11838f 417 {
mbed_official 235:685d5f11838f 418 if( hhcd->hc[ch_num].toggle_in == 0)
mbed_official 235:685d5f11838f 419 {
mbed_official 235:685d5f11838f 420 hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
mbed_official 235:685d5f11838f 421 }
mbed_official 235:685d5f11838f 422 else
mbed_official 235:685d5f11838f 423 {
mbed_official 235:685d5f11838f 424 hhcd->hc[ch_num].data_pid = HC_PID_DATA1;
mbed_official 235:685d5f11838f 425 }
mbed_official 235:685d5f11838f 426 }
mbed_official 235:685d5f11838f 427 break;
mbed_official 235:685d5f11838f 428
mbed_official 235:685d5f11838f 429 case EP_TYPE_ISOC:
mbed_official 235:685d5f11838f 430 hhcd->hc[ch_num].data_pid = HC_PID_DATA0;
mbed_official 532:fe11edbda85c 431 break;
mbed_official 235:685d5f11838f 432 }
mbed_official 235:685d5f11838f 433
mbed_official 235:685d5f11838f 434 hhcd->hc[ch_num].xfer_buff = pbuff;
mbed_official 235:685d5f11838f 435 hhcd->hc[ch_num].xfer_len = length;
mbed_official 235:685d5f11838f 436 hhcd->hc[ch_num].urb_state = URB_IDLE;
mbed_official 532:fe11edbda85c 437 hhcd->hc[ch_num].xfer_count = 0;
mbed_official 235:685d5f11838f 438 hhcd->hc[ch_num].ch_num = ch_num;
mbed_official 235:685d5f11838f 439 hhcd->hc[ch_num].state = HC_IDLE;
mbed_official 235:685d5f11838f 440
mbed_official 235:685d5f11838f 441 return USB_HC_StartXfer(hhcd->Instance, &(hhcd->hc[ch_num]), hhcd->Init.dma_enable);
mbed_official 235:685d5f11838f 442 }
mbed_official 235:685d5f11838f 443
mbed_official 235:685d5f11838f 444 /**
mbed_official 613:bc40b8d2aec4 445 * @brief Handle HCD interrupt request.
mbed_official 235:685d5f11838f 446 * @param hhcd: HCD handle
mbed_official 235:685d5f11838f 447 * @retval None
mbed_official 235:685d5f11838f 448 */
mbed_official 235:685d5f11838f 449 void HAL_HCD_IRQHandler(HCD_HandleTypeDef *hhcd)
mbed_official 235:685d5f11838f 450 {
mbed_official 235:685d5f11838f 451 USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
mbed_official 235:685d5f11838f 452 uint32_t i = 0 , interrupt = 0;
mbed_official 235:685d5f11838f 453
mbed_official 532:fe11edbda85c 454 /* Ensure that we are in device mode */
mbed_official 235:685d5f11838f 455 if (USB_GetMode(hhcd->Instance) == USB_OTG_MODE_HOST)
mbed_official 235:685d5f11838f 456 {
mbed_official 532:fe11edbda85c 457 /* Avoid spurious interrupt */
mbed_official 235:685d5f11838f 458 if(__HAL_HCD_IS_INVALID_INTERRUPT(hhcd))
mbed_official 235:685d5f11838f 459 {
mbed_official 235:685d5f11838f 460 return;
mbed_official 235:685d5f11838f 461 }
mbed_official 235:685d5f11838f 462
mbed_official 235:685d5f11838f 463 if(__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_PXFR_INCOMPISOOUT))
mbed_official 235:685d5f11838f 464 {
mbed_official 532:fe11edbda85c 465 /* Incorrect mode, acknowledge the interrupt */
mbed_official 235:685d5f11838f 466 __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_PXFR_INCOMPISOOUT);
mbed_official 235:685d5f11838f 467 }
mbed_official 235:685d5f11838f 468
mbed_official 235:685d5f11838f 469 if(__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_IISOIXFR))
mbed_official 235:685d5f11838f 470 {
mbed_official 532:fe11edbda85c 471 /* Incorrect mode, acknowledge the interrupt */
mbed_official 235:685d5f11838f 472 __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_IISOIXFR);
mbed_official 235:685d5f11838f 473 }
mbed_official 532:fe11edbda85c 474
mbed_official 235:685d5f11838f 475 if(__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_PTXFE))
mbed_official 235:685d5f11838f 476 {
mbed_official 532:fe11edbda85c 477 /* Incorrect mode, acknowledge the interrupt */
mbed_official 235:685d5f11838f 478 __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_PTXFE);
mbed_official 235:685d5f11838f 479 }
mbed_official 235:685d5f11838f 480
mbed_official 235:685d5f11838f 481 if(__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_MMIS))
mbed_official 235:685d5f11838f 482 {
mbed_official 532:fe11edbda85c 483 /* Incorrect mode, acknowledge the interrupt */
mbed_official 235:685d5f11838f 484 __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_MMIS);
mbed_official 235:685d5f11838f 485 }
mbed_official 235:685d5f11838f 486
mbed_official 235:685d5f11838f 487 /* Handle Host Disconnect Interrupts */
mbed_official 235:685d5f11838f 488 if(__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_DISCINT))
mbed_official 235:685d5f11838f 489 {
mbed_official 235:685d5f11838f 490
mbed_official 235:685d5f11838f 491 /* Cleanup HPRT */
mbed_official 235:685d5f11838f 492 USBx_HPRT0 &= ~(USB_OTG_HPRT_PENA | USB_OTG_HPRT_PCDET |\
mbed_official 235:685d5f11838f 493 USB_OTG_HPRT_PENCHNG | USB_OTG_HPRT_POCCHNG );
mbed_official 532:fe11edbda85c 494
mbed_official 235:685d5f11838f 495 /* Handle Host Port Interrupts */
mbed_official 235:685d5f11838f 496 HAL_HCD_Disconnect_Callback(hhcd);
mbed_official 532:fe11edbda85c 497 USB_InitFSLSPClkSel(hhcd->Instance ,HCFG_48_MHZ );
mbed_official 235:685d5f11838f 498 __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_DISCINT);
mbed_official 235:685d5f11838f 499 }
mbed_official 235:685d5f11838f 500
mbed_official 235:685d5f11838f 501 /* Handle Host Port Interrupts */
mbed_official 235:685d5f11838f 502 if(__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_HPRTINT))
mbed_official 235:685d5f11838f 503 {
mbed_official 235:685d5f11838f 504 HCD_Port_IRQHandler (hhcd);
mbed_official 235:685d5f11838f 505 }
mbed_official 235:685d5f11838f 506
mbed_official 235:685d5f11838f 507 /* Handle Host SOF Interrupts */
mbed_official 235:685d5f11838f 508 if(__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_SOF))
mbed_official 235:685d5f11838f 509 {
mbed_official 235:685d5f11838f 510 HAL_HCD_SOF_Callback(hhcd);
mbed_official 235:685d5f11838f 511 __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_SOF);
mbed_official 235:685d5f11838f 512 }
mbed_official 532:fe11edbda85c 513
mbed_official 235:685d5f11838f 514 /* Handle Host channel Interrupts */
mbed_official 235:685d5f11838f 515 if(__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_HCINT))
mbed_official 235:685d5f11838f 516 {
mbed_official 235:685d5f11838f 517 interrupt = USB_HC_ReadInterrupt(hhcd->Instance);
mbed_official 532:fe11edbda85c 518 for (i = 0; i < hhcd->Init.Host_channels; i++)
mbed_official 235:685d5f11838f 519 {
mbed_official 235:685d5f11838f 520 if (interrupt & (1 << i))
mbed_official 235:685d5f11838f 521 {
mbed_official 235:685d5f11838f 522 if ((USBx_HC(i)->HCCHAR) & USB_OTG_HCCHAR_EPDIR)
mbed_official 235:685d5f11838f 523 {
mbed_official 532:fe11edbda85c 524 HCD_HC_IN_IRQHandler(hhcd, i);
mbed_official 235:685d5f11838f 525 }
mbed_official 235:685d5f11838f 526 else
mbed_official 235:685d5f11838f 527 {
mbed_official 235:685d5f11838f 528 HCD_HC_OUT_IRQHandler (hhcd, i);
mbed_official 235:685d5f11838f 529 }
mbed_official 235:685d5f11838f 530 }
mbed_official 235:685d5f11838f 531 }
mbed_official 235:685d5f11838f 532 __HAL_HCD_CLEAR_FLAG(hhcd, USB_OTG_GINTSTS_HCINT);
mbed_official 235:685d5f11838f 533 }
mbed_official 235:685d5f11838f 534
mbed_official 532:fe11edbda85c 535 /* Handle Rx Queue Level Interrupts */
mbed_official 235:685d5f11838f 536 if(__HAL_HCD_GET_FLAG(hhcd, USB_OTG_GINTSTS_RXFLVL))
mbed_official 235:685d5f11838f 537 {
mbed_official 235:685d5f11838f 538 USB_MASK_INTERRUPT(hhcd->Instance, USB_OTG_GINTSTS_RXFLVL);
mbed_official 235:685d5f11838f 539
mbed_official 235:685d5f11838f 540 HCD_RXQLVL_IRQHandler (hhcd);
mbed_official 235:685d5f11838f 541
mbed_official 235:685d5f11838f 542 USB_UNMASK_INTERRUPT(hhcd->Instance, USB_OTG_GINTSTS_RXFLVL);
mbed_official 235:685d5f11838f 543 }
mbed_official 235:685d5f11838f 544 }
mbed_official 235:685d5f11838f 545 }
mbed_official 235:685d5f11838f 546
mbed_official 235:685d5f11838f 547 /**
mbed_official 235:685d5f11838f 548 * @brief SOF callback.
mbed_official 235:685d5f11838f 549 * @param hhcd: HCD handle
mbed_official 235:685d5f11838f 550 * @retval None
mbed_official 235:685d5f11838f 551 */
mbed_official 235:685d5f11838f 552 __weak void HAL_HCD_SOF_Callback(HCD_HandleTypeDef *hhcd)
mbed_official 235:685d5f11838f 553 {
mbed_official 235:685d5f11838f 554 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 532:fe11edbda85c 555 the HAL_HCD_SOF_Callback could be implemented in the user file
mbed_official 235:685d5f11838f 556 */
mbed_official 235:685d5f11838f 557 }
mbed_official 235:685d5f11838f 558
mbed_official 235:685d5f11838f 559 /**
mbed_official 613:bc40b8d2aec4 560 * @brief Connection Event callback.
mbed_official 235:685d5f11838f 561 * @param hhcd: HCD handle
mbed_official 235:685d5f11838f 562 * @retval None
mbed_official 235:685d5f11838f 563 */
mbed_official 235:685d5f11838f 564 __weak void HAL_HCD_Connect_Callback(HCD_HandleTypeDef *hhcd)
mbed_official 235:685d5f11838f 565 {
mbed_official 235:685d5f11838f 566 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 532:fe11edbda85c 567 the HAL_HCD_Connect_Callback could be implemented in the user file
mbed_official 235:685d5f11838f 568 */
mbed_official 235:685d5f11838f 569 }
mbed_official 235:685d5f11838f 570
mbed_official 235:685d5f11838f 571 /**
mbed_official 613:bc40b8d2aec4 572 * @brief Disconnection Event callback.
mbed_official 235:685d5f11838f 573 * @param hhcd: HCD handle
mbed_official 235:685d5f11838f 574 * @retval None
mbed_official 235:685d5f11838f 575 */
mbed_official 235:685d5f11838f 576 __weak void HAL_HCD_Disconnect_Callback(HCD_HandleTypeDef *hhcd)
mbed_official 235:685d5f11838f 577 {
mbed_official 235:685d5f11838f 578 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 532:fe11edbda85c 579 the HAL_HCD_Disconnect_Callback could be implemented in the user file
mbed_official 235:685d5f11838f 580 */
mbed_official 235:685d5f11838f 581 }
mbed_official 235:685d5f11838f 582
mbed_official 235:685d5f11838f 583 /**
mbed_official 235:685d5f11838f 584 * @brief Notify URB state change callback.
mbed_official 235:685d5f11838f 585 * @param hhcd: HCD handle
mbed_official 235:685d5f11838f 586 * @param chnum: Channel number.
mbed_official 235:685d5f11838f 587 * This parameter can be a value from 1 to 15
mbed_official 235:685d5f11838f 588 * @param urb_state:
mbed_official 235:685d5f11838f 589 * This parameter can be one of these values:
mbed_official 235:685d5f11838f 590 * URB_IDLE/
mbed_official 235:685d5f11838f 591 * URB_DONE/
mbed_official 235:685d5f11838f 592 * URB_NOTREADY/
mbed_official 235:685d5f11838f 593 * URB_NYET/
mbed_official 235:685d5f11838f 594 * URB_ERROR/
mbed_official 235:685d5f11838f 595 * URB_STALL/
mbed_official 235:685d5f11838f 596 * @retval None
mbed_official 235:685d5f11838f 597 */
mbed_official 235:685d5f11838f 598 __weak void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *hhcd, uint8_t chnum, HCD_URBStateTypeDef urb_state)
mbed_official 235:685d5f11838f 599 {
mbed_official 235:685d5f11838f 600 /* NOTE : This function Should not be modified, when the callback is needed,
mbed_official 532:fe11edbda85c 601 the HAL_HCD_HC_NotifyURBChange_Callback could be implemented in the user file
mbed_official 235:685d5f11838f 602 */
mbed_official 235:685d5f11838f 603 }
mbed_official 235:685d5f11838f 604
mbed_official 235:685d5f11838f 605 /**
mbed_official 235:685d5f11838f 606 * @}
mbed_official 235:685d5f11838f 607 */
mbed_official 235:685d5f11838f 608
mbed_official 613:bc40b8d2aec4 609 /** @defgroup HCD_Exported_Functions_Group3 Peripheral Control functions
mbed_official 613:bc40b8d2aec4 610 * @brief Management functions
mbed_official 235:685d5f11838f 611 *
mbed_official 532:fe11edbda85c 612 @verbatim
mbed_official 235:685d5f11838f 613 ===============================================================================
mbed_official 235:685d5f11838f 614 ##### Peripheral Control functions #####
mbed_official 235:685d5f11838f 615 ===============================================================================
mbed_official 235:685d5f11838f 616 [..]
mbed_official 235:685d5f11838f 617 This subsection provides a set of functions allowing to control the HCD data
mbed_official 235:685d5f11838f 618 transfers.
mbed_official 235:685d5f11838f 619
mbed_official 235:685d5f11838f 620 @endverbatim
mbed_official 235:685d5f11838f 621 * @{
mbed_official 235:685d5f11838f 622 */
mbed_official 235:685d5f11838f 623
mbed_official 235:685d5f11838f 624 /**
mbed_official 613:bc40b8d2aec4 625 * @brief Start the host driver.
mbed_official 235:685d5f11838f 626 * @param hhcd: HCD handle
mbed_official 235:685d5f11838f 627 * @retval HAL status
mbed_official 235:685d5f11838f 628 */
mbed_official 235:685d5f11838f 629 HAL_StatusTypeDef HAL_HCD_Start(HCD_HandleTypeDef *hhcd)
mbed_official 235:685d5f11838f 630 {
mbed_official 235:685d5f11838f 631 __HAL_LOCK(hhcd);
mbed_official 235:685d5f11838f 632 __HAL_HCD_ENABLE(hhcd);
mbed_official 235:685d5f11838f 633 USB_DriveVbus(hhcd->Instance, 1);
mbed_official 235:685d5f11838f 634 __HAL_UNLOCK(hhcd);
mbed_official 235:685d5f11838f 635 return HAL_OK;
mbed_official 235:685d5f11838f 636 }
mbed_official 235:685d5f11838f 637
mbed_official 235:685d5f11838f 638 /**
mbed_official 613:bc40b8d2aec4 639 * @brief Stop the host driver.
mbed_official 235:685d5f11838f 640 * @param hhcd: HCD handle
mbed_official 235:685d5f11838f 641 * @retval HAL status
mbed_official 235:685d5f11838f 642 */
mbed_official 235:685d5f11838f 643
mbed_official 235:685d5f11838f 644 HAL_StatusTypeDef HAL_HCD_Stop(HCD_HandleTypeDef *hhcd)
mbed_official 235:685d5f11838f 645 {
mbed_official 235:685d5f11838f 646 __HAL_LOCK(hhcd);
mbed_official 235:685d5f11838f 647 USB_StopHost(hhcd->Instance);
mbed_official 235:685d5f11838f 648 __HAL_UNLOCK(hhcd);
mbed_official 235:685d5f11838f 649 return HAL_OK;
mbed_official 235:685d5f11838f 650 }
mbed_official 235:685d5f11838f 651
mbed_official 235:685d5f11838f 652 /**
mbed_official 613:bc40b8d2aec4 653 * @brief Reset the host port.
mbed_official 235:685d5f11838f 654 * @param hhcd: HCD handle
mbed_official 235:685d5f11838f 655 * @retval HAL status
mbed_official 235:685d5f11838f 656 */
mbed_official 235:685d5f11838f 657 HAL_StatusTypeDef HAL_HCD_ResetPort(HCD_HandleTypeDef *hhcd)
mbed_official 235:685d5f11838f 658 {
mbed_official 235:685d5f11838f 659 return (USB_ResetPort(hhcd->Instance));
mbed_official 235:685d5f11838f 660 }
mbed_official 235:685d5f11838f 661
mbed_official 235:685d5f11838f 662 /**
mbed_official 235:685d5f11838f 663 * @}
mbed_official 235:685d5f11838f 664 */
mbed_official 235:685d5f11838f 665
mbed_official 613:bc40b8d2aec4 666 /** @defgroup HCD_Exported_Functions_Group4 Peripheral State functions
mbed_official 235:685d5f11838f 667 * @brief Peripheral State functions
mbed_official 235:685d5f11838f 668 *
mbed_official 532:fe11edbda85c 669 @verbatim
mbed_official 235:685d5f11838f 670 ===============================================================================
mbed_official 235:685d5f11838f 671 ##### Peripheral State functions #####
mbed_official 235:685d5f11838f 672 ===============================================================================
mbed_official 235:685d5f11838f 673 [..]
mbed_official 235:685d5f11838f 674 This subsection permits to get in run-time the status of the peripheral
mbed_official 235:685d5f11838f 675 and the data flow.
mbed_official 235:685d5f11838f 676
mbed_official 235:685d5f11838f 677 @endverbatim
mbed_official 235:685d5f11838f 678 * @{
mbed_official 235:685d5f11838f 679 */
mbed_official 235:685d5f11838f 680
mbed_official 235:685d5f11838f 681 /**
mbed_official 613:bc40b8d2aec4 682 * @brief Return the HCD handle state.
mbed_official 235:685d5f11838f 683 * @param hhcd: HCD handle
mbed_official 235:685d5f11838f 684 * @retval HAL state
mbed_official 235:685d5f11838f 685 */
mbed_official 235:685d5f11838f 686 HCD_StateTypeDef HAL_HCD_GetState(HCD_HandleTypeDef *hhcd)
mbed_official 235:685d5f11838f 687 {
mbed_official 235:685d5f11838f 688 return hhcd->State;
mbed_official 235:685d5f11838f 689 }
mbed_official 235:685d5f11838f 690
mbed_official 235:685d5f11838f 691 /**
mbed_official 613:bc40b8d2aec4 692 * @brief Return URB state for a channel.
mbed_official 235:685d5f11838f 693 * @param hhcd: HCD handle
mbed_official 235:685d5f11838f 694 * @param chnum: Channel number.
mbed_official 235:685d5f11838f 695 * This parameter can be a value from 1 to 15
mbed_official 235:685d5f11838f 696 * @retval URB state.
mbed_official 235:685d5f11838f 697 * This parameter can be one of these values:
mbed_official 235:685d5f11838f 698 * URB_IDLE/
mbed_official 235:685d5f11838f 699 * URB_DONE/
mbed_official 235:685d5f11838f 700 * URB_NOTREADY/
mbed_official 235:685d5f11838f 701 * URB_NYET/
mbed_official 235:685d5f11838f 702 * URB_ERROR/
mbed_official 613:bc40b8d2aec4 703 * URB_STALL
mbed_official 235:685d5f11838f 704 */
mbed_official 235:685d5f11838f 705 HCD_URBStateTypeDef HAL_HCD_HC_GetURBState(HCD_HandleTypeDef *hhcd, uint8_t chnum)
mbed_official 235:685d5f11838f 706 {
mbed_official 235:685d5f11838f 707 return hhcd->hc[chnum].urb_state;
mbed_official 235:685d5f11838f 708 }
mbed_official 235:685d5f11838f 709
mbed_official 235:685d5f11838f 710
mbed_official 235:685d5f11838f 711 /**
mbed_official 613:bc40b8d2aec4 712 * @brief Return the last host transfer size.
mbed_official 235:685d5f11838f 713 * @param hhcd: HCD handle
mbed_official 235:685d5f11838f 714 * @param chnum: Channel number.
mbed_official 235:685d5f11838f 715 * This parameter can be a value from 1 to 15
mbed_official 235:685d5f11838f 716 * @retval last transfer size in byte
mbed_official 235:685d5f11838f 717 */
mbed_official 235:685d5f11838f 718 uint32_t HAL_HCD_HC_GetXferCount(HCD_HandleTypeDef *hhcd, uint8_t chnum)
mbed_official 235:685d5f11838f 719 {
mbed_official 235:685d5f11838f 720 return hhcd->hc[chnum].xfer_count;
mbed_official 235:685d5f11838f 721 }
mbed_official 235:685d5f11838f 722
mbed_official 235:685d5f11838f 723 /**
mbed_official 613:bc40b8d2aec4 724 * @brief Return the Host Channel state.
mbed_official 235:685d5f11838f 725 * @param hhcd: HCD handle
mbed_official 235:685d5f11838f 726 * @param chnum: Channel number.
mbed_official 235:685d5f11838f 727 * This parameter can be a value from 1 to 15
mbed_official 235:685d5f11838f 728 * @retval Host channel state
mbed_official 613:bc40b8d2aec4 729 * This parameter can be one of these values:
mbed_official 235:685d5f11838f 730 * HC_IDLE/
mbed_official 235:685d5f11838f 731 * HC_XFRC/
mbed_official 235:685d5f11838f 732 * HC_HALTED/
mbed_official 235:685d5f11838f 733 * HC_NYET/
mbed_official 235:685d5f11838f 734 * HC_NAK/
mbed_official 235:685d5f11838f 735 * HC_STALL/
mbed_official 235:685d5f11838f 736 * HC_XACTERR/
mbed_official 235:685d5f11838f 737 * HC_BBLERR/
mbed_official 613:bc40b8d2aec4 738 * HC_DATATGLERR
mbed_official 235:685d5f11838f 739 */
mbed_official 235:685d5f11838f 740 HCD_HCStateTypeDef HAL_HCD_HC_GetState(HCD_HandleTypeDef *hhcd, uint8_t chnum)
mbed_official 235:685d5f11838f 741 {
mbed_official 235:685d5f11838f 742 return hhcd->hc[chnum].state;
mbed_official 235:685d5f11838f 743 }
mbed_official 235:685d5f11838f 744
mbed_official 235:685d5f11838f 745 /**
mbed_official 613:bc40b8d2aec4 746 * @brief Return the current Host frame number.
mbed_official 235:685d5f11838f 747 * @param hhcd: HCD handle
mbed_official 235:685d5f11838f 748 * @retval Current Host frame number
mbed_official 235:685d5f11838f 749 */
mbed_official 235:685d5f11838f 750 uint32_t HAL_HCD_GetCurrentFrame(HCD_HandleTypeDef *hhcd)
mbed_official 235:685d5f11838f 751 {
mbed_official 235:685d5f11838f 752 return (USB_GetCurrentFrame(hhcd->Instance));
mbed_official 235:685d5f11838f 753 }
mbed_official 235:685d5f11838f 754
mbed_official 235:685d5f11838f 755 /**
mbed_official 613:bc40b8d2aec4 756 * @brief Return the Host enumeration speed.
mbed_official 235:685d5f11838f 757 * @param hhcd: HCD handle
mbed_official 235:685d5f11838f 758 * @retval Enumeration speed
mbed_official 235:685d5f11838f 759 */
mbed_official 235:685d5f11838f 760 uint32_t HAL_HCD_GetCurrentSpeed(HCD_HandleTypeDef *hhcd)
mbed_official 235:685d5f11838f 761 {
mbed_official 235:685d5f11838f 762 return (USB_GetHostSpeed(hhcd->Instance));
mbed_official 235:685d5f11838f 763 }
mbed_official 613:bc40b8d2aec4 764
mbed_official 235:685d5f11838f 765 /**
mbed_official 235:685d5f11838f 766 * @}
mbed_official 235:685d5f11838f 767 */
mbed_official 235:685d5f11838f 768
mbed_official 235:685d5f11838f 769 /**
mbed_official 532:fe11edbda85c 770 * @}
mbed_official 532:fe11edbda85c 771 */
mbed_official 532:fe11edbda85c 772
mbed_official 532:fe11edbda85c 773 /** @addtogroup HCD_Private_Functions
mbed_official 532:fe11edbda85c 774 * @{
mbed_official 532:fe11edbda85c 775 */
mbed_official 532:fe11edbda85c 776 /**
mbed_official 613:bc40b8d2aec4 777 * @brief Handle Host Channel IN interrupt requests.
mbed_official 235:685d5f11838f 778 * @param hhcd: HCD handle
mbed_official 235:685d5f11838f 779 * @param chnum: Channel number.
mbed_official 235:685d5f11838f 780 * This parameter can be a value from 1 to 15
mbed_official 532:fe11edbda85c 781 * @retval None
mbed_official 235:685d5f11838f 782 */
mbed_official 532:fe11edbda85c 783 static void HCD_HC_IN_IRQHandler(HCD_HandleTypeDef *hhcd, uint8_t chnum)
mbed_official 235:685d5f11838f 784 {
mbed_official 235:685d5f11838f 785 USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
mbed_official 613:bc40b8d2aec4 786 uint32_t tmpreg = 0;
mbed_official 532:fe11edbda85c 787
mbed_official 235:685d5f11838f 788 if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_AHBERR)
mbed_official 235:685d5f11838f 789 {
mbed_official 235:685d5f11838f 790 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_AHBERR);
mbed_official 235:685d5f11838f 791 __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
mbed_official 235:685d5f11838f 792 }
mbed_official 235:685d5f11838f 793 else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_ACK)
mbed_official 235:685d5f11838f 794 {
mbed_official 235:685d5f11838f 795 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_ACK);
mbed_official 235:685d5f11838f 796 }
mbed_official 235:685d5f11838f 797
mbed_official 235:685d5f11838f 798 else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_STALL)
mbed_official 235:685d5f11838f 799 {
mbed_official 235:685d5f11838f 800 __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
mbed_official 235:685d5f11838f 801 hhcd->hc[chnum].state = HC_STALL;
mbed_official 235:685d5f11838f 802 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK);
mbed_official 235:685d5f11838f 803 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_STALL);
mbed_official 235:685d5f11838f 804 USB_HC_Halt(hhcd->Instance, chnum);
mbed_official 235:685d5f11838f 805 }
mbed_official 235:685d5f11838f 806 else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_DTERR)
mbed_official 235:685d5f11838f 807 {
mbed_official 235:685d5f11838f 808 __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
mbed_official 235:685d5f11838f 809 USB_HC_Halt(hhcd->Instance, chnum);
mbed_official 235:685d5f11838f 810 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK);
mbed_official 235:685d5f11838f 811 hhcd->hc[chnum].state = HC_DATATGLERR;
mbed_official 235:685d5f11838f 812 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_DTERR);
mbed_official 235:685d5f11838f 813 }
mbed_official 235:685d5f11838f 814
mbed_official 235:685d5f11838f 815 if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_FRMOR)
mbed_official 235:685d5f11838f 816 {
mbed_official 235:685d5f11838f 817 __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
mbed_official 235:685d5f11838f 818 USB_HC_Halt(hhcd->Instance, chnum);
mbed_official 235:685d5f11838f 819 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_FRMOR);
mbed_official 235:685d5f11838f 820 }
mbed_official 235:685d5f11838f 821
mbed_official 235:685d5f11838f 822 else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_XFRC)
mbed_official 235:685d5f11838f 823 {
mbed_official 235:685d5f11838f 824
mbed_official 235:685d5f11838f 825 if (hhcd->Init.dma_enable)
mbed_official 235:685d5f11838f 826 {
mbed_official 235:685d5f11838f 827 hhcd->hc[chnum].xfer_count = hhcd->hc[chnum].xfer_len - \
mbed_official 532:fe11edbda85c 828 (USBx_HC(chnum)->HCTSIZ & USB_OTG_HCTSIZ_XFRSIZ);
mbed_official 235:685d5f11838f 829 }
mbed_official 235:685d5f11838f 830
mbed_official 235:685d5f11838f 831 hhcd->hc[chnum].state = HC_XFRC;
mbed_official 235:685d5f11838f 832 hhcd->hc[chnum].ErrCnt = 0;
mbed_official 235:685d5f11838f 833 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_XFRC);
mbed_official 235:685d5f11838f 834
mbed_official 235:685d5f11838f 835
mbed_official 235:685d5f11838f 836 if ((hhcd->hc[chnum].ep_type == EP_TYPE_CTRL)||
mbed_official 235:685d5f11838f 837 (hhcd->hc[chnum].ep_type == EP_TYPE_BULK))
mbed_official 235:685d5f11838f 838 {
mbed_official 235:685d5f11838f 839 __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
mbed_official 235:685d5f11838f 840 USB_HC_Halt(hhcd->Instance, chnum);
mbed_official 235:685d5f11838f 841 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK);
mbed_official 235:685d5f11838f 842
mbed_official 235:685d5f11838f 843 }
mbed_official 235:685d5f11838f 844 else if(hhcd->hc[chnum].ep_type == EP_TYPE_INTR)
mbed_official 235:685d5f11838f 845 {
mbed_official 235:685d5f11838f 846 USBx_HC(chnum)->HCCHAR |= USB_OTG_HCCHAR_ODDFRM;
mbed_official 235:685d5f11838f 847 hhcd->hc[chnum].urb_state = URB_DONE;
mbed_official 235:685d5f11838f 848 HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state);
mbed_official 235:685d5f11838f 849 }
mbed_official 235:685d5f11838f 850 hhcd->hc[chnum].toggle_in ^= 1;
mbed_official 235:685d5f11838f 851
mbed_official 235:685d5f11838f 852 }
mbed_official 235:685d5f11838f 853 else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_CHH)
mbed_official 235:685d5f11838f 854 {
mbed_official 235:685d5f11838f 855 __HAL_HCD_MASK_HALT_HC_INT(chnum);
mbed_official 235:685d5f11838f 856
mbed_official 235:685d5f11838f 857 if(hhcd->hc[chnum].state == HC_XFRC)
mbed_official 235:685d5f11838f 858 {
mbed_official 235:685d5f11838f 859 hhcd->hc[chnum].urb_state = URB_DONE;
mbed_official 235:685d5f11838f 860 }
mbed_official 235:685d5f11838f 861
mbed_official 235:685d5f11838f 862 else if (hhcd->hc[chnum].state == HC_STALL)
mbed_official 235:685d5f11838f 863 {
mbed_official 235:685d5f11838f 864 hhcd->hc[chnum].urb_state = URB_STALL;
mbed_official 235:685d5f11838f 865 }
mbed_official 235:685d5f11838f 866
mbed_official 235:685d5f11838f 867 else if((hhcd->hc[chnum].state == HC_XACTERR) ||
mbed_official 235:685d5f11838f 868 (hhcd->hc[chnum].state == HC_DATATGLERR))
mbed_official 235:685d5f11838f 869 {
mbed_official 235:685d5f11838f 870 if(hhcd->hc[chnum].ErrCnt++ > 3)
mbed_official 235:685d5f11838f 871 {
mbed_official 235:685d5f11838f 872 hhcd->hc[chnum].ErrCnt = 0;
mbed_official 235:685d5f11838f 873 hhcd->hc[chnum].urb_state = URB_ERROR;
mbed_official 235:685d5f11838f 874 }
mbed_official 235:685d5f11838f 875 else
mbed_official 235:685d5f11838f 876 {
mbed_official 235:685d5f11838f 877 hhcd->hc[chnum].urb_state = URB_NOTREADY;
mbed_official 235:685d5f11838f 878 }
mbed_official 235:685d5f11838f 879
mbed_official 235:685d5f11838f 880 /* re-activate the channel */
mbed_official 613:bc40b8d2aec4 881 tmpreg = USBx_HC(chnum)->HCCHAR;
mbed_official 613:bc40b8d2aec4 882 tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
mbed_official 613:bc40b8d2aec4 883 tmpreg |= USB_OTG_HCCHAR_CHENA;
mbed_official 613:bc40b8d2aec4 884 USBx_HC(chnum)->HCCHAR = tmpreg;
mbed_official 235:685d5f11838f 885 }
mbed_official 235:685d5f11838f 886 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_CHH);
mbed_official 235:685d5f11838f 887 HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state);
mbed_official 235:685d5f11838f 888 }
mbed_official 235:685d5f11838f 889
mbed_official 235:685d5f11838f 890 else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_TXERR)
mbed_official 235:685d5f11838f 891 {
mbed_official 235:685d5f11838f 892 __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
mbed_official 532:fe11edbda85c 893 hhcd->hc[chnum].ErrCnt++;
mbed_official 532:fe11edbda85c 894 hhcd->hc[chnum].state = HC_XACTERR;
mbed_official 532:fe11edbda85c 895 USB_HC_Halt(hhcd->Instance, chnum);
mbed_official 532:fe11edbda85c 896 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_TXERR);
mbed_official 235:685d5f11838f 897 }
mbed_official 235:685d5f11838f 898 else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_NAK)
mbed_official 235:685d5f11838f 899 {
mbed_official 235:685d5f11838f 900 if(hhcd->hc[chnum].ep_type == EP_TYPE_INTR)
mbed_official 235:685d5f11838f 901 {
mbed_official 235:685d5f11838f 902 __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
mbed_official 235:685d5f11838f 903 USB_HC_Halt(hhcd->Instance, chnum);
mbed_official 235:685d5f11838f 904 }
mbed_official 235:685d5f11838f 905 else if ((hhcd->hc[chnum].ep_type == EP_TYPE_CTRL)||
mbed_official 235:685d5f11838f 906 (hhcd->hc[chnum].ep_type == EP_TYPE_BULK))
mbed_official 235:685d5f11838f 907 {
mbed_official 613:bc40b8d2aec4 908 /* re-activate the channel */
mbed_official 613:bc40b8d2aec4 909 tmpreg = USBx_HC(chnum)->HCCHAR;
mbed_official 613:bc40b8d2aec4 910 tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
mbed_official 613:bc40b8d2aec4 911 tmpreg |= USB_OTG_HCCHAR_CHENA;
mbed_official 613:bc40b8d2aec4 912 USBx_HC(chnum)->HCCHAR = tmpreg;
mbed_official 235:685d5f11838f 913 }
mbed_official 235:685d5f11838f 914 hhcd->hc[chnum].state = HC_NAK;
mbed_official 532:fe11edbda85c 915 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK);
mbed_official 235:685d5f11838f 916 }
mbed_official 235:685d5f11838f 917 }
mbed_official 235:685d5f11838f 918
mbed_official 235:685d5f11838f 919 /**
mbed_official 613:bc40b8d2aec4 920 * @brief Handle Host Channel OUT interrupt requests.
mbed_official 235:685d5f11838f 921 * @param hhcd: HCD handle
mbed_official 235:685d5f11838f 922 * @param chnum: Channel number.
mbed_official 235:685d5f11838f 923 * This parameter can be a value from 1 to 15
mbed_official 532:fe11edbda85c 924 * @retval None
mbed_official 235:685d5f11838f 925 */
mbed_official 235:685d5f11838f 926 static void HCD_HC_OUT_IRQHandler (HCD_HandleTypeDef *hhcd, uint8_t chnum)
mbed_official 235:685d5f11838f 927 {
mbed_official 235:685d5f11838f 928 USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
mbed_official 613:bc40b8d2aec4 929 uint32_t tmpreg = 0;
mbed_official 235:685d5f11838f 930
mbed_official 235:685d5f11838f 931 if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_AHBERR)
mbed_official 235:685d5f11838f 932 {
mbed_official 235:685d5f11838f 933 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_AHBERR);
mbed_official 235:685d5f11838f 934 __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
mbed_official 235:685d5f11838f 935 }
mbed_official 235:685d5f11838f 936 else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_ACK)
mbed_official 235:685d5f11838f 937 {
mbed_official 235:685d5f11838f 938 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_ACK);
mbed_official 235:685d5f11838f 939
mbed_official 235:685d5f11838f 940 if( hhcd->hc[chnum].do_ping == 1)
mbed_official 235:685d5f11838f 941 {
mbed_official 235:685d5f11838f 942 hhcd->hc[chnum].state = HC_NYET;
mbed_official 235:685d5f11838f 943 __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
mbed_official 235:685d5f11838f 944 USB_HC_Halt(hhcd->Instance, chnum);
mbed_official 235:685d5f11838f 945 hhcd->hc[chnum].urb_state = URB_NOTREADY;
mbed_official 235:685d5f11838f 946 }
mbed_official 235:685d5f11838f 947 }
mbed_official 235:685d5f11838f 948
mbed_official 235:685d5f11838f 949 else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_NYET)
mbed_official 235:685d5f11838f 950 {
mbed_official 235:685d5f11838f 951 hhcd->hc[chnum].state = HC_NYET;
mbed_official 235:685d5f11838f 952 hhcd->hc[chnum].ErrCnt= 0;
mbed_official 235:685d5f11838f 953 __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
mbed_official 235:685d5f11838f 954 USB_HC_Halt(hhcd->Instance, chnum);
mbed_official 235:685d5f11838f 955 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NYET);
mbed_official 235:685d5f11838f 956
mbed_official 235:685d5f11838f 957 }
mbed_official 235:685d5f11838f 958
mbed_official 235:685d5f11838f 959 else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_FRMOR)
mbed_official 235:685d5f11838f 960 {
mbed_official 235:685d5f11838f 961 __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
mbed_official 235:685d5f11838f 962 USB_HC_Halt(hhcd->Instance, chnum);
mbed_official 235:685d5f11838f 963 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_FRMOR);
mbed_official 235:685d5f11838f 964 }
mbed_official 235:685d5f11838f 965
mbed_official 235:685d5f11838f 966 else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_XFRC)
mbed_official 235:685d5f11838f 967 {
mbed_official 235:685d5f11838f 968 hhcd->hc[chnum].ErrCnt = 0;
mbed_official 235:685d5f11838f 969 __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
mbed_official 235:685d5f11838f 970 USB_HC_Halt(hhcd->Instance, chnum);
mbed_official 235:685d5f11838f 971 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_XFRC);
mbed_official 235:685d5f11838f 972 hhcd->hc[chnum].state = HC_XFRC;
mbed_official 235:685d5f11838f 973
mbed_official 235:685d5f11838f 974 }
mbed_official 235:685d5f11838f 975
mbed_official 235:685d5f11838f 976 else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_STALL)
mbed_official 235:685d5f11838f 977 {
mbed_official 235:685d5f11838f 978 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_STALL);
mbed_official 235:685d5f11838f 979 __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
mbed_official 235:685d5f11838f 980 USB_HC_Halt(hhcd->Instance, chnum);
mbed_official 235:685d5f11838f 981 hhcd->hc[chnum].state = HC_STALL;
mbed_official 235:685d5f11838f 982 }
mbed_official 235:685d5f11838f 983
mbed_official 235:685d5f11838f 984 else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_NAK)
mbed_official 235:685d5f11838f 985 {
mbed_official 235:685d5f11838f 986 hhcd->hc[chnum].ErrCnt = 0;
mbed_official 235:685d5f11838f 987 __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
mbed_official 235:685d5f11838f 988 USB_HC_Halt(hhcd->Instance, chnum);
mbed_official 235:685d5f11838f 989 hhcd->hc[chnum].state = HC_NAK;
mbed_official 235:685d5f11838f 990 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK);
mbed_official 235:685d5f11838f 991 }
mbed_official 235:685d5f11838f 992
mbed_official 235:685d5f11838f 993 else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_TXERR)
mbed_official 235:685d5f11838f 994 {
mbed_official 235:685d5f11838f 995 __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
mbed_official 235:685d5f11838f 996 USB_HC_Halt(hhcd->Instance, chnum);
mbed_official 235:685d5f11838f 997 hhcd->hc[chnum].state = HC_XACTERR;
mbed_official 235:685d5f11838f 998 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_TXERR);
mbed_official 235:685d5f11838f 999 }
mbed_official 235:685d5f11838f 1000
mbed_official 235:685d5f11838f 1001 else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_DTERR)
mbed_official 235:685d5f11838f 1002 {
mbed_official 235:685d5f11838f 1003 __HAL_HCD_UNMASK_HALT_HC_INT(chnum);
mbed_official 235:685d5f11838f 1004 USB_HC_Halt(hhcd->Instance, chnum);
mbed_official 235:685d5f11838f 1005 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_NAK);
mbed_official 235:685d5f11838f 1006 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_DTERR);
mbed_official 235:685d5f11838f 1007 hhcd->hc[chnum].state = HC_DATATGLERR;
mbed_official 235:685d5f11838f 1008 }
mbed_official 235:685d5f11838f 1009
mbed_official 235:685d5f11838f 1010
mbed_official 235:685d5f11838f 1011 else if ((USBx_HC(chnum)->HCINT) & USB_OTG_HCINT_CHH)
mbed_official 235:685d5f11838f 1012 {
mbed_official 235:685d5f11838f 1013 __HAL_HCD_MASK_HALT_HC_INT(chnum);
mbed_official 235:685d5f11838f 1014
mbed_official 235:685d5f11838f 1015 if(hhcd->hc[chnum].state == HC_XFRC)
mbed_official 235:685d5f11838f 1016 {
mbed_official 235:685d5f11838f 1017 hhcd->hc[chnum].urb_state = URB_DONE;
mbed_official 235:685d5f11838f 1018 if (hhcd->hc[chnum].ep_type == EP_TYPE_BULK)
mbed_official 235:685d5f11838f 1019 {
mbed_official 235:685d5f11838f 1020 hhcd->hc[chnum].toggle_out ^= 1;
mbed_official 235:685d5f11838f 1021 }
mbed_official 235:685d5f11838f 1022 }
mbed_official 235:685d5f11838f 1023 else if (hhcd->hc[chnum].state == HC_NAK)
mbed_official 235:685d5f11838f 1024 {
mbed_official 235:685d5f11838f 1025 hhcd->hc[chnum].urb_state = URB_NOTREADY;
mbed_official 235:685d5f11838f 1026 }
mbed_official 235:685d5f11838f 1027
mbed_official 235:685d5f11838f 1028 else if (hhcd->hc[chnum].state == HC_NYET)
mbed_official 235:685d5f11838f 1029 {
mbed_official 235:685d5f11838f 1030 hhcd->hc[chnum].urb_state = URB_NOTREADY;
mbed_official 235:685d5f11838f 1031 hhcd->hc[chnum].do_ping = 0;
mbed_official 235:685d5f11838f 1032 }
mbed_official 235:685d5f11838f 1033
mbed_official 235:685d5f11838f 1034 else if (hhcd->hc[chnum].state == HC_STALL)
mbed_official 235:685d5f11838f 1035 {
mbed_official 235:685d5f11838f 1036 hhcd->hc[chnum].urb_state = URB_STALL;
mbed_official 235:685d5f11838f 1037 }
mbed_official 235:685d5f11838f 1038
mbed_official 235:685d5f11838f 1039 else if((hhcd->hc[chnum].state == HC_XACTERR) ||
mbed_official 235:685d5f11838f 1040 (hhcd->hc[chnum].state == HC_DATATGLERR))
mbed_official 235:685d5f11838f 1041 {
mbed_official 235:685d5f11838f 1042 if(hhcd->hc[chnum].ErrCnt++ > 3)
mbed_official 235:685d5f11838f 1043 {
mbed_official 235:685d5f11838f 1044 hhcd->hc[chnum].ErrCnt = 0;
mbed_official 235:685d5f11838f 1045 hhcd->hc[chnum].urb_state = URB_ERROR;
mbed_official 235:685d5f11838f 1046 }
mbed_official 235:685d5f11838f 1047 else
mbed_official 235:685d5f11838f 1048 {
mbed_official 235:685d5f11838f 1049 hhcd->hc[chnum].urb_state = URB_NOTREADY;
mbed_official 235:685d5f11838f 1050 }
mbed_official 235:685d5f11838f 1051
mbed_official 235:685d5f11838f 1052 /* re-activate the channel */
mbed_official 613:bc40b8d2aec4 1053 tmpreg = USBx_HC(chnum)->HCCHAR;
mbed_official 613:bc40b8d2aec4 1054 tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
mbed_official 613:bc40b8d2aec4 1055 tmpreg |= USB_OTG_HCCHAR_CHENA;
mbed_official 613:bc40b8d2aec4 1056 USBx_HC(chnum)->HCCHAR = tmpreg;
mbed_official 235:685d5f11838f 1057 }
mbed_official 235:685d5f11838f 1058
mbed_official 235:685d5f11838f 1059 __HAL_HCD_CLEAR_HC_INT(chnum, USB_OTG_HCINT_CHH);
mbed_official 235:685d5f11838f 1060 HAL_HCD_HC_NotifyURBChange_Callback(hhcd, chnum, hhcd->hc[chnum].urb_state);
mbed_official 235:685d5f11838f 1061 }
mbed_official 235:685d5f11838f 1062 }
mbed_official 235:685d5f11838f 1063
mbed_official 235:685d5f11838f 1064 /**
mbed_official 613:bc40b8d2aec4 1065 * @brief Handle Rx Queue Level interrupt requests.
mbed_official 235:685d5f11838f 1066 * @param hhcd: HCD handle
mbed_official 532:fe11edbda85c 1067 * @retval None
mbed_official 235:685d5f11838f 1068 */
mbed_official 532:fe11edbda85c 1069 static void HCD_RXQLVL_IRQHandler(HCD_HandleTypeDef *hhcd)
mbed_official 235:685d5f11838f 1070 {
mbed_official 235:685d5f11838f 1071 USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
mbed_official 532:fe11edbda85c 1072 uint8_t channelnum = 0;
mbed_official 532:fe11edbda85c 1073 uint32_t pktsts;
mbed_official 532:fe11edbda85c 1074 uint32_t pktcnt;
mbed_official 532:fe11edbda85c 1075 uint32_t temp = 0;
mbed_official 613:bc40b8d2aec4 1076 uint32_t tmpreg = 0;
mbed_official 235:685d5f11838f 1077
mbed_official 532:fe11edbda85c 1078 temp = hhcd->Instance->GRXSTSP;
mbed_official 235:685d5f11838f 1079 channelnum = temp & USB_OTG_GRXSTSP_EPNUM;
mbed_official 235:685d5f11838f 1080 pktsts = (temp & USB_OTG_GRXSTSP_PKTSTS) >> 17;
mbed_official 235:685d5f11838f 1081 pktcnt = (temp & USB_OTG_GRXSTSP_BCNT) >> 4;
mbed_official 532:fe11edbda85c 1082
mbed_official 235:685d5f11838f 1083 switch (pktsts)
mbed_official 235:685d5f11838f 1084 {
mbed_official 235:685d5f11838f 1085 case GRXSTS_PKTSTS_IN:
mbed_official 235:685d5f11838f 1086 /* Read the data into the host buffer. */
mbed_official 235:685d5f11838f 1087 if ((pktcnt > 0) && (hhcd->hc[channelnum].xfer_buff != (void *)0))
mbed_official 235:685d5f11838f 1088 {
mbed_official 235:685d5f11838f 1089
mbed_official 235:685d5f11838f 1090 USB_ReadPacket(hhcd->Instance, hhcd->hc[channelnum].xfer_buff, pktcnt);
mbed_official 532:fe11edbda85c 1091
mbed_official 235:685d5f11838f 1092 /*manage multiple Xfer */
mbed_official 235:685d5f11838f 1093 hhcd->hc[channelnum].xfer_buff += pktcnt;
mbed_official 235:685d5f11838f 1094 hhcd->hc[channelnum].xfer_count += pktcnt;
mbed_official 532:fe11edbda85c 1095
mbed_official 235:685d5f11838f 1096 if((USBx_HC(channelnum)->HCTSIZ & USB_OTG_HCTSIZ_PKTCNT) > 0)
mbed_official 235:685d5f11838f 1097 {
mbed_official 235:685d5f11838f 1098 /* re-activate the channel when more packets are expected */
mbed_official 613:bc40b8d2aec4 1099 tmpreg = USBx_HC(channelnum)->HCCHAR;
mbed_official 613:bc40b8d2aec4 1100 tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
mbed_official 613:bc40b8d2aec4 1101 tmpreg |= USB_OTG_HCCHAR_CHENA;
mbed_official 613:bc40b8d2aec4 1102 USBx_HC(channelnum)->HCCHAR = tmpreg;
mbed_official 235:685d5f11838f 1103 hhcd->hc[channelnum].toggle_in ^= 1;
mbed_official 235:685d5f11838f 1104 }
mbed_official 235:685d5f11838f 1105 }
mbed_official 235:685d5f11838f 1106 break;
mbed_official 532:fe11edbda85c 1107
mbed_official 235:685d5f11838f 1108 case GRXSTS_PKTSTS_DATA_TOGGLE_ERR:
mbed_official 235:685d5f11838f 1109 break;
mbed_official 235:685d5f11838f 1110 case GRXSTS_PKTSTS_IN_XFER_COMP:
mbed_official 235:685d5f11838f 1111 case GRXSTS_PKTSTS_CH_HALTED:
mbed_official 235:685d5f11838f 1112 default:
mbed_official 235:685d5f11838f 1113 break;
mbed_official 235:685d5f11838f 1114 }
mbed_official 235:685d5f11838f 1115 }
mbed_official 235:685d5f11838f 1116
mbed_official 235:685d5f11838f 1117 /**
mbed_official 613:bc40b8d2aec4 1118 * @brief Handle Host Port interrupt requests.
mbed_official 235:685d5f11838f 1119 * @param hhcd: HCD handle
mbed_official 235:685d5f11838f 1120 * @retval None
mbed_official 235:685d5f11838f 1121 */
mbed_official 235:685d5f11838f 1122 static void HCD_Port_IRQHandler (HCD_HandleTypeDef *hhcd)
mbed_official 235:685d5f11838f 1123 {
mbed_official 235:685d5f11838f 1124 USB_OTG_GlobalTypeDef *USBx = hhcd->Instance;
mbed_official 235:685d5f11838f 1125 __IO uint32_t hprt0, hprt0_dup;
mbed_official 235:685d5f11838f 1126
mbed_official 235:685d5f11838f 1127 /* Handle Host Port Interrupts */
mbed_official 235:685d5f11838f 1128 hprt0 = USBx_HPRT0;
mbed_official 235:685d5f11838f 1129 hprt0_dup = USBx_HPRT0;
mbed_official 235:685d5f11838f 1130
mbed_official 235:685d5f11838f 1131 hprt0_dup &= ~(USB_OTG_HPRT_PENA | USB_OTG_HPRT_PCDET |\
mbed_official 235:685d5f11838f 1132 USB_OTG_HPRT_PENCHNG | USB_OTG_HPRT_POCCHNG );
mbed_official 235:685d5f11838f 1133
mbed_official 532:fe11edbda85c 1134 /* Check whether Port Connect Detected */
mbed_official 235:685d5f11838f 1135 if((hprt0 & USB_OTG_HPRT_PCDET) == USB_OTG_HPRT_PCDET)
mbed_official 235:685d5f11838f 1136 {
mbed_official 235:685d5f11838f 1137 if((hprt0 & USB_OTG_HPRT_PCSTS) == USB_OTG_HPRT_PCSTS)
mbed_official 235:685d5f11838f 1138 {
mbed_official 235:685d5f11838f 1139 USB_MASK_INTERRUPT(hhcd->Instance, USB_OTG_GINTSTS_DISCINT);
mbed_official 235:685d5f11838f 1140 HAL_HCD_Connect_Callback(hhcd);
mbed_official 235:685d5f11838f 1141 }
mbed_official 235:685d5f11838f 1142 hprt0_dup |= USB_OTG_HPRT_PCDET;
mbed_official 235:685d5f11838f 1143
mbed_official 235:685d5f11838f 1144 }
mbed_official 235:685d5f11838f 1145
mbed_official 235:685d5f11838f 1146 /* Check whether Port Enable Changed */
mbed_official 235:685d5f11838f 1147 if((hprt0 & USB_OTG_HPRT_PENCHNG) == USB_OTG_HPRT_PENCHNG)
mbed_official 235:685d5f11838f 1148 {
mbed_official 235:685d5f11838f 1149 hprt0_dup |= USB_OTG_HPRT_PENCHNG;
mbed_official 235:685d5f11838f 1150
mbed_official 235:685d5f11838f 1151 if((hprt0 & USB_OTG_HPRT_PENA) == USB_OTG_HPRT_PENA)
mbed_official 235:685d5f11838f 1152 {
mbed_official 235:685d5f11838f 1153 if(hhcd->Init.phy_itface == USB_OTG_EMBEDDED_PHY)
mbed_official 235:685d5f11838f 1154 {
mbed_official 235:685d5f11838f 1155 if ((hprt0 & USB_OTG_HPRT_PSPD) == (HPRT0_PRTSPD_LOW_SPEED << 17))
mbed_official 235:685d5f11838f 1156 {
mbed_official 235:685d5f11838f 1157 USB_InitFSLSPClkSel(hhcd->Instance ,HCFG_6_MHZ );
mbed_official 235:685d5f11838f 1158 }
mbed_official 235:685d5f11838f 1159 else
mbed_official 235:685d5f11838f 1160 {
mbed_official 235:685d5f11838f 1161 USB_InitFSLSPClkSel(hhcd->Instance ,HCFG_48_MHZ );
mbed_official 235:685d5f11838f 1162 }
mbed_official 235:685d5f11838f 1163 }
mbed_official 235:685d5f11838f 1164 else
mbed_official 235:685d5f11838f 1165 {
mbed_official 235:685d5f11838f 1166 if(hhcd->Init.speed == HCD_SPEED_FULL)
mbed_official 235:685d5f11838f 1167 {
mbed_official 235:685d5f11838f 1168 USBx_HOST->HFIR = (uint32_t)60000;
mbed_official 235:685d5f11838f 1169 }
mbed_official 235:685d5f11838f 1170 }
mbed_official 235:685d5f11838f 1171 HAL_HCD_Connect_Callback(hhcd);
mbed_official 235:685d5f11838f 1172
mbed_official 235:685d5f11838f 1173 if(hhcd->Init.speed == HCD_SPEED_HIGH)
mbed_official 235:685d5f11838f 1174 {
mbed_official 235:685d5f11838f 1175 USB_UNMASK_INTERRUPT(hhcd->Instance, USB_OTG_GINTSTS_DISCINT);
mbed_official 235:685d5f11838f 1176 }
mbed_official 235:685d5f11838f 1177 }
mbed_official 235:685d5f11838f 1178 else
mbed_official 235:685d5f11838f 1179 {
mbed_official 235:685d5f11838f 1180 /* Cleanup HPRT */
mbed_official 235:685d5f11838f 1181 USBx_HPRT0 &= ~(USB_OTG_HPRT_PENA | USB_OTG_HPRT_PCDET |\
mbed_official 235:685d5f11838f 1182 USB_OTG_HPRT_PENCHNG | USB_OTG_HPRT_POCCHNG );
mbed_official 235:685d5f11838f 1183
mbed_official 235:685d5f11838f 1184 USB_UNMASK_INTERRUPT(hhcd->Instance, USB_OTG_GINTSTS_DISCINT);
mbed_official 235:685d5f11838f 1185 }
mbed_official 235:685d5f11838f 1186 }
mbed_official 235:685d5f11838f 1187
mbed_official 532:fe11edbda85c 1188 /* Check for an overcurrent */
mbed_official 235:685d5f11838f 1189 if((hprt0 & USB_OTG_HPRT_POCCHNG) == USB_OTG_HPRT_POCCHNG)
mbed_official 235:685d5f11838f 1190 {
mbed_official 235:685d5f11838f 1191 hprt0_dup |= USB_OTG_HPRT_POCCHNG;
mbed_official 235:685d5f11838f 1192 }
mbed_official 235:685d5f11838f 1193
mbed_official 235:685d5f11838f 1194 /* Clear Port Interrupts */
mbed_official 235:685d5f11838f 1195 USBx_HPRT0 = hprt0_dup;
mbed_official 235:685d5f11838f 1196 }
mbed_official 235:685d5f11838f 1197
mbed_official 235:685d5f11838f 1198 /**
mbed_official 235:685d5f11838f 1199 * @}
mbed_official 235:685d5f11838f 1200 */
mbed_official 235:685d5f11838f 1201
mbed_official 613:bc40b8d2aec4 1202 /**
mbed_official 613:bc40b8d2aec4 1203 * @}
mbed_official 613:bc40b8d2aec4 1204 */
mbed_official 613:bc40b8d2aec4 1205
mbed_official 235:685d5f11838f 1206 #endif /* HAL_HCD_MODULE_ENABLED */
mbed_official 235:685d5f11838f 1207 /**
mbed_official 235:685d5f11838f 1208 * @}
mbed_official 235:685d5f11838f 1209 */
mbed_official 235:685d5f11838f 1210
mbed_official 235:685d5f11838f 1211 /**
mbed_official 235:685d5f11838f 1212 * @}
mbed_official 235:685d5f11838f 1213 */
mbed_official 235:685d5f11838f 1214
mbed_official 235:685d5f11838f 1215 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/