mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

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

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

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

Import librarymbed

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

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

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

DISCO_F746NG - Improvements

Who changed what in which revision?

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