Mouse code for the MacroRat
mbed-dev/targets/TARGET_STM/TARGET_STM32F4/device/stm32f4xx_hal_pcd.c@18:6a4db94011d3, 2017-05-14 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sun May 14 23:18:57 2017 +0000
- Revision:
- 18:6a4db94011d3
Publishing again
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | /** |
sahilmgandhi | 18:6a4db94011d3 | 2 | ****************************************************************************** |
sahilmgandhi | 18:6a4db94011d3 | 3 | * @file stm32f4xx_hal_pcd.c |
sahilmgandhi | 18:6a4db94011d3 | 4 | * @author MCD Application Team |
sahilmgandhi | 18:6a4db94011d3 | 5 | * @version V1.5.0 |
sahilmgandhi | 18:6a4db94011d3 | 6 | * @date 06-May-2016 |
sahilmgandhi | 18:6a4db94011d3 | 7 | * @brief PCD HAL module driver. |
sahilmgandhi | 18:6a4db94011d3 | 8 | * This file provides firmware functions to manage the following |
sahilmgandhi | 18:6a4db94011d3 | 9 | * functionalities of the USB Peripheral Controller: |
sahilmgandhi | 18:6a4db94011d3 | 10 | * + Initialization and de-initialization functions |
sahilmgandhi | 18:6a4db94011d3 | 11 | * + IO operation functions |
sahilmgandhi | 18:6a4db94011d3 | 12 | * + Peripheral Control functions |
sahilmgandhi | 18:6a4db94011d3 | 13 | * + Peripheral State functions |
sahilmgandhi | 18:6a4db94011d3 | 14 | * |
sahilmgandhi | 18:6a4db94011d3 | 15 | @verbatim |
sahilmgandhi | 18:6a4db94011d3 | 16 | ============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 17 | ##### How to use this driver ##### |
sahilmgandhi | 18:6a4db94011d3 | 18 | ============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 19 | [..] |
sahilmgandhi | 18:6a4db94011d3 | 20 | The PCD HAL driver can be used as follows: |
sahilmgandhi | 18:6a4db94011d3 | 21 | |
sahilmgandhi | 18:6a4db94011d3 | 22 | (#) Declare a PCD_HandleTypeDef handle structure, for example: |
sahilmgandhi | 18:6a4db94011d3 | 23 | PCD_HandleTypeDef hpcd; |
sahilmgandhi | 18:6a4db94011d3 | 24 | |
sahilmgandhi | 18:6a4db94011d3 | 25 | (#) Fill parameters of Init structure in HCD handle |
sahilmgandhi | 18:6a4db94011d3 | 26 | |
sahilmgandhi | 18:6a4db94011d3 | 27 | (#) Call HAL_PCD_Init() API to initialize the PCD peripheral (Core, Device core, ...) |
sahilmgandhi | 18:6a4db94011d3 | 28 | |
sahilmgandhi | 18:6a4db94011d3 | 29 | (#) Initialize the PCD low level resources through the HAL_PCD_MspInit() API: |
sahilmgandhi | 18:6a4db94011d3 | 30 | (##) Enable the PCD/USB Low Level interface clock using |
sahilmgandhi | 18:6a4db94011d3 | 31 | (+++) __HAL_RCC_USB_OTG_FS_CLK_ENABLE(); |
sahilmgandhi | 18:6a4db94011d3 | 32 | (+++) __HAL_RCC_USB_OTG_HS_CLK_ENABLE(); (For High Speed Mode) |
sahilmgandhi | 18:6a4db94011d3 | 33 | |
sahilmgandhi | 18:6a4db94011d3 | 34 | (##) Initialize the related GPIO clocks |
sahilmgandhi | 18:6a4db94011d3 | 35 | (##) Configure PCD pin-out |
sahilmgandhi | 18:6a4db94011d3 | 36 | (##) Configure PCD NVIC interrupt |
sahilmgandhi | 18:6a4db94011d3 | 37 | |
sahilmgandhi | 18:6a4db94011d3 | 38 | (#)Associate the Upper USB device stack to the HAL PCD Driver: |
sahilmgandhi | 18:6a4db94011d3 | 39 | (##) hpcd.pData = pdev; |
sahilmgandhi | 18:6a4db94011d3 | 40 | |
sahilmgandhi | 18:6a4db94011d3 | 41 | (#)Enable PCD transmission and reception: |
sahilmgandhi | 18:6a4db94011d3 | 42 | (##) HAL_PCD_Start(); |
sahilmgandhi | 18:6a4db94011d3 | 43 | |
sahilmgandhi | 18:6a4db94011d3 | 44 | @endverbatim |
sahilmgandhi | 18:6a4db94011d3 | 45 | ****************************************************************************** |
sahilmgandhi | 18:6a4db94011d3 | 46 | * @attention |
sahilmgandhi | 18:6a4db94011d3 | 47 | * |
sahilmgandhi | 18:6a4db94011d3 | 48 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
sahilmgandhi | 18:6a4db94011d3 | 49 | * |
sahilmgandhi | 18:6a4db94011d3 | 50 | * Redistribution and use in source and binary forms, with or without modification, |
sahilmgandhi | 18:6a4db94011d3 | 51 | * are permitted provided that the following conditions are met: |
sahilmgandhi | 18:6a4db94011d3 | 52 | * 1. Redistributions of source code must retain the above copyright notice, |
sahilmgandhi | 18:6a4db94011d3 | 53 | * this list of conditions and the following disclaimer. |
sahilmgandhi | 18:6a4db94011d3 | 54 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
sahilmgandhi | 18:6a4db94011d3 | 55 | * this list of conditions and the following disclaimer in the documentation |
sahilmgandhi | 18:6a4db94011d3 | 56 | * and/or other materials provided with the distribution. |
sahilmgandhi | 18:6a4db94011d3 | 57 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
sahilmgandhi | 18:6a4db94011d3 | 58 | * may be used to endorse or promote products derived from this software |
sahilmgandhi | 18:6a4db94011d3 | 59 | * without specific prior written permission. |
sahilmgandhi | 18:6a4db94011d3 | 60 | * |
sahilmgandhi | 18:6a4db94011d3 | 61 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
sahilmgandhi | 18:6a4db94011d3 | 62 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
sahilmgandhi | 18:6a4db94011d3 | 63 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
sahilmgandhi | 18:6a4db94011d3 | 64 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
sahilmgandhi | 18:6a4db94011d3 | 65 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
sahilmgandhi | 18:6a4db94011d3 | 66 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
sahilmgandhi | 18:6a4db94011d3 | 67 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
sahilmgandhi | 18:6a4db94011d3 | 68 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
sahilmgandhi | 18:6a4db94011d3 | 69 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
sahilmgandhi | 18:6a4db94011d3 | 70 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
sahilmgandhi | 18:6a4db94011d3 | 71 | * |
sahilmgandhi | 18:6a4db94011d3 | 72 | ****************************************************************************** |
sahilmgandhi | 18:6a4db94011d3 | 73 | */ |
sahilmgandhi | 18:6a4db94011d3 | 74 | |
sahilmgandhi | 18:6a4db94011d3 | 75 | /* Includes ------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 76 | #include "stm32f4xx_hal.h" |
sahilmgandhi | 18:6a4db94011d3 | 77 | |
sahilmgandhi | 18:6a4db94011d3 | 78 | /** @addtogroup STM32F4xx_HAL_Driver |
sahilmgandhi | 18:6a4db94011d3 | 79 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 80 | */ |
sahilmgandhi | 18:6a4db94011d3 | 81 | |
sahilmgandhi | 18:6a4db94011d3 | 82 | /** @defgroup PCD PCD |
sahilmgandhi | 18:6a4db94011d3 | 83 | * @brief PCD HAL module driver |
sahilmgandhi | 18:6a4db94011d3 | 84 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 85 | */ |
sahilmgandhi | 18:6a4db94011d3 | 86 | |
sahilmgandhi | 18:6a4db94011d3 | 87 | #ifdef HAL_PCD_MODULE_ENABLED |
sahilmgandhi | 18:6a4db94011d3 | 88 | #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) || \ |
sahilmgandhi | 18:6a4db94011d3 | 89 | defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || \ |
sahilmgandhi | 18:6a4db94011d3 | 90 | defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE) || defined(STM32F446xx) || \ |
sahilmgandhi | 18:6a4db94011d3 | 91 | defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \ |
sahilmgandhi | 18:6a4db94011d3 | 92 | defined(STM32F412Rx) || defined(STM32F412Cx) |
sahilmgandhi | 18:6a4db94011d3 | 93 | /* Private types -------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 94 | /* Private variables ---------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 95 | /* Private constants ---------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 96 | /* Private macros ------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 97 | /** @defgroup PCD_Private_Macros PCD Private Macros |
sahilmgandhi | 18:6a4db94011d3 | 98 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 99 | */ |
sahilmgandhi | 18:6a4db94011d3 | 100 | #define PCD_MIN(a, b) (((a) < (b)) ? (a) : (b)) |
sahilmgandhi | 18:6a4db94011d3 | 101 | #define PCD_MAX(a, b) (((a) > (b)) ? (a) : (b)) |
sahilmgandhi | 18:6a4db94011d3 | 102 | /** |
sahilmgandhi | 18:6a4db94011d3 | 103 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 104 | */ |
sahilmgandhi | 18:6a4db94011d3 | 105 | |
sahilmgandhi | 18:6a4db94011d3 | 106 | /* Private functions prototypes ----------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 107 | /** @defgroup PCD_Private_Functions PCD Private Functions |
sahilmgandhi | 18:6a4db94011d3 | 108 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 109 | */ |
sahilmgandhi | 18:6a4db94011d3 | 110 | static HAL_StatusTypeDef PCD_WriteEmptyTxFifo(PCD_HandleTypeDef *hpcd, uint32_t epnum); |
sahilmgandhi | 18:6a4db94011d3 | 111 | /** |
sahilmgandhi | 18:6a4db94011d3 | 112 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 113 | */ |
sahilmgandhi | 18:6a4db94011d3 | 114 | |
sahilmgandhi | 18:6a4db94011d3 | 115 | /* Exported functions --------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 116 | /** @defgroup PCD_Exported_Functions PCD Exported Functions |
sahilmgandhi | 18:6a4db94011d3 | 117 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 118 | */ |
sahilmgandhi | 18:6a4db94011d3 | 119 | |
sahilmgandhi | 18:6a4db94011d3 | 120 | /** @defgroup PCD_Exported_Functions_Group1 Initialization and de-initialization functions |
sahilmgandhi | 18:6a4db94011d3 | 121 | * @brief Initialization and Configuration functions |
sahilmgandhi | 18:6a4db94011d3 | 122 | * |
sahilmgandhi | 18:6a4db94011d3 | 123 | @verbatim |
sahilmgandhi | 18:6a4db94011d3 | 124 | =============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 125 | ##### Initialization and de-initialization functions ##### |
sahilmgandhi | 18:6a4db94011d3 | 126 | =============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 127 | [..] This section provides functions allowing to: |
sahilmgandhi | 18:6a4db94011d3 | 128 | |
sahilmgandhi | 18:6a4db94011d3 | 129 | @endverbatim |
sahilmgandhi | 18:6a4db94011d3 | 130 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 131 | */ |
sahilmgandhi | 18:6a4db94011d3 | 132 | |
sahilmgandhi | 18:6a4db94011d3 | 133 | /** |
sahilmgandhi | 18:6a4db94011d3 | 134 | * @brief Initializes the PCD according to the specified |
sahilmgandhi | 18:6a4db94011d3 | 135 | * parameters in the PCD_InitTypeDef and initialize the associated handle. |
sahilmgandhi | 18:6a4db94011d3 | 136 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 137 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 138 | */ |
sahilmgandhi | 18:6a4db94011d3 | 139 | HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd) |
sahilmgandhi | 18:6a4db94011d3 | 140 | { |
sahilmgandhi | 18:6a4db94011d3 | 141 | uint32_t i = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 142 | |
sahilmgandhi | 18:6a4db94011d3 | 143 | /* Check the PCD handle allocation */ |
sahilmgandhi | 18:6a4db94011d3 | 144 | if(hpcd == NULL) |
sahilmgandhi | 18:6a4db94011d3 | 145 | { |
sahilmgandhi | 18:6a4db94011d3 | 146 | return HAL_ERROR; |
sahilmgandhi | 18:6a4db94011d3 | 147 | } |
sahilmgandhi | 18:6a4db94011d3 | 148 | |
sahilmgandhi | 18:6a4db94011d3 | 149 | /* Check the parameters */ |
sahilmgandhi | 18:6a4db94011d3 | 150 | assert_param(IS_PCD_ALL_INSTANCE(hpcd->Instance)); |
sahilmgandhi | 18:6a4db94011d3 | 151 | if(hpcd->State == HAL_PCD_STATE_RESET) |
sahilmgandhi | 18:6a4db94011d3 | 152 | { |
sahilmgandhi | 18:6a4db94011d3 | 153 | /* Allocate lock resource and initialize it */ |
sahilmgandhi | 18:6a4db94011d3 | 154 | hpcd->Lock = HAL_UNLOCKED; |
sahilmgandhi | 18:6a4db94011d3 | 155 | for (i = 0; i < hpcd->Init.dev_endpoints ; i++) |
sahilmgandhi | 18:6a4db94011d3 | 156 | hpcd->EPLock[i].Lock = HAL_UNLOCKED; |
sahilmgandhi | 18:6a4db94011d3 | 157 | /* Init the low level hardware : GPIO, CLOCK, NVIC... */ |
sahilmgandhi | 18:6a4db94011d3 | 158 | HAL_PCD_MspInit(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 159 | } |
sahilmgandhi | 18:6a4db94011d3 | 160 | |
sahilmgandhi | 18:6a4db94011d3 | 161 | hpcd->State = HAL_PCD_STATE_BUSY; |
sahilmgandhi | 18:6a4db94011d3 | 162 | |
sahilmgandhi | 18:6a4db94011d3 | 163 | /* Disable the Interrupts */ |
sahilmgandhi | 18:6a4db94011d3 | 164 | __HAL_PCD_DISABLE(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 165 | |
sahilmgandhi | 18:6a4db94011d3 | 166 | /*Init the Core (common init.) */ |
sahilmgandhi | 18:6a4db94011d3 | 167 | USB_CoreInit(hpcd->Instance, hpcd->Init); |
sahilmgandhi | 18:6a4db94011d3 | 168 | |
sahilmgandhi | 18:6a4db94011d3 | 169 | /* Force Device Mode*/ |
sahilmgandhi | 18:6a4db94011d3 | 170 | USB_SetCurrentMode(hpcd->Instance , USB_OTG_DEVICE_MODE); |
sahilmgandhi | 18:6a4db94011d3 | 171 | |
sahilmgandhi | 18:6a4db94011d3 | 172 | /* Init endpoints structures */ |
sahilmgandhi | 18:6a4db94011d3 | 173 | for (i = 0U; i < 15U; i++) |
sahilmgandhi | 18:6a4db94011d3 | 174 | { |
sahilmgandhi | 18:6a4db94011d3 | 175 | /* Init ep structure */ |
sahilmgandhi | 18:6a4db94011d3 | 176 | hpcd->IN_ep[i].is_in = 1U; |
sahilmgandhi | 18:6a4db94011d3 | 177 | hpcd->IN_ep[i].num = i; |
sahilmgandhi | 18:6a4db94011d3 | 178 | hpcd->IN_ep[i].tx_fifo_num = i; |
sahilmgandhi | 18:6a4db94011d3 | 179 | /* Control until ep is activated */ |
sahilmgandhi | 18:6a4db94011d3 | 180 | hpcd->IN_ep[i].type = EP_TYPE_CTRL; |
sahilmgandhi | 18:6a4db94011d3 | 181 | hpcd->IN_ep[i].maxpacket = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 182 | hpcd->IN_ep[i].xfer_buff = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 183 | hpcd->IN_ep[i].xfer_len = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 184 | } |
sahilmgandhi | 18:6a4db94011d3 | 185 | |
sahilmgandhi | 18:6a4db94011d3 | 186 | for (i = 0U; i < 15U; i++) |
sahilmgandhi | 18:6a4db94011d3 | 187 | { |
sahilmgandhi | 18:6a4db94011d3 | 188 | hpcd->OUT_ep[i].is_in = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 189 | hpcd->OUT_ep[i].num = i; |
sahilmgandhi | 18:6a4db94011d3 | 190 | hpcd->IN_ep[i].tx_fifo_num = i; |
sahilmgandhi | 18:6a4db94011d3 | 191 | /* Control until ep is activated */ |
sahilmgandhi | 18:6a4db94011d3 | 192 | hpcd->OUT_ep[i].type = EP_TYPE_CTRL; |
sahilmgandhi | 18:6a4db94011d3 | 193 | hpcd->OUT_ep[i].maxpacket = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 194 | hpcd->OUT_ep[i].xfer_buff = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 195 | hpcd->OUT_ep[i].xfer_len = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 196 | |
sahilmgandhi | 18:6a4db94011d3 | 197 | hpcd->Instance->DIEPTXF[i] = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 198 | } |
sahilmgandhi | 18:6a4db94011d3 | 199 | /* Init Device */ |
sahilmgandhi | 18:6a4db94011d3 | 200 | USB_DevInit(hpcd->Instance, hpcd->Init); |
sahilmgandhi | 18:6a4db94011d3 | 201 | |
sahilmgandhi | 18:6a4db94011d3 | 202 | hpcd->State= HAL_PCD_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 203 | |
sahilmgandhi | 18:6a4db94011d3 | 204 | #ifdef USB_OTG_GLPMCFG_LPMEN |
sahilmgandhi | 18:6a4db94011d3 | 205 | /* Activate LPM */ |
sahilmgandhi | 18:6a4db94011d3 | 206 | if (hpcd->Init.lpm_enable == 1U) |
sahilmgandhi | 18:6a4db94011d3 | 207 | { |
sahilmgandhi | 18:6a4db94011d3 | 208 | HAL_PCDEx_ActivateLPM(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 209 | } |
sahilmgandhi | 18:6a4db94011d3 | 210 | #endif /* USB_OTG_GLPMCFG_LPMEN */ |
sahilmgandhi | 18:6a4db94011d3 | 211 | |
sahilmgandhi | 18:6a4db94011d3 | 212 | #ifdef USB_OTG_GCCFG_BCDEN |
sahilmgandhi | 18:6a4db94011d3 | 213 | /* Activate Battery charging */ |
sahilmgandhi | 18:6a4db94011d3 | 214 | if (hpcd->Init.battery_charging_enable == 1U) |
sahilmgandhi | 18:6a4db94011d3 | 215 | { |
sahilmgandhi | 18:6a4db94011d3 | 216 | HAL_PCDEx_ActivateBCD(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 217 | } |
sahilmgandhi | 18:6a4db94011d3 | 218 | #endif /* USB_OTG_GCCFG_BCDEN */ |
sahilmgandhi | 18:6a4db94011d3 | 219 | |
sahilmgandhi | 18:6a4db94011d3 | 220 | USB_DevDisconnect (hpcd->Instance); |
sahilmgandhi | 18:6a4db94011d3 | 221 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 222 | } |
sahilmgandhi | 18:6a4db94011d3 | 223 | |
sahilmgandhi | 18:6a4db94011d3 | 224 | /** |
sahilmgandhi | 18:6a4db94011d3 | 225 | * @brief DeInitializes the PCD peripheral. |
sahilmgandhi | 18:6a4db94011d3 | 226 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 227 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 228 | */ |
sahilmgandhi | 18:6a4db94011d3 | 229 | HAL_StatusTypeDef HAL_PCD_DeInit(PCD_HandleTypeDef *hpcd) |
sahilmgandhi | 18:6a4db94011d3 | 230 | { |
sahilmgandhi | 18:6a4db94011d3 | 231 | /* Check the PCD handle allocation */ |
sahilmgandhi | 18:6a4db94011d3 | 232 | if(hpcd == NULL) |
sahilmgandhi | 18:6a4db94011d3 | 233 | { |
sahilmgandhi | 18:6a4db94011d3 | 234 | return HAL_ERROR; |
sahilmgandhi | 18:6a4db94011d3 | 235 | } |
sahilmgandhi | 18:6a4db94011d3 | 236 | |
sahilmgandhi | 18:6a4db94011d3 | 237 | hpcd->State = HAL_PCD_STATE_BUSY; |
sahilmgandhi | 18:6a4db94011d3 | 238 | |
sahilmgandhi | 18:6a4db94011d3 | 239 | /* Stop Device */ |
sahilmgandhi | 18:6a4db94011d3 | 240 | HAL_PCD_Stop(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 241 | |
sahilmgandhi | 18:6a4db94011d3 | 242 | /* DeInit the low level hardware */ |
sahilmgandhi | 18:6a4db94011d3 | 243 | HAL_PCD_MspDeInit(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 244 | |
sahilmgandhi | 18:6a4db94011d3 | 245 | hpcd->State = HAL_PCD_STATE_RESET; |
sahilmgandhi | 18:6a4db94011d3 | 246 | |
sahilmgandhi | 18:6a4db94011d3 | 247 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 248 | } |
sahilmgandhi | 18:6a4db94011d3 | 249 | |
sahilmgandhi | 18:6a4db94011d3 | 250 | /** |
sahilmgandhi | 18:6a4db94011d3 | 251 | * @brief Initializes the PCD MSP. |
sahilmgandhi | 18:6a4db94011d3 | 252 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 253 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 254 | */ |
sahilmgandhi | 18:6a4db94011d3 | 255 | __weak void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) |
sahilmgandhi | 18:6a4db94011d3 | 256 | { |
sahilmgandhi | 18:6a4db94011d3 | 257 | /* Prevent unused argument(s) compilation warning */ |
sahilmgandhi | 18:6a4db94011d3 | 258 | UNUSED(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 259 | /* NOTE : This function Should not be modified, when the callback is needed, |
sahilmgandhi | 18:6a4db94011d3 | 260 | the HAL_PCD_MspInit could be implemented in the user file |
sahilmgandhi | 18:6a4db94011d3 | 261 | */ |
sahilmgandhi | 18:6a4db94011d3 | 262 | } |
sahilmgandhi | 18:6a4db94011d3 | 263 | |
sahilmgandhi | 18:6a4db94011d3 | 264 | /** |
sahilmgandhi | 18:6a4db94011d3 | 265 | * @brief DeInitializes PCD MSP. |
sahilmgandhi | 18:6a4db94011d3 | 266 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 267 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 268 | */ |
sahilmgandhi | 18:6a4db94011d3 | 269 | __weak void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd) |
sahilmgandhi | 18:6a4db94011d3 | 270 | { |
sahilmgandhi | 18:6a4db94011d3 | 271 | /* Prevent unused argument(s) compilation warning */ |
sahilmgandhi | 18:6a4db94011d3 | 272 | UNUSED(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 273 | /* NOTE : This function Should not be modified, when the callback is needed, |
sahilmgandhi | 18:6a4db94011d3 | 274 | the HAL_PCD_MspDeInit could be implemented in the user file |
sahilmgandhi | 18:6a4db94011d3 | 275 | */ |
sahilmgandhi | 18:6a4db94011d3 | 276 | } |
sahilmgandhi | 18:6a4db94011d3 | 277 | |
sahilmgandhi | 18:6a4db94011d3 | 278 | /** |
sahilmgandhi | 18:6a4db94011d3 | 279 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 280 | */ |
sahilmgandhi | 18:6a4db94011d3 | 281 | |
sahilmgandhi | 18:6a4db94011d3 | 282 | /** @defgroup PCD_Exported_Functions_Group2 Input and Output operation functions |
sahilmgandhi | 18:6a4db94011d3 | 283 | * @brief Data transfers functions |
sahilmgandhi | 18:6a4db94011d3 | 284 | * |
sahilmgandhi | 18:6a4db94011d3 | 285 | @verbatim |
sahilmgandhi | 18:6a4db94011d3 | 286 | =============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 287 | ##### IO operation functions ##### |
sahilmgandhi | 18:6a4db94011d3 | 288 | =============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 289 | [..] |
sahilmgandhi | 18:6a4db94011d3 | 290 | This subsection provides a set of functions allowing to manage the PCD data |
sahilmgandhi | 18:6a4db94011d3 | 291 | transfers. |
sahilmgandhi | 18:6a4db94011d3 | 292 | |
sahilmgandhi | 18:6a4db94011d3 | 293 | @endverbatim |
sahilmgandhi | 18:6a4db94011d3 | 294 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 295 | */ |
sahilmgandhi | 18:6a4db94011d3 | 296 | |
sahilmgandhi | 18:6a4db94011d3 | 297 | /** |
sahilmgandhi | 18:6a4db94011d3 | 298 | * @brief Start The USB OTG Device. |
sahilmgandhi | 18:6a4db94011d3 | 299 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 300 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 301 | */ |
sahilmgandhi | 18:6a4db94011d3 | 302 | HAL_StatusTypeDef HAL_PCD_Start(PCD_HandleTypeDef *hpcd) |
sahilmgandhi | 18:6a4db94011d3 | 303 | { |
sahilmgandhi | 18:6a4db94011d3 | 304 | //__HAL_LOCK(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 305 | USB_DevConnect (hpcd->Instance); |
sahilmgandhi | 18:6a4db94011d3 | 306 | __HAL_PCD_ENABLE(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 307 | //__HAL_UNLOCK(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 308 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 309 | } |
sahilmgandhi | 18:6a4db94011d3 | 310 | |
sahilmgandhi | 18:6a4db94011d3 | 311 | /** |
sahilmgandhi | 18:6a4db94011d3 | 312 | * @brief Stop The USB OTG Device. |
sahilmgandhi | 18:6a4db94011d3 | 313 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 314 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 315 | */ |
sahilmgandhi | 18:6a4db94011d3 | 316 | HAL_StatusTypeDef HAL_PCD_Stop(PCD_HandleTypeDef *hpcd) |
sahilmgandhi | 18:6a4db94011d3 | 317 | { |
sahilmgandhi | 18:6a4db94011d3 | 318 | //__HAL_LOCK(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 319 | __HAL_PCD_DISABLE(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 320 | USB_StopDevice(hpcd->Instance); |
sahilmgandhi | 18:6a4db94011d3 | 321 | USB_DevDisconnect(hpcd->Instance); |
sahilmgandhi | 18:6a4db94011d3 | 322 | //__HAL_UNLOCK(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 323 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 324 | } |
sahilmgandhi | 18:6a4db94011d3 | 325 | |
sahilmgandhi | 18:6a4db94011d3 | 326 | /** |
sahilmgandhi | 18:6a4db94011d3 | 327 | * @brief Handles PCD interrupt request. |
sahilmgandhi | 18:6a4db94011d3 | 328 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 329 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 330 | */ |
sahilmgandhi | 18:6a4db94011d3 | 331 | void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd) |
sahilmgandhi | 18:6a4db94011d3 | 332 | { |
sahilmgandhi | 18:6a4db94011d3 | 333 | USB_OTG_GlobalTypeDef *USBx = hpcd->Instance; |
sahilmgandhi | 18:6a4db94011d3 | 334 | uint32_t i = 0U, ep_intr = 0U, epint = 0U, epnum = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 335 | uint32_t fifoemptymsk = 0U, temp = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 336 | USB_OTG_EPTypeDef *ep; |
sahilmgandhi | 18:6a4db94011d3 | 337 | uint32_t hclk = 180000000; |
sahilmgandhi | 18:6a4db94011d3 | 338 | |
sahilmgandhi | 18:6a4db94011d3 | 339 | /* ensure that we are in device mode */ |
sahilmgandhi | 18:6a4db94011d3 | 340 | if (USB_GetMode(hpcd->Instance) == USB_OTG_MODE_DEVICE) |
sahilmgandhi | 18:6a4db94011d3 | 341 | { |
sahilmgandhi | 18:6a4db94011d3 | 342 | /* avoid spurious interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 343 | if(__HAL_PCD_IS_INVALID_INTERRUPT(hpcd)) |
sahilmgandhi | 18:6a4db94011d3 | 344 | { |
sahilmgandhi | 18:6a4db94011d3 | 345 | return; |
sahilmgandhi | 18:6a4db94011d3 | 346 | } |
sahilmgandhi | 18:6a4db94011d3 | 347 | |
sahilmgandhi | 18:6a4db94011d3 | 348 | if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_MMIS)) |
sahilmgandhi | 18:6a4db94011d3 | 349 | { |
sahilmgandhi | 18:6a4db94011d3 | 350 | /* incorrect mode, acknowledge the interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 351 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_MMIS); |
sahilmgandhi | 18:6a4db94011d3 | 352 | } |
sahilmgandhi | 18:6a4db94011d3 | 353 | |
sahilmgandhi | 18:6a4db94011d3 | 354 | if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_OEPINT)) |
sahilmgandhi | 18:6a4db94011d3 | 355 | { |
sahilmgandhi | 18:6a4db94011d3 | 356 | epnum = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 357 | |
sahilmgandhi | 18:6a4db94011d3 | 358 | /* Read in the device interrupt bits */ |
sahilmgandhi | 18:6a4db94011d3 | 359 | ep_intr = USB_ReadDevAllOutEpInterrupt(hpcd->Instance); |
sahilmgandhi | 18:6a4db94011d3 | 360 | |
sahilmgandhi | 18:6a4db94011d3 | 361 | while ( ep_intr ) |
sahilmgandhi | 18:6a4db94011d3 | 362 | { |
sahilmgandhi | 18:6a4db94011d3 | 363 | if (ep_intr & 0x1U) |
sahilmgandhi | 18:6a4db94011d3 | 364 | { |
sahilmgandhi | 18:6a4db94011d3 | 365 | epint = USB_ReadDevOutEPInterrupt(hpcd->Instance, epnum); |
sahilmgandhi | 18:6a4db94011d3 | 366 | |
sahilmgandhi | 18:6a4db94011d3 | 367 | if(( epint & USB_OTG_DOEPINT_XFRC) == USB_OTG_DOEPINT_XFRC) |
sahilmgandhi | 18:6a4db94011d3 | 368 | { |
sahilmgandhi | 18:6a4db94011d3 | 369 | CLEAR_OUT_EP_INTR(epnum, USB_OTG_DOEPINT_XFRC); |
sahilmgandhi | 18:6a4db94011d3 | 370 | |
sahilmgandhi | 18:6a4db94011d3 | 371 | if(hpcd->Init.dma_enable == 1U) |
sahilmgandhi | 18:6a4db94011d3 | 372 | { |
sahilmgandhi | 18:6a4db94011d3 | 373 | hpcd->OUT_ep[epnum].xfer_count = hpcd->OUT_ep[epnum].maxpacket- (USBx_OUTEP(epnum)->DOEPTSIZ & USB_OTG_DOEPTSIZ_XFRSIZ); |
sahilmgandhi | 18:6a4db94011d3 | 374 | hpcd->OUT_ep[epnum].xfer_buff += hpcd->OUT_ep[epnum].maxpacket; |
sahilmgandhi | 18:6a4db94011d3 | 375 | } |
sahilmgandhi | 18:6a4db94011d3 | 376 | |
sahilmgandhi | 18:6a4db94011d3 | 377 | HAL_PCD_DataOutStageCallback(hpcd, epnum); |
sahilmgandhi | 18:6a4db94011d3 | 378 | if(hpcd->Init.dma_enable == 1U) |
sahilmgandhi | 18:6a4db94011d3 | 379 | { |
sahilmgandhi | 18:6a4db94011d3 | 380 | if((epnum == 0U) && (hpcd->OUT_ep[epnum].xfer_len == 0U)) |
sahilmgandhi | 18:6a4db94011d3 | 381 | { |
sahilmgandhi | 18:6a4db94011d3 | 382 | /* this is ZLP, so prepare EP0 for next setup */ |
sahilmgandhi | 18:6a4db94011d3 | 383 | USB_EP0_OutStart(hpcd->Instance, 1U, (uint8_t *)hpcd->Setup); |
sahilmgandhi | 18:6a4db94011d3 | 384 | } |
sahilmgandhi | 18:6a4db94011d3 | 385 | } |
sahilmgandhi | 18:6a4db94011d3 | 386 | } |
sahilmgandhi | 18:6a4db94011d3 | 387 | |
sahilmgandhi | 18:6a4db94011d3 | 388 | if(( epint & USB_OTG_DOEPINT_STUP) == USB_OTG_DOEPINT_STUP) |
sahilmgandhi | 18:6a4db94011d3 | 389 | { |
sahilmgandhi | 18:6a4db94011d3 | 390 | /* Inform the upper layer that a setup packet is available */ |
sahilmgandhi | 18:6a4db94011d3 | 391 | HAL_PCD_SetupStageCallback(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 392 | CLEAR_OUT_EP_INTR(epnum, USB_OTG_DOEPINT_STUP); |
sahilmgandhi | 18:6a4db94011d3 | 393 | } |
sahilmgandhi | 18:6a4db94011d3 | 394 | |
sahilmgandhi | 18:6a4db94011d3 | 395 | if(( epint & USB_OTG_DOEPINT_OTEPDIS) == USB_OTG_DOEPINT_OTEPDIS) |
sahilmgandhi | 18:6a4db94011d3 | 396 | { |
sahilmgandhi | 18:6a4db94011d3 | 397 | CLEAR_OUT_EP_INTR(epnum, USB_OTG_DOEPINT_OTEPDIS); |
sahilmgandhi | 18:6a4db94011d3 | 398 | } |
sahilmgandhi | 18:6a4db94011d3 | 399 | |
sahilmgandhi | 18:6a4db94011d3 | 400 | #ifdef USB_OTG_DOEPINT_OTEPSPR |
sahilmgandhi | 18:6a4db94011d3 | 401 | /* Clear Status Phase Received interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 402 | if(( epint & USB_OTG_DOEPINT_OTEPSPR) == USB_OTG_DOEPINT_OTEPSPR) |
sahilmgandhi | 18:6a4db94011d3 | 403 | { |
sahilmgandhi | 18:6a4db94011d3 | 404 | CLEAR_OUT_EP_INTR(epnum, USB_OTG_DOEPINT_OTEPSPR); |
sahilmgandhi | 18:6a4db94011d3 | 405 | } |
sahilmgandhi | 18:6a4db94011d3 | 406 | #endif /* USB_OTG_DOEPINT_OTEPSPR */ |
sahilmgandhi | 18:6a4db94011d3 | 407 | } |
sahilmgandhi | 18:6a4db94011d3 | 408 | epnum++; |
sahilmgandhi | 18:6a4db94011d3 | 409 | ep_intr >>= 1U; |
sahilmgandhi | 18:6a4db94011d3 | 410 | } |
sahilmgandhi | 18:6a4db94011d3 | 411 | } |
sahilmgandhi | 18:6a4db94011d3 | 412 | |
sahilmgandhi | 18:6a4db94011d3 | 413 | if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_IEPINT)) |
sahilmgandhi | 18:6a4db94011d3 | 414 | { |
sahilmgandhi | 18:6a4db94011d3 | 415 | /* Read in the device interrupt bits */ |
sahilmgandhi | 18:6a4db94011d3 | 416 | ep_intr = USB_ReadDevAllInEpInterrupt(hpcd->Instance); |
sahilmgandhi | 18:6a4db94011d3 | 417 | |
sahilmgandhi | 18:6a4db94011d3 | 418 | epnum = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 419 | |
sahilmgandhi | 18:6a4db94011d3 | 420 | while ( ep_intr ) |
sahilmgandhi | 18:6a4db94011d3 | 421 | { |
sahilmgandhi | 18:6a4db94011d3 | 422 | if (ep_intr & 0x1U) /* In ITR */ |
sahilmgandhi | 18:6a4db94011d3 | 423 | { |
sahilmgandhi | 18:6a4db94011d3 | 424 | epint = USB_ReadDevInEPInterrupt(hpcd->Instance, epnum); |
sahilmgandhi | 18:6a4db94011d3 | 425 | |
sahilmgandhi | 18:6a4db94011d3 | 426 | if(( epint & USB_OTG_DIEPINT_XFRC) == USB_OTG_DIEPINT_XFRC) |
sahilmgandhi | 18:6a4db94011d3 | 427 | { |
sahilmgandhi | 18:6a4db94011d3 | 428 | fifoemptymsk = 0x1U << epnum; |
sahilmgandhi | 18:6a4db94011d3 | 429 | |
sahilmgandhi | 18:6a4db94011d3 | 430 | atomic_clr_u32(&USBx_DEVICE->DIEPEMPMSK,fifoemptymsk); |
sahilmgandhi | 18:6a4db94011d3 | 431 | |
sahilmgandhi | 18:6a4db94011d3 | 432 | CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_XFRC); |
sahilmgandhi | 18:6a4db94011d3 | 433 | |
sahilmgandhi | 18:6a4db94011d3 | 434 | if (hpcd->Init.dma_enable == 1U) |
sahilmgandhi | 18:6a4db94011d3 | 435 | { |
sahilmgandhi | 18:6a4db94011d3 | 436 | hpcd->IN_ep[epnum].xfer_buff += hpcd->IN_ep[epnum].maxpacket; |
sahilmgandhi | 18:6a4db94011d3 | 437 | } |
sahilmgandhi | 18:6a4db94011d3 | 438 | |
sahilmgandhi | 18:6a4db94011d3 | 439 | HAL_PCD_DataInStageCallback(hpcd, epnum); |
sahilmgandhi | 18:6a4db94011d3 | 440 | |
sahilmgandhi | 18:6a4db94011d3 | 441 | if (hpcd->Init.dma_enable == 1U) |
sahilmgandhi | 18:6a4db94011d3 | 442 | { |
sahilmgandhi | 18:6a4db94011d3 | 443 | /* this is ZLP, so prepare EP0 for next setup */ |
sahilmgandhi | 18:6a4db94011d3 | 444 | if((epnum == 0U) && (hpcd->IN_ep[epnum].xfer_len == 0U)) |
sahilmgandhi | 18:6a4db94011d3 | 445 | { |
sahilmgandhi | 18:6a4db94011d3 | 446 | /* prepare to rx more setup packets */ |
sahilmgandhi | 18:6a4db94011d3 | 447 | USB_EP0_OutStart(hpcd->Instance, 1U, (uint8_t *)hpcd->Setup); |
sahilmgandhi | 18:6a4db94011d3 | 448 | } |
sahilmgandhi | 18:6a4db94011d3 | 449 | } |
sahilmgandhi | 18:6a4db94011d3 | 450 | } |
sahilmgandhi | 18:6a4db94011d3 | 451 | if(( epint & USB_OTG_DIEPINT_TOC) == USB_OTG_DIEPINT_TOC) |
sahilmgandhi | 18:6a4db94011d3 | 452 | { |
sahilmgandhi | 18:6a4db94011d3 | 453 | CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_TOC); |
sahilmgandhi | 18:6a4db94011d3 | 454 | } |
sahilmgandhi | 18:6a4db94011d3 | 455 | if(( epint & USB_OTG_DIEPINT_ITTXFE) == USB_OTG_DIEPINT_ITTXFE) |
sahilmgandhi | 18:6a4db94011d3 | 456 | { |
sahilmgandhi | 18:6a4db94011d3 | 457 | CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_ITTXFE); |
sahilmgandhi | 18:6a4db94011d3 | 458 | } |
sahilmgandhi | 18:6a4db94011d3 | 459 | if(( epint & USB_OTG_DIEPINT_INEPNE) == USB_OTG_DIEPINT_INEPNE) |
sahilmgandhi | 18:6a4db94011d3 | 460 | { |
sahilmgandhi | 18:6a4db94011d3 | 461 | CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_INEPNE); |
sahilmgandhi | 18:6a4db94011d3 | 462 | } |
sahilmgandhi | 18:6a4db94011d3 | 463 | if(( epint & USB_OTG_DIEPINT_EPDISD) == USB_OTG_DIEPINT_EPDISD) |
sahilmgandhi | 18:6a4db94011d3 | 464 | { |
sahilmgandhi | 18:6a4db94011d3 | 465 | CLEAR_IN_EP_INTR(epnum, USB_OTG_DIEPINT_EPDISD); |
sahilmgandhi | 18:6a4db94011d3 | 466 | } |
sahilmgandhi | 18:6a4db94011d3 | 467 | if(( epint & USB_OTG_DIEPINT_TXFE) == USB_OTG_DIEPINT_TXFE) |
sahilmgandhi | 18:6a4db94011d3 | 468 | { |
sahilmgandhi | 18:6a4db94011d3 | 469 | PCD_WriteEmptyTxFifo(hpcd , epnum); |
sahilmgandhi | 18:6a4db94011d3 | 470 | } |
sahilmgandhi | 18:6a4db94011d3 | 471 | } |
sahilmgandhi | 18:6a4db94011d3 | 472 | epnum++; |
sahilmgandhi | 18:6a4db94011d3 | 473 | ep_intr >>= 1U; |
sahilmgandhi | 18:6a4db94011d3 | 474 | } |
sahilmgandhi | 18:6a4db94011d3 | 475 | } |
sahilmgandhi | 18:6a4db94011d3 | 476 | |
sahilmgandhi | 18:6a4db94011d3 | 477 | /* Handle Resume Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 478 | if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_WKUINT)) |
sahilmgandhi | 18:6a4db94011d3 | 479 | { |
sahilmgandhi | 18:6a4db94011d3 | 480 | /* Clear the Remote Wake-up Signaling */ |
sahilmgandhi | 18:6a4db94011d3 | 481 | USBx_DEVICE->DCTL &= ~USB_OTG_DCTL_RWUSIG; |
sahilmgandhi | 18:6a4db94011d3 | 482 | |
sahilmgandhi | 18:6a4db94011d3 | 483 | #ifdef USB_OTG_GLPMCFG_LPMEN |
sahilmgandhi | 18:6a4db94011d3 | 484 | if(hpcd->LPM_State == LPM_L1) |
sahilmgandhi | 18:6a4db94011d3 | 485 | { |
sahilmgandhi | 18:6a4db94011d3 | 486 | hpcd->LPM_State = LPM_L0; |
sahilmgandhi | 18:6a4db94011d3 | 487 | HAL_PCDEx_LPM_Callback(hpcd, PCD_LPM_L0_ACTIVE); |
sahilmgandhi | 18:6a4db94011d3 | 488 | } |
sahilmgandhi | 18:6a4db94011d3 | 489 | else |
sahilmgandhi | 18:6a4db94011d3 | 490 | #endif /* USB_OTG_GLPMCFG_LPMEN */ |
sahilmgandhi | 18:6a4db94011d3 | 491 | { |
sahilmgandhi | 18:6a4db94011d3 | 492 | HAL_PCD_ResumeCallback(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 493 | } |
sahilmgandhi | 18:6a4db94011d3 | 494 | |
sahilmgandhi | 18:6a4db94011d3 | 495 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_WKUINT); |
sahilmgandhi | 18:6a4db94011d3 | 496 | } |
sahilmgandhi | 18:6a4db94011d3 | 497 | |
sahilmgandhi | 18:6a4db94011d3 | 498 | /* Handle Suspend Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 499 | if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_USBSUSP)) |
sahilmgandhi | 18:6a4db94011d3 | 500 | { |
sahilmgandhi | 18:6a4db94011d3 | 501 | if((USBx_DEVICE->DSTS & USB_OTG_DSTS_SUSPSTS) == USB_OTG_DSTS_SUSPSTS) |
sahilmgandhi | 18:6a4db94011d3 | 502 | { |
sahilmgandhi | 18:6a4db94011d3 | 503 | |
sahilmgandhi | 18:6a4db94011d3 | 504 | HAL_PCD_SuspendCallback(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 505 | } |
sahilmgandhi | 18:6a4db94011d3 | 506 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_USBSUSP); |
sahilmgandhi | 18:6a4db94011d3 | 507 | } |
sahilmgandhi | 18:6a4db94011d3 | 508 | |
sahilmgandhi | 18:6a4db94011d3 | 509 | #ifdef USB_OTG_GLPMCFG_LPMEN |
sahilmgandhi | 18:6a4db94011d3 | 510 | /* Handle LPM Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 511 | if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_LPMINT)) |
sahilmgandhi | 18:6a4db94011d3 | 512 | { |
sahilmgandhi | 18:6a4db94011d3 | 513 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_LPMINT); |
sahilmgandhi | 18:6a4db94011d3 | 514 | if( hpcd->LPM_State == LPM_L0) |
sahilmgandhi | 18:6a4db94011d3 | 515 | { |
sahilmgandhi | 18:6a4db94011d3 | 516 | hpcd->LPM_State = LPM_L1; |
sahilmgandhi | 18:6a4db94011d3 | 517 | hpcd->BESL = (hpcd->Instance->GLPMCFG & USB_OTG_GLPMCFG_BESL) >>2 ; |
sahilmgandhi | 18:6a4db94011d3 | 518 | HAL_PCDEx_LPM_Callback(hpcd, PCD_LPM_L1_ACTIVE); |
sahilmgandhi | 18:6a4db94011d3 | 519 | } |
sahilmgandhi | 18:6a4db94011d3 | 520 | else |
sahilmgandhi | 18:6a4db94011d3 | 521 | { |
sahilmgandhi | 18:6a4db94011d3 | 522 | HAL_PCD_SuspendCallback(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 523 | } |
sahilmgandhi | 18:6a4db94011d3 | 524 | } |
sahilmgandhi | 18:6a4db94011d3 | 525 | #endif /* USB_OTG_GLPMCFG_LPMEN */ |
sahilmgandhi | 18:6a4db94011d3 | 526 | |
sahilmgandhi | 18:6a4db94011d3 | 527 | /* Handle Reset Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 528 | if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_USBRST)) |
sahilmgandhi | 18:6a4db94011d3 | 529 | { |
sahilmgandhi | 18:6a4db94011d3 | 530 | USBx_DEVICE->DCTL &= ~USB_OTG_DCTL_RWUSIG; |
sahilmgandhi | 18:6a4db94011d3 | 531 | USB_FlushTxFifo(hpcd->Instance , 0U); |
sahilmgandhi | 18:6a4db94011d3 | 532 | |
sahilmgandhi | 18:6a4db94011d3 | 533 | for (i = 0U; i < hpcd->Init.dev_endpoints; i++) |
sahilmgandhi | 18:6a4db94011d3 | 534 | { |
sahilmgandhi | 18:6a4db94011d3 | 535 | USBx_INEP(i)->DIEPINT = 0xFFU; |
sahilmgandhi | 18:6a4db94011d3 | 536 | USBx_OUTEP(i)->DOEPINT = 0xFFU; |
sahilmgandhi | 18:6a4db94011d3 | 537 | } |
sahilmgandhi | 18:6a4db94011d3 | 538 | USBx_DEVICE->DAINT = 0xFFFFFFFFU; |
sahilmgandhi | 18:6a4db94011d3 | 539 | USBx_DEVICE->DAINTMSK |= 0x10001U; |
sahilmgandhi | 18:6a4db94011d3 | 540 | |
sahilmgandhi | 18:6a4db94011d3 | 541 | if(hpcd->Init.use_dedicated_ep1) |
sahilmgandhi | 18:6a4db94011d3 | 542 | { |
sahilmgandhi | 18:6a4db94011d3 | 543 | USBx_DEVICE->DOUTEP1MSK |= (USB_OTG_DOEPMSK_STUPM | USB_OTG_DOEPMSK_XFRCM | USB_OTG_DOEPMSK_EPDM); |
sahilmgandhi | 18:6a4db94011d3 | 544 | USBx_DEVICE->DINEP1MSK |= (USB_OTG_DIEPMSK_TOM | USB_OTG_DIEPMSK_XFRCM | USB_OTG_DIEPMSK_EPDM); |
sahilmgandhi | 18:6a4db94011d3 | 545 | } |
sahilmgandhi | 18:6a4db94011d3 | 546 | else |
sahilmgandhi | 18:6a4db94011d3 | 547 | { |
sahilmgandhi | 18:6a4db94011d3 | 548 | #ifdef USB_OTG_DOEPINT_OTEPSPR |
sahilmgandhi | 18:6a4db94011d3 | 549 | USBx_DEVICE->DOEPMSK |= (USB_OTG_DOEPMSK_STUPM | USB_OTG_DOEPMSK_XFRCM | USB_OTG_DOEPMSK_EPDM | USB_OTG_DOEPMSK_OTEPSPRM); |
sahilmgandhi | 18:6a4db94011d3 | 550 | #else |
sahilmgandhi | 18:6a4db94011d3 | 551 | USBx_DEVICE->DOEPMSK |= (USB_OTG_DOEPMSK_STUPM | USB_OTG_DOEPMSK_XFRCM | USB_OTG_DOEPMSK_EPDM); |
sahilmgandhi | 18:6a4db94011d3 | 552 | #endif /* USB_OTG_DOEPINT_OTEPSPR */ |
sahilmgandhi | 18:6a4db94011d3 | 553 | USBx_DEVICE->DIEPMSK |= (USB_OTG_DIEPMSK_TOM | USB_OTG_DIEPMSK_XFRCM | USB_OTG_DIEPMSK_EPDM); |
sahilmgandhi | 18:6a4db94011d3 | 554 | } |
sahilmgandhi | 18:6a4db94011d3 | 555 | |
sahilmgandhi | 18:6a4db94011d3 | 556 | /* Set Default Address to 0 */ |
sahilmgandhi | 18:6a4db94011d3 | 557 | USBx_DEVICE->DCFG &= ~USB_OTG_DCFG_DAD; |
sahilmgandhi | 18:6a4db94011d3 | 558 | |
sahilmgandhi | 18:6a4db94011d3 | 559 | /* setup EP0 to receive SETUP packets */ |
sahilmgandhi | 18:6a4db94011d3 | 560 | USB_EP0_OutStart(hpcd->Instance, hpcd->Init.dma_enable, (uint8_t *)hpcd->Setup); |
sahilmgandhi | 18:6a4db94011d3 | 561 | |
sahilmgandhi | 18:6a4db94011d3 | 562 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_USBRST); |
sahilmgandhi | 18:6a4db94011d3 | 563 | } |
sahilmgandhi | 18:6a4db94011d3 | 564 | |
sahilmgandhi | 18:6a4db94011d3 | 565 | /* Handle Enumeration done Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 566 | if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_ENUMDNE)) |
sahilmgandhi | 18:6a4db94011d3 | 567 | { |
sahilmgandhi | 18:6a4db94011d3 | 568 | USB_ActivateSetup(hpcd->Instance); |
sahilmgandhi | 18:6a4db94011d3 | 569 | hpcd->Instance->GUSBCFG &= ~USB_OTG_GUSBCFG_TRDT; |
sahilmgandhi | 18:6a4db94011d3 | 570 | |
sahilmgandhi | 18:6a4db94011d3 | 571 | if ( USB_GetDevSpeed(hpcd->Instance) == USB_OTG_SPEED_HIGH) |
sahilmgandhi | 18:6a4db94011d3 | 572 | { |
sahilmgandhi | 18:6a4db94011d3 | 573 | hpcd->Init.speed = USB_OTG_SPEED_HIGH; |
sahilmgandhi | 18:6a4db94011d3 | 574 | hpcd->Init.ep0_mps = USB_OTG_HS_MAX_PACKET_SIZE ; |
sahilmgandhi | 18:6a4db94011d3 | 575 | hpcd->Instance->GUSBCFG |= (uint32_t)((USBD_HS_TRDT_VALUE << 10U) & USB_OTG_GUSBCFG_TRDT); |
sahilmgandhi | 18:6a4db94011d3 | 576 | } |
sahilmgandhi | 18:6a4db94011d3 | 577 | else |
sahilmgandhi | 18:6a4db94011d3 | 578 | { |
sahilmgandhi | 18:6a4db94011d3 | 579 | hpcd->Init.speed = USB_OTG_SPEED_FULL; |
sahilmgandhi | 18:6a4db94011d3 | 580 | hpcd->Init.ep0_mps = USB_OTG_FS_MAX_PACKET_SIZE ; |
sahilmgandhi | 18:6a4db94011d3 | 581 | |
sahilmgandhi | 18:6a4db94011d3 | 582 | /* The USBTRD is configured according to the tables below, depending on AHB frequency |
sahilmgandhi | 18:6a4db94011d3 | 583 | used by application. In the low AHB frequency range it is used to stretch enough the USB response |
sahilmgandhi | 18:6a4db94011d3 | 584 | time to IN tokens, the USB turnaround time, so to compensate for the longer AHB read access |
sahilmgandhi | 18:6a4db94011d3 | 585 | latency to the Data FIFO */ |
sahilmgandhi | 18:6a4db94011d3 | 586 | |
sahilmgandhi | 18:6a4db94011d3 | 587 | if((hclk >= 14200000)&&(hclk < 15000000)) |
sahilmgandhi | 18:6a4db94011d3 | 588 | { |
sahilmgandhi | 18:6a4db94011d3 | 589 | /* hclk Clock Range between 14.2-15 MHz */ |
sahilmgandhi | 18:6a4db94011d3 | 590 | hpcd->Instance->GUSBCFG |= (uint32_t)((0xF << 10) & USB_OTG_GUSBCFG_TRDT); |
sahilmgandhi | 18:6a4db94011d3 | 591 | } |
sahilmgandhi | 18:6a4db94011d3 | 592 | |
sahilmgandhi | 18:6a4db94011d3 | 593 | else if((hclk >= 15000000)&&(hclk < 16000000)) |
sahilmgandhi | 18:6a4db94011d3 | 594 | { |
sahilmgandhi | 18:6a4db94011d3 | 595 | /* hclk Clock Range between 15-16 MHz */ |
sahilmgandhi | 18:6a4db94011d3 | 596 | hpcd->Instance->GUSBCFG |= (uint32_t)((0xE << 10) & USB_OTG_GUSBCFG_TRDT); |
sahilmgandhi | 18:6a4db94011d3 | 597 | } |
sahilmgandhi | 18:6a4db94011d3 | 598 | |
sahilmgandhi | 18:6a4db94011d3 | 599 | else if((hclk >= 16000000)&&(hclk < 17200000)) |
sahilmgandhi | 18:6a4db94011d3 | 600 | { |
sahilmgandhi | 18:6a4db94011d3 | 601 | /* hclk Clock Range between 16-17.2 MHz */ |
sahilmgandhi | 18:6a4db94011d3 | 602 | hpcd->Instance->GUSBCFG |= (uint32_t)((0xD << 10) & USB_OTG_GUSBCFG_TRDT); |
sahilmgandhi | 18:6a4db94011d3 | 603 | } |
sahilmgandhi | 18:6a4db94011d3 | 604 | |
sahilmgandhi | 18:6a4db94011d3 | 605 | else if((hclk >= 17200000)&&(hclk < 18500000)) |
sahilmgandhi | 18:6a4db94011d3 | 606 | { |
sahilmgandhi | 18:6a4db94011d3 | 607 | /* hclk Clock Range between 17.2-18.5 MHz */ |
sahilmgandhi | 18:6a4db94011d3 | 608 | hpcd->Instance->GUSBCFG |= (uint32_t)((0xC << 10) & USB_OTG_GUSBCFG_TRDT); |
sahilmgandhi | 18:6a4db94011d3 | 609 | } |
sahilmgandhi | 18:6a4db94011d3 | 610 | |
sahilmgandhi | 18:6a4db94011d3 | 611 | else if((hclk >= 18500000)&&(hclk < 20000000)) |
sahilmgandhi | 18:6a4db94011d3 | 612 | { |
sahilmgandhi | 18:6a4db94011d3 | 613 | /* hclk Clock Range between 18.5-20 MHz */ |
sahilmgandhi | 18:6a4db94011d3 | 614 | hpcd->Instance->GUSBCFG |= (uint32_t)((0xB << 10) & USB_OTG_GUSBCFG_TRDT); |
sahilmgandhi | 18:6a4db94011d3 | 615 | } |
sahilmgandhi | 18:6a4db94011d3 | 616 | |
sahilmgandhi | 18:6a4db94011d3 | 617 | else if((hclk >= 20000000)&&(hclk < 21800000)) |
sahilmgandhi | 18:6a4db94011d3 | 618 | { |
sahilmgandhi | 18:6a4db94011d3 | 619 | /* hclk Clock Range between 20-21.8 MHz */ |
sahilmgandhi | 18:6a4db94011d3 | 620 | hpcd->Instance->GUSBCFG |= (uint32_t)((0xA << 10) & USB_OTG_GUSBCFG_TRDT); |
sahilmgandhi | 18:6a4db94011d3 | 621 | } |
sahilmgandhi | 18:6a4db94011d3 | 622 | |
sahilmgandhi | 18:6a4db94011d3 | 623 | else if((hclk >= 21800000)&&(hclk < 24000000)) |
sahilmgandhi | 18:6a4db94011d3 | 624 | { |
sahilmgandhi | 18:6a4db94011d3 | 625 | /* hclk Clock Range between 21.8-24 MHz */ |
sahilmgandhi | 18:6a4db94011d3 | 626 | hpcd->Instance->GUSBCFG |= (uint32_t)((0x9 << 10) & USB_OTG_GUSBCFG_TRDT); |
sahilmgandhi | 18:6a4db94011d3 | 627 | } |
sahilmgandhi | 18:6a4db94011d3 | 628 | |
sahilmgandhi | 18:6a4db94011d3 | 629 | else if((hclk >= 24000000)&&(hclk < 27700000)) |
sahilmgandhi | 18:6a4db94011d3 | 630 | { |
sahilmgandhi | 18:6a4db94011d3 | 631 | /* hclk Clock Range between 24-27.7 MHz */ |
sahilmgandhi | 18:6a4db94011d3 | 632 | hpcd->Instance->GUSBCFG |= (uint32_t)((0x8 << 10) & USB_OTG_GUSBCFG_TRDT); |
sahilmgandhi | 18:6a4db94011d3 | 633 | } |
sahilmgandhi | 18:6a4db94011d3 | 634 | |
sahilmgandhi | 18:6a4db94011d3 | 635 | else if((hclk >= 27700000)&&(hclk < 32000000)) |
sahilmgandhi | 18:6a4db94011d3 | 636 | { |
sahilmgandhi | 18:6a4db94011d3 | 637 | /* hclk Clock Range between 27.7-32 MHz */ |
sahilmgandhi | 18:6a4db94011d3 | 638 | hpcd->Instance->GUSBCFG |= (uint32_t)((0x7 << 10) & USB_OTG_GUSBCFG_TRDT); |
sahilmgandhi | 18:6a4db94011d3 | 639 | } |
sahilmgandhi | 18:6a4db94011d3 | 640 | |
sahilmgandhi | 18:6a4db94011d3 | 641 | else /* if(hclk >= 32000000) */ |
sahilmgandhi | 18:6a4db94011d3 | 642 | { |
sahilmgandhi | 18:6a4db94011d3 | 643 | /* hclk Clock Range between 32-180 MHz */ |
sahilmgandhi | 18:6a4db94011d3 | 644 | hpcd->Instance->GUSBCFG |= (uint32_t)((0x6 << 10) & USB_OTG_GUSBCFG_TRDT); |
sahilmgandhi | 18:6a4db94011d3 | 645 | } |
sahilmgandhi | 18:6a4db94011d3 | 646 | } |
sahilmgandhi | 18:6a4db94011d3 | 647 | |
sahilmgandhi | 18:6a4db94011d3 | 648 | HAL_PCD_ResetCallback(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 649 | |
sahilmgandhi | 18:6a4db94011d3 | 650 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_ENUMDNE); |
sahilmgandhi | 18:6a4db94011d3 | 651 | } |
sahilmgandhi | 18:6a4db94011d3 | 652 | |
sahilmgandhi | 18:6a4db94011d3 | 653 | /* Handle RxQLevel Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 654 | if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_RXFLVL)) |
sahilmgandhi | 18:6a4db94011d3 | 655 | { |
sahilmgandhi | 18:6a4db94011d3 | 656 | USB_MASK_INTERRUPT(hpcd->Instance, USB_OTG_GINTSTS_RXFLVL); |
sahilmgandhi | 18:6a4db94011d3 | 657 | |
sahilmgandhi | 18:6a4db94011d3 | 658 | temp = USBx->GRXSTSP; |
sahilmgandhi | 18:6a4db94011d3 | 659 | |
sahilmgandhi | 18:6a4db94011d3 | 660 | ep = &hpcd->OUT_ep[temp & USB_OTG_GRXSTSP_EPNUM]; |
sahilmgandhi | 18:6a4db94011d3 | 661 | |
sahilmgandhi | 18:6a4db94011d3 | 662 | if(((temp & USB_OTG_GRXSTSP_PKTSTS) >> 17U) == STS_DATA_UPDT) |
sahilmgandhi | 18:6a4db94011d3 | 663 | { |
sahilmgandhi | 18:6a4db94011d3 | 664 | if((temp & USB_OTG_GRXSTSP_BCNT) != 0U) |
sahilmgandhi | 18:6a4db94011d3 | 665 | { |
sahilmgandhi | 18:6a4db94011d3 | 666 | USB_ReadPacket(USBx, ep->xfer_buff, (temp & USB_OTG_GRXSTSP_BCNT) >> 4U); |
sahilmgandhi | 18:6a4db94011d3 | 667 | ep->xfer_buff += (temp & USB_OTG_GRXSTSP_BCNT) >> 4U; |
sahilmgandhi | 18:6a4db94011d3 | 668 | ep->xfer_count += (temp & USB_OTG_GRXSTSP_BCNT) >> 4U; |
sahilmgandhi | 18:6a4db94011d3 | 669 | } |
sahilmgandhi | 18:6a4db94011d3 | 670 | } |
sahilmgandhi | 18:6a4db94011d3 | 671 | else if (((temp & USB_OTG_GRXSTSP_PKTSTS) >> 17U) == STS_SETUP_UPDT) |
sahilmgandhi | 18:6a4db94011d3 | 672 | { |
sahilmgandhi | 18:6a4db94011d3 | 673 | USB_ReadPacket(USBx, (uint8_t *)hpcd->Setup, 8U); |
sahilmgandhi | 18:6a4db94011d3 | 674 | ep->xfer_count += (temp & USB_OTG_GRXSTSP_BCNT) >> 4U; |
sahilmgandhi | 18:6a4db94011d3 | 675 | } |
sahilmgandhi | 18:6a4db94011d3 | 676 | USB_UNMASK_INTERRUPT(hpcd->Instance, USB_OTG_GINTSTS_RXFLVL); |
sahilmgandhi | 18:6a4db94011d3 | 677 | } |
sahilmgandhi | 18:6a4db94011d3 | 678 | |
sahilmgandhi | 18:6a4db94011d3 | 679 | /* Handle SOF Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 680 | if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_SOF)) |
sahilmgandhi | 18:6a4db94011d3 | 681 | { |
sahilmgandhi | 18:6a4db94011d3 | 682 | HAL_PCD_SOFCallback(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 683 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_SOF); |
sahilmgandhi | 18:6a4db94011d3 | 684 | } |
sahilmgandhi | 18:6a4db94011d3 | 685 | |
sahilmgandhi | 18:6a4db94011d3 | 686 | /* Handle Incomplete ISO IN Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 687 | if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_IISOIXFR)) |
sahilmgandhi | 18:6a4db94011d3 | 688 | { |
sahilmgandhi | 18:6a4db94011d3 | 689 | HAL_PCD_ISOINIncompleteCallback(hpcd, epnum); |
sahilmgandhi | 18:6a4db94011d3 | 690 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_IISOIXFR); |
sahilmgandhi | 18:6a4db94011d3 | 691 | } |
sahilmgandhi | 18:6a4db94011d3 | 692 | |
sahilmgandhi | 18:6a4db94011d3 | 693 | /* Handle Incomplete ISO OUT Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 694 | if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_PXFR_INCOMPISOOUT)) |
sahilmgandhi | 18:6a4db94011d3 | 695 | { |
sahilmgandhi | 18:6a4db94011d3 | 696 | HAL_PCD_ISOOUTIncompleteCallback(hpcd, epnum); |
sahilmgandhi | 18:6a4db94011d3 | 697 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_PXFR_INCOMPISOOUT); |
sahilmgandhi | 18:6a4db94011d3 | 698 | } |
sahilmgandhi | 18:6a4db94011d3 | 699 | |
sahilmgandhi | 18:6a4db94011d3 | 700 | /* Handle Connection event Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 701 | if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_SRQINT)) |
sahilmgandhi | 18:6a4db94011d3 | 702 | { |
sahilmgandhi | 18:6a4db94011d3 | 703 | HAL_PCD_ConnectCallback(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 704 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_OTG_GINTSTS_SRQINT); |
sahilmgandhi | 18:6a4db94011d3 | 705 | } |
sahilmgandhi | 18:6a4db94011d3 | 706 | |
sahilmgandhi | 18:6a4db94011d3 | 707 | /* Handle Disconnection event Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 708 | if(__HAL_PCD_GET_FLAG(hpcd, USB_OTG_GINTSTS_OTGINT)) |
sahilmgandhi | 18:6a4db94011d3 | 709 | { |
sahilmgandhi | 18:6a4db94011d3 | 710 | temp = hpcd->Instance->GOTGINT; |
sahilmgandhi | 18:6a4db94011d3 | 711 | |
sahilmgandhi | 18:6a4db94011d3 | 712 | if((temp & USB_OTG_GOTGINT_SEDET) == USB_OTG_GOTGINT_SEDET) |
sahilmgandhi | 18:6a4db94011d3 | 713 | { |
sahilmgandhi | 18:6a4db94011d3 | 714 | HAL_PCD_DisconnectCallback(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 715 | } |
sahilmgandhi | 18:6a4db94011d3 | 716 | hpcd->Instance->GOTGINT |= temp; |
sahilmgandhi | 18:6a4db94011d3 | 717 | } |
sahilmgandhi | 18:6a4db94011d3 | 718 | } |
sahilmgandhi | 18:6a4db94011d3 | 719 | } |
sahilmgandhi | 18:6a4db94011d3 | 720 | |
sahilmgandhi | 18:6a4db94011d3 | 721 | /** |
sahilmgandhi | 18:6a4db94011d3 | 722 | * @brief Data OUT stage callback. |
sahilmgandhi | 18:6a4db94011d3 | 723 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 724 | * @param epnum: endpoint number |
sahilmgandhi | 18:6a4db94011d3 | 725 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 726 | */ |
sahilmgandhi | 18:6a4db94011d3 | 727 | __weak void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
sahilmgandhi | 18:6a4db94011d3 | 728 | { |
sahilmgandhi | 18:6a4db94011d3 | 729 | /* Prevent unused argument(s) compilation warning */ |
sahilmgandhi | 18:6a4db94011d3 | 730 | UNUSED(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 731 | UNUSED(epnum); |
sahilmgandhi | 18:6a4db94011d3 | 732 | /* NOTE : This function Should not be modified, when the callback is needed, |
sahilmgandhi | 18:6a4db94011d3 | 733 | the HAL_PCD_DataOutStageCallback could be implemented in the user file |
sahilmgandhi | 18:6a4db94011d3 | 734 | */ |
sahilmgandhi | 18:6a4db94011d3 | 735 | } |
sahilmgandhi | 18:6a4db94011d3 | 736 | |
sahilmgandhi | 18:6a4db94011d3 | 737 | /** |
sahilmgandhi | 18:6a4db94011d3 | 738 | * @brief Data IN stage callback. |
sahilmgandhi | 18:6a4db94011d3 | 739 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 740 | * @param epnum: endpoint number |
sahilmgandhi | 18:6a4db94011d3 | 741 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 742 | */ |
sahilmgandhi | 18:6a4db94011d3 | 743 | __weak void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
sahilmgandhi | 18:6a4db94011d3 | 744 | { |
sahilmgandhi | 18:6a4db94011d3 | 745 | /* Prevent unused argument(s) compilation warning */ |
sahilmgandhi | 18:6a4db94011d3 | 746 | UNUSED(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 747 | UNUSED(epnum); |
sahilmgandhi | 18:6a4db94011d3 | 748 | /* NOTE : This function Should not be modified, when the callback is needed, |
sahilmgandhi | 18:6a4db94011d3 | 749 | the HAL_PCD_DataInStageCallback could be implemented in the user file |
sahilmgandhi | 18:6a4db94011d3 | 750 | */ |
sahilmgandhi | 18:6a4db94011d3 | 751 | } |
sahilmgandhi | 18:6a4db94011d3 | 752 | /** |
sahilmgandhi | 18:6a4db94011d3 | 753 | * @brief Setup stage callback. |
sahilmgandhi | 18:6a4db94011d3 | 754 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 755 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 756 | */ |
sahilmgandhi | 18:6a4db94011d3 | 757 | __weak void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) |
sahilmgandhi | 18:6a4db94011d3 | 758 | { |
sahilmgandhi | 18:6a4db94011d3 | 759 | /* Prevent unused argument(s) compilation warning */ |
sahilmgandhi | 18:6a4db94011d3 | 760 | UNUSED(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 761 | /* NOTE : This function Should not be modified, when the callback is needed, |
sahilmgandhi | 18:6a4db94011d3 | 762 | the HAL_PCD_SetupStageCallback could be implemented in the user file |
sahilmgandhi | 18:6a4db94011d3 | 763 | */ |
sahilmgandhi | 18:6a4db94011d3 | 764 | } |
sahilmgandhi | 18:6a4db94011d3 | 765 | |
sahilmgandhi | 18:6a4db94011d3 | 766 | /** |
sahilmgandhi | 18:6a4db94011d3 | 767 | * @brief USB Start Of Frame callback. |
sahilmgandhi | 18:6a4db94011d3 | 768 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 769 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 770 | */ |
sahilmgandhi | 18:6a4db94011d3 | 771 | __weak void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) |
sahilmgandhi | 18:6a4db94011d3 | 772 | { |
sahilmgandhi | 18:6a4db94011d3 | 773 | /* Prevent unused argument(s) compilation warning */ |
sahilmgandhi | 18:6a4db94011d3 | 774 | UNUSED(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 775 | /* NOTE : This function Should not be modified, when the callback is needed, |
sahilmgandhi | 18:6a4db94011d3 | 776 | the HAL_PCD_SOFCallback could be implemented in the user file |
sahilmgandhi | 18:6a4db94011d3 | 777 | */ |
sahilmgandhi | 18:6a4db94011d3 | 778 | } |
sahilmgandhi | 18:6a4db94011d3 | 779 | |
sahilmgandhi | 18:6a4db94011d3 | 780 | /** |
sahilmgandhi | 18:6a4db94011d3 | 781 | * @brief USB Reset callback. |
sahilmgandhi | 18:6a4db94011d3 | 782 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 783 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 784 | */ |
sahilmgandhi | 18:6a4db94011d3 | 785 | __weak void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd) |
sahilmgandhi | 18:6a4db94011d3 | 786 | { |
sahilmgandhi | 18:6a4db94011d3 | 787 | /* Prevent unused argument(s) compilation warning */ |
sahilmgandhi | 18:6a4db94011d3 | 788 | UNUSED(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 789 | /* NOTE : This function Should not be modified, when the callback is needed, |
sahilmgandhi | 18:6a4db94011d3 | 790 | the HAL_PCD_ResetCallback could be implemented in the user file |
sahilmgandhi | 18:6a4db94011d3 | 791 | */ |
sahilmgandhi | 18:6a4db94011d3 | 792 | } |
sahilmgandhi | 18:6a4db94011d3 | 793 | |
sahilmgandhi | 18:6a4db94011d3 | 794 | /** |
sahilmgandhi | 18:6a4db94011d3 | 795 | * @brief Suspend event callback. |
sahilmgandhi | 18:6a4db94011d3 | 796 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 797 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 798 | */ |
sahilmgandhi | 18:6a4db94011d3 | 799 | __weak void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) |
sahilmgandhi | 18:6a4db94011d3 | 800 | { |
sahilmgandhi | 18:6a4db94011d3 | 801 | /* Prevent unused argument(s) compilation warning */ |
sahilmgandhi | 18:6a4db94011d3 | 802 | UNUSED(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 803 | /* NOTE : This function Should not be modified, when the callback is needed, |
sahilmgandhi | 18:6a4db94011d3 | 804 | the HAL_PCD_SuspendCallback could be implemented in the user file |
sahilmgandhi | 18:6a4db94011d3 | 805 | */ |
sahilmgandhi | 18:6a4db94011d3 | 806 | } |
sahilmgandhi | 18:6a4db94011d3 | 807 | |
sahilmgandhi | 18:6a4db94011d3 | 808 | /** |
sahilmgandhi | 18:6a4db94011d3 | 809 | * @brief Resume event callback. |
sahilmgandhi | 18:6a4db94011d3 | 810 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 811 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 812 | */ |
sahilmgandhi | 18:6a4db94011d3 | 813 | __weak void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) |
sahilmgandhi | 18:6a4db94011d3 | 814 | { |
sahilmgandhi | 18:6a4db94011d3 | 815 | /* Prevent unused argument(s) compilation warning */ |
sahilmgandhi | 18:6a4db94011d3 | 816 | UNUSED(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 817 | /* NOTE : This function Should not be modified, when the callback is needed, |
sahilmgandhi | 18:6a4db94011d3 | 818 | the HAL_PCD_ResumeCallback could be implemented in the user file |
sahilmgandhi | 18:6a4db94011d3 | 819 | */ |
sahilmgandhi | 18:6a4db94011d3 | 820 | } |
sahilmgandhi | 18:6a4db94011d3 | 821 | |
sahilmgandhi | 18:6a4db94011d3 | 822 | /** |
sahilmgandhi | 18:6a4db94011d3 | 823 | * @brief Incomplete ISO OUT callback. |
sahilmgandhi | 18:6a4db94011d3 | 824 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 825 | * @param epnum: endpoint number |
sahilmgandhi | 18:6a4db94011d3 | 826 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 827 | */ |
sahilmgandhi | 18:6a4db94011d3 | 828 | __weak void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
sahilmgandhi | 18:6a4db94011d3 | 829 | { |
sahilmgandhi | 18:6a4db94011d3 | 830 | /* Prevent unused argument(s) compilation warning */ |
sahilmgandhi | 18:6a4db94011d3 | 831 | UNUSED(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 832 | UNUSED(epnum); |
sahilmgandhi | 18:6a4db94011d3 | 833 | /* NOTE : This function Should not be modified, when the callback is needed, |
sahilmgandhi | 18:6a4db94011d3 | 834 | the HAL_PCD_ISOOUTIncompleteCallback could be implemented in the user file |
sahilmgandhi | 18:6a4db94011d3 | 835 | */ |
sahilmgandhi | 18:6a4db94011d3 | 836 | } |
sahilmgandhi | 18:6a4db94011d3 | 837 | |
sahilmgandhi | 18:6a4db94011d3 | 838 | /** |
sahilmgandhi | 18:6a4db94011d3 | 839 | * @brief Incomplete ISO IN callback. |
sahilmgandhi | 18:6a4db94011d3 | 840 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 841 | * @param epnum: endpoint number |
sahilmgandhi | 18:6a4db94011d3 | 842 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 843 | */ |
sahilmgandhi | 18:6a4db94011d3 | 844 | __weak void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
sahilmgandhi | 18:6a4db94011d3 | 845 | { |
sahilmgandhi | 18:6a4db94011d3 | 846 | /* Prevent unused argument(s) compilation warning */ |
sahilmgandhi | 18:6a4db94011d3 | 847 | UNUSED(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 848 | UNUSED(epnum); |
sahilmgandhi | 18:6a4db94011d3 | 849 | /* NOTE : This function Should not be modified, when the callback is needed, |
sahilmgandhi | 18:6a4db94011d3 | 850 | the HAL_PCD_ISOINIncompleteCallback could be implemented in the user file |
sahilmgandhi | 18:6a4db94011d3 | 851 | */ |
sahilmgandhi | 18:6a4db94011d3 | 852 | } |
sahilmgandhi | 18:6a4db94011d3 | 853 | |
sahilmgandhi | 18:6a4db94011d3 | 854 | /** |
sahilmgandhi | 18:6a4db94011d3 | 855 | * @brief Connection event callback. |
sahilmgandhi | 18:6a4db94011d3 | 856 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 857 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 858 | */ |
sahilmgandhi | 18:6a4db94011d3 | 859 | __weak void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) |
sahilmgandhi | 18:6a4db94011d3 | 860 | { |
sahilmgandhi | 18:6a4db94011d3 | 861 | /* Prevent unused argument(s) compilation warning */ |
sahilmgandhi | 18:6a4db94011d3 | 862 | UNUSED(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 863 | /* NOTE : This function Should not be modified, when the callback is needed, |
sahilmgandhi | 18:6a4db94011d3 | 864 | the HAL_PCD_ConnectCallback could be implemented in the user file |
sahilmgandhi | 18:6a4db94011d3 | 865 | */ |
sahilmgandhi | 18:6a4db94011d3 | 866 | } |
sahilmgandhi | 18:6a4db94011d3 | 867 | |
sahilmgandhi | 18:6a4db94011d3 | 868 | /** |
sahilmgandhi | 18:6a4db94011d3 | 869 | * @brief Disconnection event callback. |
sahilmgandhi | 18:6a4db94011d3 | 870 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 871 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 872 | */ |
sahilmgandhi | 18:6a4db94011d3 | 873 | __weak void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) |
sahilmgandhi | 18:6a4db94011d3 | 874 | { |
sahilmgandhi | 18:6a4db94011d3 | 875 | /* Prevent unused argument(s) compilation warning */ |
sahilmgandhi | 18:6a4db94011d3 | 876 | UNUSED(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 877 | /* NOTE : This function Should not be modified, when the callback is needed, |
sahilmgandhi | 18:6a4db94011d3 | 878 | the HAL_PCD_DisconnectCallback could be implemented in the user file |
sahilmgandhi | 18:6a4db94011d3 | 879 | */ |
sahilmgandhi | 18:6a4db94011d3 | 880 | } |
sahilmgandhi | 18:6a4db94011d3 | 881 | |
sahilmgandhi | 18:6a4db94011d3 | 882 | /** |
sahilmgandhi | 18:6a4db94011d3 | 883 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 884 | */ |
sahilmgandhi | 18:6a4db94011d3 | 885 | |
sahilmgandhi | 18:6a4db94011d3 | 886 | /** @defgroup PCD_Exported_Functions_Group3 Peripheral Control functions |
sahilmgandhi | 18:6a4db94011d3 | 887 | * @brief management functions |
sahilmgandhi | 18:6a4db94011d3 | 888 | * |
sahilmgandhi | 18:6a4db94011d3 | 889 | @verbatim |
sahilmgandhi | 18:6a4db94011d3 | 890 | =============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 891 | ##### Peripheral Control functions ##### |
sahilmgandhi | 18:6a4db94011d3 | 892 | =============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 893 | [..] |
sahilmgandhi | 18:6a4db94011d3 | 894 | This subsection provides a set of functions allowing to control the PCD data |
sahilmgandhi | 18:6a4db94011d3 | 895 | transfers. |
sahilmgandhi | 18:6a4db94011d3 | 896 | |
sahilmgandhi | 18:6a4db94011d3 | 897 | @endverbatim |
sahilmgandhi | 18:6a4db94011d3 | 898 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 899 | */ |
sahilmgandhi | 18:6a4db94011d3 | 900 | |
sahilmgandhi | 18:6a4db94011d3 | 901 | /** |
sahilmgandhi | 18:6a4db94011d3 | 902 | * @brief Connect the USB device. |
sahilmgandhi | 18:6a4db94011d3 | 903 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 904 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 905 | */ |
sahilmgandhi | 18:6a4db94011d3 | 906 | HAL_StatusTypeDef HAL_PCD_DevConnect(PCD_HandleTypeDef *hpcd) |
sahilmgandhi | 18:6a4db94011d3 | 907 | { |
sahilmgandhi | 18:6a4db94011d3 | 908 | __HAL_LOCK(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 909 | USB_DevConnect(hpcd->Instance); |
sahilmgandhi | 18:6a4db94011d3 | 910 | __HAL_UNLOCK(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 911 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 912 | } |
sahilmgandhi | 18:6a4db94011d3 | 913 | |
sahilmgandhi | 18:6a4db94011d3 | 914 | /** |
sahilmgandhi | 18:6a4db94011d3 | 915 | * @brief Disconnect the USB device. |
sahilmgandhi | 18:6a4db94011d3 | 916 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 917 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 918 | */ |
sahilmgandhi | 18:6a4db94011d3 | 919 | HAL_StatusTypeDef HAL_PCD_DevDisconnect(PCD_HandleTypeDef *hpcd) |
sahilmgandhi | 18:6a4db94011d3 | 920 | { |
sahilmgandhi | 18:6a4db94011d3 | 921 | __HAL_LOCK(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 922 | USB_DevDisconnect(hpcd->Instance); |
sahilmgandhi | 18:6a4db94011d3 | 923 | __HAL_UNLOCK(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 924 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 925 | } |
sahilmgandhi | 18:6a4db94011d3 | 926 | |
sahilmgandhi | 18:6a4db94011d3 | 927 | /** |
sahilmgandhi | 18:6a4db94011d3 | 928 | * @brief Set the USB Device address. |
sahilmgandhi | 18:6a4db94011d3 | 929 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 930 | * @param address: new device address |
sahilmgandhi | 18:6a4db94011d3 | 931 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 932 | */ |
sahilmgandhi | 18:6a4db94011d3 | 933 | HAL_StatusTypeDef HAL_PCD_SetAddress(PCD_HandleTypeDef *hpcd, uint8_t address) |
sahilmgandhi | 18:6a4db94011d3 | 934 | { |
sahilmgandhi | 18:6a4db94011d3 | 935 | __HAL_LOCK(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 936 | USB_SetDevAddress(hpcd->Instance, address); |
sahilmgandhi | 18:6a4db94011d3 | 937 | __HAL_UNLOCK(hpcd); |
sahilmgandhi | 18:6a4db94011d3 | 938 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 939 | } |
sahilmgandhi | 18:6a4db94011d3 | 940 | /** |
sahilmgandhi | 18:6a4db94011d3 | 941 | * @brief Open and configure an endpoint. |
sahilmgandhi | 18:6a4db94011d3 | 942 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 943 | * @param ep_addr: endpoint address |
sahilmgandhi | 18:6a4db94011d3 | 944 | * @param ep_mps: endpoint max packet size |
sahilmgandhi | 18:6a4db94011d3 | 945 | * @param ep_type: endpoint type |
sahilmgandhi | 18:6a4db94011d3 | 946 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 947 | */ |
sahilmgandhi | 18:6a4db94011d3 | 948 | HAL_StatusTypeDef HAL_PCD_EP_Open(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type) |
sahilmgandhi | 18:6a4db94011d3 | 949 | { |
sahilmgandhi | 18:6a4db94011d3 | 950 | HAL_StatusTypeDef ret = HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 951 | USB_OTG_EPTypeDef *ep; |
sahilmgandhi | 18:6a4db94011d3 | 952 | |
sahilmgandhi | 18:6a4db94011d3 | 953 | if ((ep_addr & 0x80U) == 0x80U) |
sahilmgandhi | 18:6a4db94011d3 | 954 | { |
sahilmgandhi | 18:6a4db94011d3 | 955 | ep = &hpcd->IN_ep[ep_addr & 0x7FU]; |
sahilmgandhi | 18:6a4db94011d3 | 956 | } |
sahilmgandhi | 18:6a4db94011d3 | 957 | else |
sahilmgandhi | 18:6a4db94011d3 | 958 | { |
sahilmgandhi | 18:6a4db94011d3 | 959 | ep = &hpcd->OUT_ep[ep_addr & 0x7FU]; |
sahilmgandhi | 18:6a4db94011d3 | 960 | } |
sahilmgandhi | 18:6a4db94011d3 | 961 | ep->num = ep_addr & 0x7FU; |
sahilmgandhi | 18:6a4db94011d3 | 962 | |
sahilmgandhi | 18:6a4db94011d3 | 963 | ep->is_in = (0x80U & ep_addr) != 0U; |
sahilmgandhi | 18:6a4db94011d3 | 964 | ep->maxpacket = ep_mps; |
sahilmgandhi | 18:6a4db94011d3 | 965 | ep->type = ep_type; |
sahilmgandhi | 18:6a4db94011d3 | 966 | if (ep->is_in) |
sahilmgandhi | 18:6a4db94011d3 | 967 | { |
sahilmgandhi | 18:6a4db94011d3 | 968 | /* Assign a Tx FIFO */ |
sahilmgandhi | 18:6a4db94011d3 | 969 | ep->tx_fifo_num = ep->num; |
sahilmgandhi | 18:6a4db94011d3 | 970 | } |
sahilmgandhi | 18:6a4db94011d3 | 971 | /* Set initial data PID. */ |
sahilmgandhi | 18:6a4db94011d3 | 972 | if (ep_type == EP_TYPE_BULK ) |
sahilmgandhi | 18:6a4db94011d3 | 973 | { |
sahilmgandhi | 18:6a4db94011d3 | 974 | ep->data_pid_start = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 975 | } |
sahilmgandhi | 18:6a4db94011d3 | 976 | |
sahilmgandhi | 18:6a4db94011d3 | 977 | __HAL_LOCK(&hpcd->EPLock[ep_addr & 0x7FU]); |
sahilmgandhi | 18:6a4db94011d3 | 978 | USB_ActivateEndpoint(hpcd->Instance , ep); |
sahilmgandhi | 18:6a4db94011d3 | 979 | __HAL_UNLOCK(&hpcd->EPLock[ep_addr & 0x7FU]); |
sahilmgandhi | 18:6a4db94011d3 | 980 | return ret; |
sahilmgandhi | 18:6a4db94011d3 | 981 | } |
sahilmgandhi | 18:6a4db94011d3 | 982 | |
sahilmgandhi | 18:6a4db94011d3 | 983 | |
sahilmgandhi | 18:6a4db94011d3 | 984 | /** |
sahilmgandhi | 18:6a4db94011d3 | 985 | * @brief Deactivate an endpoint. |
sahilmgandhi | 18:6a4db94011d3 | 986 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 987 | * @param ep_addr: endpoint address |
sahilmgandhi | 18:6a4db94011d3 | 988 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 989 | */ |
sahilmgandhi | 18:6a4db94011d3 | 990 | HAL_StatusTypeDef HAL_PCD_EP_Close(PCD_HandleTypeDef *hpcd, uint8_t ep_addr) |
sahilmgandhi | 18:6a4db94011d3 | 991 | { |
sahilmgandhi | 18:6a4db94011d3 | 992 | USB_OTG_EPTypeDef *ep; |
sahilmgandhi | 18:6a4db94011d3 | 993 | |
sahilmgandhi | 18:6a4db94011d3 | 994 | if ((ep_addr & 0x80U) == 0x80U) |
sahilmgandhi | 18:6a4db94011d3 | 995 | { |
sahilmgandhi | 18:6a4db94011d3 | 996 | ep = &hpcd->IN_ep[ep_addr & 0x7FU]; |
sahilmgandhi | 18:6a4db94011d3 | 997 | } |
sahilmgandhi | 18:6a4db94011d3 | 998 | else |
sahilmgandhi | 18:6a4db94011d3 | 999 | { |
sahilmgandhi | 18:6a4db94011d3 | 1000 | ep = &hpcd->OUT_ep[ep_addr & 0x7FU]; |
sahilmgandhi | 18:6a4db94011d3 | 1001 | } |
sahilmgandhi | 18:6a4db94011d3 | 1002 | ep->num = ep_addr & 0x7FU; |
sahilmgandhi | 18:6a4db94011d3 | 1003 | |
sahilmgandhi | 18:6a4db94011d3 | 1004 | ep->is_in = (0x80U & ep_addr) != 0U; |
sahilmgandhi | 18:6a4db94011d3 | 1005 | |
sahilmgandhi | 18:6a4db94011d3 | 1006 | __HAL_LOCK(&hpcd->EPLock[ep_addr & 0x7FU]); |
sahilmgandhi | 18:6a4db94011d3 | 1007 | USB_DeactivateEndpoint(hpcd->Instance , ep); |
sahilmgandhi | 18:6a4db94011d3 | 1008 | __HAL_UNLOCK(&hpcd->EPLock[ep_addr & 0x7FU]); |
sahilmgandhi | 18:6a4db94011d3 | 1009 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 1010 | } |
sahilmgandhi | 18:6a4db94011d3 | 1011 | |
sahilmgandhi | 18:6a4db94011d3 | 1012 | |
sahilmgandhi | 18:6a4db94011d3 | 1013 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1014 | * @brief Receive an amount of data. |
sahilmgandhi | 18:6a4db94011d3 | 1015 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 1016 | * @param ep_addr: endpoint address |
sahilmgandhi | 18:6a4db94011d3 | 1017 | * @param pBuf: pointer to the reception buffer |
sahilmgandhi | 18:6a4db94011d3 | 1018 | * @param len: amount of data to be received |
sahilmgandhi | 18:6a4db94011d3 | 1019 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 1020 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1021 | HAL_StatusTypeDef HAL_PCD_EP_Receive(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len) |
sahilmgandhi | 18:6a4db94011d3 | 1022 | { |
sahilmgandhi | 18:6a4db94011d3 | 1023 | USB_OTG_EPTypeDef *ep; |
sahilmgandhi | 18:6a4db94011d3 | 1024 | |
sahilmgandhi | 18:6a4db94011d3 | 1025 | ep = &hpcd->OUT_ep[ep_addr & 0x7FU]; |
sahilmgandhi | 18:6a4db94011d3 | 1026 | |
sahilmgandhi | 18:6a4db94011d3 | 1027 | /*setup and start the Xfer */ |
sahilmgandhi | 18:6a4db94011d3 | 1028 | ep->xfer_buff = pBuf; |
sahilmgandhi | 18:6a4db94011d3 | 1029 | ep->xfer_len = len; |
sahilmgandhi | 18:6a4db94011d3 | 1030 | ep->xfer_count = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 1031 | ep->is_in = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 1032 | ep->num = ep_addr & 0x7FU; |
sahilmgandhi | 18:6a4db94011d3 | 1033 | |
sahilmgandhi | 18:6a4db94011d3 | 1034 | if (hpcd->Init.dma_enable == 1U) |
sahilmgandhi | 18:6a4db94011d3 | 1035 | { |
sahilmgandhi | 18:6a4db94011d3 | 1036 | ep->dma_addr = (uint32_t)pBuf; |
sahilmgandhi | 18:6a4db94011d3 | 1037 | } |
sahilmgandhi | 18:6a4db94011d3 | 1038 | |
sahilmgandhi | 18:6a4db94011d3 | 1039 | __HAL_LOCK(&hpcd->EPLock[ep_addr & 0x7FU]); |
sahilmgandhi | 18:6a4db94011d3 | 1040 | |
sahilmgandhi | 18:6a4db94011d3 | 1041 | if ((ep_addr & 0x7FU) == 0U) |
sahilmgandhi | 18:6a4db94011d3 | 1042 | { |
sahilmgandhi | 18:6a4db94011d3 | 1043 | USB_EP0StartXfer(hpcd->Instance , ep, hpcd->Init.dma_enable); |
sahilmgandhi | 18:6a4db94011d3 | 1044 | } |
sahilmgandhi | 18:6a4db94011d3 | 1045 | else |
sahilmgandhi | 18:6a4db94011d3 | 1046 | { |
sahilmgandhi | 18:6a4db94011d3 | 1047 | USB_EPStartXfer(hpcd->Instance , ep, hpcd->Init.dma_enable); |
sahilmgandhi | 18:6a4db94011d3 | 1048 | } |
sahilmgandhi | 18:6a4db94011d3 | 1049 | __HAL_UNLOCK(&hpcd->EPLock[ep_addr & 0x7FU]); |
sahilmgandhi | 18:6a4db94011d3 | 1050 | |
sahilmgandhi | 18:6a4db94011d3 | 1051 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 1052 | } |
sahilmgandhi | 18:6a4db94011d3 | 1053 | |
sahilmgandhi | 18:6a4db94011d3 | 1054 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1055 | * @brief Get Received Data Size. |
sahilmgandhi | 18:6a4db94011d3 | 1056 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 1057 | * @param ep_addr: endpoint address |
sahilmgandhi | 18:6a4db94011d3 | 1058 | * @retval Data Size |
sahilmgandhi | 18:6a4db94011d3 | 1059 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1060 | uint16_t HAL_PCD_EP_GetRxCount(PCD_HandleTypeDef *hpcd, uint8_t ep_addr) |
sahilmgandhi | 18:6a4db94011d3 | 1061 | { |
sahilmgandhi | 18:6a4db94011d3 | 1062 | return hpcd->OUT_ep[ep_addr & 0x7FU].xfer_count; |
sahilmgandhi | 18:6a4db94011d3 | 1063 | } |
sahilmgandhi | 18:6a4db94011d3 | 1064 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1065 | * @brief Send an amount of data. |
sahilmgandhi | 18:6a4db94011d3 | 1066 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 1067 | * @param ep_addr: endpoint address |
sahilmgandhi | 18:6a4db94011d3 | 1068 | * @param pBuf: pointer to the transmission buffer |
sahilmgandhi | 18:6a4db94011d3 | 1069 | * @param len: amount of data to be sent |
sahilmgandhi | 18:6a4db94011d3 | 1070 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 1071 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1072 | HAL_StatusTypeDef HAL_PCD_EP_Transmit(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len) |
sahilmgandhi | 18:6a4db94011d3 | 1073 | { |
sahilmgandhi | 18:6a4db94011d3 | 1074 | USB_OTG_EPTypeDef *ep; |
sahilmgandhi | 18:6a4db94011d3 | 1075 | |
sahilmgandhi | 18:6a4db94011d3 | 1076 | ep = &hpcd->IN_ep[ep_addr & 0x7FU]; |
sahilmgandhi | 18:6a4db94011d3 | 1077 | |
sahilmgandhi | 18:6a4db94011d3 | 1078 | /*setup and start the Xfer */ |
sahilmgandhi | 18:6a4db94011d3 | 1079 | ep->xfer_buff = pBuf; |
sahilmgandhi | 18:6a4db94011d3 | 1080 | ep->xfer_len = len; |
sahilmgandhi | 18:6a4db94011d3 | 1081 | ep->xfer_count = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 1082 | ep->is_in = 1U; |
sahilmgandhi | 18:6a4db94011d3 | 1083 | ep->num = ep_addr & 0x7FU; |
sahilmgandhi | 18:6a4db94011d3 | 1084 | |
sahilmgandhi | 18:6a4db94011d3 | 1085 | if (hpcd->Init.dma_enable == 1U) |
sahilmgandhi | 18:6a4db94011d3 | 1086 | { |
sahilmgandhi | 18:6a4db94011d3 | 1087 | ep->dma_addr = (uint32_t)pBuf; |
sahilmgandhi | 18:6a4db94011d3 | 1088 | } |
sahilmgandhi | 18:6a4db94011d3 | 1089 | |
sahilmgandhi | 18:6a4db94011d3 | 1090 | __HAL_LOCK(&hpcd->EPLock[ep_addr & 0x7FU]); |
sahilmgandhi | 18:6a4db94011d3 | 1091 | |
sahilmgandhi | 18:6a4db94011d3 | 1092 | if ((ep_addr & 0x7FU) == 0U) |
sahilmgandhi | 18:6a4db94011d3 | 1093 | { |
sahilmgandhi | 18:6a4db94011d3 | 1094 | USB_EP0StartXfer(hpcd->Instance , ep, hpcd->Init.dma_enable); |
sahilmgandhi | 18:6a4db94011d3 | 1095 | } |
sahilmgandhi | 18:6a4db94011d3 | 1096 | else |
sahilmgandhi | 18:6a4db94011d3 | 1097 | { |
sahilmgandhi | 18:6a4db94011d3 | 1098 | USB_EPStartXfer(hpcd->Instance , ep, hpcd->Init.dma_enable); |
sahilmgandhi | 18:6a4db94011d3 | 1099 | } |
sahilmgandhi | 18:6a4db94011d3 | 1100 | |
sahilmgandhi | 18:6a4db94011d3 | 1101 | __HAL_UNLOCK(&hpcd->EPLock[ep_addr & 0x7FU]); |
sahilmgandhi | 18:6a4db94011d3 | 1102 | |
sahilmgandhi | 18:6a4db94011d3 | 1103 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 1104 | } |
sahilmgandhi | 18:6a4db94011d3 | 1105 | |
sahilmgandhi | 18:6a4db94011d3 | 1106 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1107 | * @brief Set a STALL condition over an endpoint. |
sahilmgandhi | 18:6a4db94011d3 | 1108 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 1109 | * @param ep_addr: endpoint address |
sahilmgandhi | 18:6a4db94011d3 | 1110 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 1111 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1112 | HAL_StatusTypeDef HAL_PCD_EP_SetStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr) |
sahilmgandhi | 18:6a4db94011d3 | 1113 | { |
sahilmgandhi | 18:6a4db94011d3 | 1114 | USB_OTG_EPTypeDef *ep; |
sahilmgandhi | 18:6a4db94011d3 | 1115 | |
sahilmgandhi | 18:6a4db94011d3 | 1116 | if ((0x80U & ep_addr) == 0x80U) |
sahilmgandhi | 18:6a4db94011d3 | 1117 | { |
sahilmgandhi | 18:6a4db94011d3 | 1118 | ep = &hpcd->IN_ep[ep_addr & 0x7FU]; |
sahilmgandhi | 18:6a4db94011d3 | 1119 | } |
sahilmgandhi | 18:6a4db94011d3 | 1120 | else |
sahilmgandhi | 18:6a4db94011d3 | 1121 | { |
sahilmgandhi | 18:6a4db94011d3 | 1122 | ep = &hpcd->OUT_ep[ep_addr]; |
sahilmgandhi | 18:6a4db94011d3 | 1123 | } |
sahilmgandhi | 18:6a4db94011d3 | 1124 | |
sahilmgandhi | 18:6a4db94011d3 | 1125 | ep->is_stall = 1U; |
sahilmgandhi | 18:6a4db94011d3 | 1126 | ep->num = ep_addr & 0x7FU; |
sahilmgandhi | 18:6a4db94011d3 | 1127 | ep->is_in = ((ep_addr & 0x80U) == 0x80U); |
sahilmgandhi | 18:6a4db94011d3 | 1128 | |
sahilmgandhi | 18:6a4db94011d3 | 1129 | |
sahilmgandhi | 18:6a4db94011d3 | 1130 | __HAL_LOCK(&hpcd->EPLock[ep_addr & 0x7FU]); |
sahilmgandhi | 18:6a4db94011d3 | 1131 | USB_EPSetStall(hpcd->Instance , ep); |
sahilmgandhi | 18:6a4db94011d3 | 1132 | if((ep_addr & 0x7FU) == 0U) |
sahilmgandhi | 18:6a4db94011d3 | 1133 | { |
sahilmgandhi | 18:6a4db94011d3 | 1134 | USB_EP0_OutStart(hpcd->Instance, hpcd->Init.dma_enable, (uint8_t *)hpcd->Setup); |
sahilmgandhi | 18:6a4db94011d3 | 1135 | } |
sahilmgandhi | 18:6a4db94011d3 | 1136 | __HAL_UNLOCK(&hpcd->EPLock[ep_addr & 0x7FU]); |
sahilmgandhi | 18:6a4db94011d3 | 1137 | |
sahilmgandhi | 18:6a4db94011d3 | 1138 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 1139 | } |
sahilmgandhi | 18:6a4db94011d3 | 1140 | |
sahilmgandhi | 18:6a4db94011d3 | 1141 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1142 | * @brief Clear a STALL condition over in an endpoint. |
sahilmgandhi | 18:6a4db94011d3 | 1143 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 1144 | * @param ep_addr: endpoint address |
sahilmgandhi | 18:6a4db94011d3 | 1145 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 1146 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1147 | HAL_StatusTypeDef HAL_PCD_EP_ClrStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr) |
sahilmgandhi | 18:6a4db94011d3 | 1148 | { |
sahilmgandhi | 18:6a4db94011d3 | 1149 | USB_OTG_EPTypeDef *ep; |
sahilmgandhi | 18:6a4db94011d3 | 1150 | |
sahilmgandhi | 18:6a4db94011d3 | 1151 | if ((0x80U & ep_addr) == 0x80U) |
sahilmgandhi | 18:6a4db94011d3 | 1152 | { |
sahilmgandhi | 18:6a4db94011d3 | 1153 | ep = &hpcd->IN_ep[ep_addr & 0x7FU]; |
sahilmgandhi | 18:6a4db94011d3 | 1154 | } |
sahilmgandhi | 18:6a4db94011d3 | 1155 | else |
sahilmgandhi | 18:6a4db94011d3 | 1156 | { |
sahilmgandhi | 18:6a4db94011d3 | 1157 | ep = &hpcd->OUT_ep[ep_addr]; |
sahilmgandhi | 18:6a4db94011d3 | 1158 | } |
sahilmgandhi | 18:6a4db94011d3 | 1159 | |
sahilmgandhi | 18:6a4db94011d3 | 1160 | ep->is_stall = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 1161 | ep->num = ep_addr & 0x7FU; |
sahilmgandhi | 18:6a4db94011d3 | 1162 | ep->is_in = ((ep_addr & 0x80U) == 0x80U); |
sahilmgandhi | 18:6a4db94011d3 | 1163 | |
sahilmgandhi | 18:6a4db94011d3 | 1164 | __HAL_LOCK(&hpcd->EPLock[ep_addr & 0x7FU]); |
sahilmgandhi | 18:6a4db94011d3 | 1165 | USB_EPClearStall(hpcd->Instance , ep); |
sahilmgandhi | 18:6a4db94011d3 | 1166 | __HAL_UNLOCK(&hpcd->EPLock[ep_addr & 0x7FU]); |
sahilmgandhi | 18:6a4db94011d3 | 1167 | |
sahilmgandhi | 18:6a4db94011d3 | 1168 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 1169 | } |
sahilmgandhi | 18:6a4db94011d3 | 1170 | |
sahilmgandhi | 18:6a4db94011d3 | 1171 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1172 | * @brief Flush an endpoint. |
sahilmgandhi | 18:6a4db94011d3 | 1173 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 1174 | * @param ep_addr: endpoint address |
sahilmgandhi | 18:6a4db94011d3 | 1175 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 1176 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1177 | HAL_StatusTypeDef HAL_PCD_EP_Flush(PCD_HandleTypeDef *hpcd, uint8_t ep_addr) |
sahilmgandhi | 18:6a4db94011d3 | 1178 | { |
sahilmgandhi | 18:6a4db94011d3 | 1179 | __HAL_LOCK(&hpcd->EPLock[ep_addr & 0x7FU]); |
sahilmgandhi | 18:6a4db94011d3 | 1180 | if ((ep_addr & 0x80U) == 0x80U) |
sahilmgandhi | 18:6a4db94011d3 | 1181 | { |
sahilmgandhi | 18:6a4db94011d3 | 1182 | USB_FlushTxFifo(hpcd->Instance, ep_addr & 0x7FU); |
sahilmgandhi | 18:6a4db94011d3 | 1183 | } |
sahilmgandhi | 18:6a4db94011d3 | 1184 | else |
sahilmgandhi | 18:6a4db94011d3 | 1185 | { |
sahilmgandhi | 18:6a4db94011d3 | 1186 | USB_FlushRxFifo(hpcd->Instance); |
sahilmgandhi | 18:6a4db94011d3 | 1187 | } |
sahilmgandhi | 18:6a4db94011d3 | 1188 | |
sahilmgandhi | 18:6a4db94011d3 | 1189 | __HAL_UNLOCK(&hpcd->EPLock[ep_addr & 0x7FU]); |
sahilmgandhi | 18:6a4db94011d3 | 1190 | |
sahilmgandhi | 18:6a4db94011d3 | 1191 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 1192 | } |
sahilmgandhi | 18:6a4db94011d3 | 1193 | |
sahilmgandhi | 18:6a4db94011d3 | 1194 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1195 | * @brief Activate remote wakeup signalling. |
sahilmgandhi | 18:6a4db94011d3 | 1196 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 1197 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 1198 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1199 | HAL_StatusTypeDef HAL_PCD_ActivateRemoteWakeup(PCD_HandleTypeDef *hpcd) |
sahilmgandhi | 18:6a4db94011d3 | 1200 | { |
sahilmgandhi | 18:6a4db94011d3 | 1201 | USB_OTG_GlobalTypeDef *USBx = hpcd->Instance; |
sahilmgandhi | 18:6a4db94011d3 | 1202 | |
sahilmgandhi | 18:6a4db94011d3 | 1203 | if((USBx_DEVICE->DSTS & USB_OTG_DSTS_SUSPSTS) == USB_OTG_DSTS_SUSPSTS) |
sahilmgandhi | 18:6a4db94011d3 | 1204 | { |
sahilmgandhi | 18:6a4db94011d3 | 1205 | /* Activate Remote wakeup signaling */ |
sahilmgandhi | 18:6a4db94011d3 | 1206 | USBx_DEVICE->DCTL |= USB_OTG_DCTL_RWUSIG; |
sahilmgandhi | 18:6a4db94011d3 | 1207 | } |
sahilmgandhi | 18:6a4db94011d3 | 1208 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 1209 | } |
sahilmgandhi | 18:6a4db94011d3 | 1210 | |
sahilmgandhi | 18:6a4db94011d3 | 1211 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1212 | * @brief De-activate remote wakeup signalling. |
sahilmgandhi | 18:6a4db94011d3 | 1213 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 1214 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 1215 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1216 | HAL_StatusTypeDef HAL_PCD_DeActivateRemoteWakeup(PCD_HandleTypeDef *hpcd) |
sahilmgandhi | 18:6a4db94011d3 | 1217 | { |
sahilmgandhi | 18:6a4db94011d3 | 1218 | USB_OTG_GlobalTypeDef *USBx = hpcd->Instance; |
sahilmgandhi | 18:6a4db94011d3 | 1219 | |
sahilmgandhi | 18:6a4db94011d3 | 1220 | /* De-activate Remote wakeup signaling */ |
sahilmgandhi | 18:6a4db94011d3 | 1221 | USBx_DEVICE->DCTL &= ~(USB_OTG_DCTL_RWUSIG); |
sahilmgandhi | 18:6a4db94011d3 | 1222 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 1223 | } |
sahilmgandhi | 18:6a4db94011d3 | 1224 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1225 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 1226 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1227 | |
sahilmgandhi | 18:6a4db94011d3 | 1228 | /** @defgroup PCD_Exported_Functions_Group4 Peripheral State functions |
sahilmgandhi | 18:6a4db94011d3 | 1229 | * @brief Peripheral State functions |
sahilmgandhi | 18:6a4db94011d3 | 1230 | * |
sahilmgandhi | 18:6a4db94011d3 | 1231 | @verbatim |
sahilmgandhi | 18:6a4db94011d3 | 1232 | =============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 1233 | ##### Peripheral State functions ##### |
sahilmgandhi | 18:6a4db94011d3 | 1234 | =============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 1235 | [..] |
sahilmgandhi | 18:6a4db94011d3 | 1236 | This subsection permits to get in run-time the status of the peripheral |
sahilmgandhi | 18:6a4db94011d3 | 1237 | and the data flow. |
sahilmgandhi | 18:6a4db94011d3 | 1238 | |
sahilmgandhi | 18:6a4db94011d3 | 1239 | @endverbatim |
sahilmgandhi | 18:6a4db94011d3 | 1240 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 1241 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1242 | |
sahilmgandhi | 18:6a4db94011d3 | 1243 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1244 | * @brief Return the PCD handle state. |
sahilmgandhi | 18:6a4db94011d3 | 1245 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 1246 | * @retval HAL state |
sahilmgandhi | 18:6a4db94011d3 | 1247 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1248 | PCD_StateTypeDef HAL_PCD_GetState(PCD_HandleTypeDef *hpcd) |
sahilmgandhi | 18:6a4db94011d3 | 1249 | { |
sahilmgandhi | 18:6a4db94011d3 | 1250 | return hpcd->State; |
sahilmgandhi | 18:6a4db94011d3 | 1251 | } |
sahilmgandhi | 18:6a4db94011d3 | 1252 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1253 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 1254 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1255 | |
sahilmgandhi | 18:6a4db94011d3 | 1256 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1257 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 1258 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1259 | |
sahilmgandhi | 18:6a4db94011d3 | 1260 | /* Private functions ---------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 1261 | /** @addtogroup PCD_Private_Functions |
sahilmgandhi | 18:6a4db94011d3 | 1262 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 1263 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1264 | |
sahilmgandhi | 18:6a4db94011d3 | 1265 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1266 | * @brief Check FIFO for the next packet to be loaded. |
sahilmgandhi | 18:6a4db94011d3 | 1267 | * @param hpcd: PCD handle |
sahilmgandhi | 18:6a4db94011d3 | 1268 | * @param epnum : endpoint number |
sahilmgandhi | 18:6a4db94011d3 | 1269 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 1270 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1271 | static HAL_StatusTypeDef PCD_WriteEmptyTxFifo(PCD_HandleTypeDef *hpcd, uint32_t epnum) |
sahilmgandhi | 18:6a4db94011d3 | 1272 | { |
sahilmgandhi | 18:6a4db94011d3 | 1273 | USB_OTG_GlobalTypeDef *USBx = hpcd->Instance; |
sahilmgandhi | 18:6a4db94011d3 | 1274 | USB_OTG_EPTypeDef *ep; |
sahilmgandhi | 18:6a4db94011d3 | 1275 | int32_t len = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 1276 | uint32_t len32b; |
sahilmgandhi | 18:6a4db94011d3 | 1277 | uint32_t fifoemptymsk = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 1278 | |
sahilmgandhi | 18:6a4db94011d3 | 1279 | ep = &hpcd->IN_ep[epnum]; |
sahilmgandhi | 18:6a4db94011d3 | 1280 | len = ep->xfer_len - ep->xfer_count; |
sahilmgandhi | 18:6a4db94011d3 | 1281 | |
sahilmgandhi | 18:6a4db94011d3 | 1282 | if (len > ep->maxpacket) |
sahilmgandhi | 18:6a4db94011d3 | 1283 | { |
sahilmgandhi | 18:6a4db94011d3 | 1284 | len = ep->maxpacket; |
sahilmgandhi | 18:6a4db94011d3 | 1285 | } |
sahilmgandhi | 18:6a4db94011d3 | 1286 | |
sahilmgandhi | 18:6a4db94011d3 | 1287 | |
sahilmgandhi | 18:6a4db94011d3 | 1288 | len32b = (len + 3U) / 4U; |
sahilmgandhi | 18:6a4db94011d3 | 1289 | |
sahilmgandhi | 18:6a4db94011d3 | 1290 | while ( (USBx_INEP(epnum)->DTXFSTS & USB_OTG_DTXFSTS_INEPTFSAV) > len32b && |
sahilmgandhi | 18:6a4db94011d3 | 1291 | ep->xfer_count < ep->xfer_len && |
sahilmgandhi | 18:6a4db94011d3 | 1292 | ep->xfer_len != 0U) |
sahilmgandhi | 18:6a4db94011d3 | 1293 | { |
sahilmgandhi | 18:6a4db94011d3 | 1294 | /* Write the FIFO */ |
sahilmgandhi | 18:6a4db94011d3 | 1295 | len = ep->xfer_len - ep->xfer_count; |
sahilmgandhi | 18:6a4db94011d3 | 1296 | |
sahilmgandhi | 18:6a4db94011d3 | 1297 | if (len > ep->maxpacket) |
sahilmgandhi | 18:6a4db94011d3 | 1298 | { |
sahilmgandhi | 18:6a4db94011d3 | 1299 | len = ep->maxpacket; |
sahilmgandhi | 18:6a4db94011d3 | 1300 | } |
sahilmgandhi | 18:6a4db94011d3 | 1301 | len32b = (len + 3U) / 4U; |
sahilmgandhi | 18:6a4db94011d3 | 1302 | |
sahilmgandhi | 18:6a4db94011d3 | 1303 | USB_WritePacket(USBx, ep->xfer_buff, epnum, len, hpcd->Init.dma_enable); |
sahilmgandhi | 18:6a4db94011d3 | 1304 | |
sahilmgandhi | 18:6a4db94011d3 | 1305 | ep->xfer_buff += len; |
sahilmgandhi | 18:6a4db94011d3 | 1306 | ep->xfer_count += len; |
sahilmgandhi | 18:6a4db94011d3 | 1307 | } |
sahilmgandhi | 18:6a4db94011d3 | 1308 | |
sahilmgandhi | 18:6a4db94011d3 | 1309 | if(len <= 0U) |
sahilmgandhi | 18:6a4db94011d3 | 1310 | { |
sahilmgandhi | 18:6a4db94011d3 | 1311 | fifoemptymsk = 0x1U << epnum; |
sahilmgandhi | 18:6a4db94011d3 | 1312 | atomic_clr_u32(&USBx_DEVICE->DIEPEMPMSK, fifoemptymsk); |
sahilmgandhi | 18:6a4db94011d3 | 1313 | } |
sahilmgandhi | 18:6a4db94011d3 | 1314 | |
sahilmgandhi | 18:6a4db94011d3 | 1315 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 1316 | } |
sahilmgandhi | 18:6a4db94011d3 | 1317 | |
sahilmgandhi | 18:6a4db94011d3 | 1318 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1319 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 1320 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1321 | #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || |
sahilmgandhi | 18:6a4db94011d3 | 1322 | STM32F401xC || STM32F401xE || STM32F411xE || STM32F446xx || STM32F469xx || STM32F479xx || STM32F412Zx || STM32F412Rx || |
sahilmgandhi | 18:6a4db94011d3 | 1323 | STM32F412Vx || STM32F412Cx */ |
sahilmgandhi | 18:6a4db94011d3 | 1324 | #endif /* HAL_PCD_MODULE_ENABLED */ |
sahilmgandhi | 18:6a4db94011d3 | 1325 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1326 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 1327 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1328 | |
sahilmgandhi | 18:6a4db94011d3 | 1329 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1330 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 1331 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1332 | |
sahilmgandhi | 18:6a4db94011d3 | 1333 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |