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