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