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