mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
targets/TARGET_STM/TARGET_STM32L1/device/stm32l1xx_hal_pcd.c@149:156823d33999, 2016-10-28 (annotated)
- Committer:
- <>
- Date:
- Fri Oct 28 11:17:30 2016 +0100
- Revision:
- 149:156823d33999
- Child:
- 184:08ed48f1de7f
This updates the lib to the mbed lib v128
NOTE: This release includes a restructuring of the file and directory locations and thus some
include paths in your code may need updating accordingly.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 149:156823d33999 | 1 | /** |
<> | 149:156823d33999 | 2 | ****************************************************************************** |
<> | 149:156823d33999 | 3 | * @file stm32l1xx_hal_pcd.c |
<> | 149:156823d33999 | 4 | * @author MCD Application Team |
<> | 149:156823d33999 | 5 | * @version V1.2.0 |
<> | 149:156823d33999 | 6 | * @date 01-July-2016 |
<> | 149:156823d33999 | 7 | * @brief PCD HAL module driver. |
<> | 149:156823d33999 | 8 | * This file provides firmware functions to manage the following |
<> | 149:156823d33999 | 9 | * functionalities of the USB Peripheral Controller: |
<> | 149:156823d33999 | 10 | * + Initialization and de-initialization functions |
<> | 149:156823d33999 | 11 | * + IO operation functions |
<> | 149:156823d33999 | 12 | * + Peripheral Control functions |
<> | 149:156823d33999 | 13 | * + Peripheral State functions |
<> | 149:156823d33999 | 14 | * |
<> | 149:156823d33999 | 15 | @verbatim |
<> | 149:156823d33999 | 16 | ============================================================================== |
<> | 149:156823d33999 | 17 | ##### How to use this driver ##### |
<> | 149:156823d33999 | 18 | ============================================================================== |
<> | 149:156823d33999 | 19 | [..] |
<> | 149:156823d33999 | 20 | The PCD HAL driver can be used as follows: |
<> | 149:156823d33999 | 21 | |
<> | 149:156823d33999 | 22 | (#) Declare a PCD_HandleTypeDef handle structure, for example: |
<> | 149:156823d33999 | 23 | PCD_HandleTypeDef hpcd; |
<> | 149:156823d33999 | 24 | |
<> | 149:156823d33999 | 25 | (#) Fill parameters of Init structure in HCD handle |
<> | 149:156823d33999 | 26 | |
<> | 149:156823d33999 | 27 | (#) Call HAL_PCD_Init() API to initialize the HCD peripheral (Core, Device core, ...) |
<> | 149:156823d33999 | 28 | |
<> | 149:156823d33999 | 29 | (#) Initialize the PCD low level resources through the HAL_PCD_MspInit() API: |
<> | 149:156823d33999 | 30 | (##) Enable the PCD/USB Low Level interface clock using |
<> | 149:156823d33999 | 31 | (+++) __HAL_RCC_USB_CLK_ENABLE); |
<> | 149:156823d33999 | 32 | |
<> | 149:156823d33999 | 33 | (##) Initialize the related GPIO clocks |
<> | 149:156823d33999 | 34 | (##) Configure PCD pin-out |
<> | 149:156823d33999 | 35 | (##) Configure PCD NVIC interrupt |
<> | 149:156823d33999 | 36 | |
<> | 149:156823d33999 | 37 | (#)Associate the Upper USB device stack to the HAL PCD Driver: |
<> | 149:156823d33999 | 38 | (##) hpcd.pData = pdev; |
<> | 149:156823d33999 | 39 | |
<> | 149:156823d33999 | 40 | (#)Enable HCD transmission and reception: |
<> | 149:156823d33999 | 41 | (##) HAL_PCD_Start(); |
<> | 149:156823d33999 | 42 | |
<> | 149:156823d33999 | 43 | @endverbatim |
<> | 149:156823d33999 | 44 | ****************************************************************************** |
<> | 149:156823d33999 | 45 | * @attention |
<> | 149:156823d33999 | 46 | * |
<> | 149:156823d33999 | 47 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
<> | 149:156823d33999 | 48 | * |
<> | 149:156823d33999 | 49 | * Redistribution and use in source and binary forms, with or without modification, |
<> | 149:156823d33999 | 50 | * are permitted provided that the following conditions are met: |
<> | 149:156823d33999 | 51 | * 1. Redistributions of source code must retain the above copyright notice, |
<> | 149:156823d33999 | 52 | * this list of conditions and the following disclaimer. |
<> | 149:156823d33999 | 53 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
<> | 149:156823d33999 | 54 | * this list of conditions and the following disclaimer in the documentation |
<> | 149:156823d33999 | 55 | * and/or other materials provided with the distribution. |
<> | 149:156823d33999 | 56 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
<> | 149:156823d33999 | 57 | * may be used to endorse or promote products derived from this software |
<> | 149:156823d33999 | 58 | * without specific prior written permission. |
<> | 149:156823d33999 | 59 | * |
<> | 149:156823d33999 | 60 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
<> | 149:156823d33999 | 61 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
<> | 149:156823d33999 | 62 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
<> | 149:156823d33999 | 63 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
<> | 149:156823d33999 | 64 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
<> | 149:156823d33999 | 65 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
<> | 149:156823d33999 | 66 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
<> | 149:156823d33999 | 67 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
<> | 149:156823d33999 | 68 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
<> | 149:156823d33999 | 69 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
<> | 149:156823d33999 | 70 | * |
<> | 149:156823d33999 | 71 | ****************************************************************************** |
<> | 149:156823d33999 | 72 | */ |
<> | 149:156823d33999 | 73 | |
<> | 149:156823d33999 | 74 | /* Includes ------------------------------------------------------------------*/ |
<> | 149:156823d33999 | 75 | #include "stm32l1xx_hal.h" |
<> | 149:156823d33999 | 76 | |
<> | 149:156823d33999 | 77 | /** @addtogroup STM32L1xx_HAL_Driver |
<> | 149:156823d33999 | 78 | * @{ |
<> | 149:156823d33999 | 79 | */ |
<> | 149:156823d33999 | 80 | |
<> | 149:156823d33999 | 81 | /** @defgroup PCD PCD |
<> | 149:156823d33999 | 82 | * @brief PCD HAL module driver |
<> | 149:156823d33999 | 83 | * @{ |
<> | 149:156823d33999 | 84 | */ |
<> | 149:156823d33999 | 85 | |
<> | 149:156823d33999 | 86 | #ifdef HAL_PCD_MODULE_ENABLED |
<> | 149:156823d33999 | 87 | |
<> | 149:156823d33999 | 88 | /* Private typedef -----------------------------------------------------------*/ |
<> | 149:156823d33999 | 89 | /* Private define ------------------------------------------------------------*/ |
<> | 149:156823d33999 | 90 | |
<> | 149:156823d33999 | 91 | /** @defgroup PCD_Private_Define PCD Private Define |
<> | 149:156823d33999 | 92 | * @{ |
<> | 149:156823d33999 | 93 | */ |
<> | 149:156823d33999 | 94 | #define BTABLE_ADDRESS (0x000) |
<> | 149:156823d33999 | 95 | /** |
<> | 149:156823d33999 | 96 | * @} |
<> | 149:156823d33999 | 97 | */ |
<> | 149:156823d33999 | 98 | |
<> | 149:156823d33999 | 99 | /* Private macro -------------------------------------------------------------*/ |
<> | 149:156823d33999 | 100 | /* Private variables ---------------------------------------------------------*/ |
<> | 149:156823d33999 | 101 | /* Private function prototypes -----------------------------------------------*/ |
<> | 149:156823d33999 | 102 | /** @defgroup PCD_Private_Functions PCD Private Functions |
<> | 149:156823d33999 | 103 | * @{ |
<> | 149:156823d33999 | 104 | */ |
<> | 149:156823d33999 | 105 | static HAL_StatusTypeDef PCD_EP_ISR_Handler(PCD_HandleTypeDef *hpcd); |
<> | 149:156823d33999 | 106 | static void PCD_WritePMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes); |
<> | 149:156823d33999 | 107 | static void PCD_ReadPMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes); |
<> | 149:156823d33999 | 108 | |
<> | 149:156823d33999 | 109 | /** |
<> | 149:156823d33999 | 110 | * @} |
<> | 149:156823d33999 | 111 | */ |
<> | 149:156823d33999 | 112 | |
<> | 149:156823d33999 | 113 | /* Exported functions ---------------------------------------------------------*/ |
<> | 149:156823d33999 | 114 | |
<> | 149:156823d33999 | 115 | /** @defgroup PCD_Exported_Functions PCD Exported Functions |
<> | 149:156823d33999 | 116 | * @{ |
<> | 149:156823d33999 | 117 | */ |
<> | 149:156823d33999 | 118 | |
<> | 149:156823d33999 | 119 | /** @defgroup PCD_Exported_Functions_Group1 Initialization and de-initialization functions |
<> | 149:156823d33999 | 120 | * @brief Initialization and Configuration functions |
<> | 149:156823d33999 | 121 | * |
<> | 149:156823d33999 | 122 | @verbatim |
<> | 149:156823d33999 | 123 | =============================================================================== |
<> | 149:156823d33999 | 124 | ##### Initialization and de-initialization functions ##### |
<> | 149:156823d33999 | 125 | =============================================================================== |
<> | 149:156823d33999 | 126 | [..] This section provides functions allowing to: |
<> | 149:156823d33999 | 127 | |
<> | 149:156823d33999 | 128 | @endverbatim |
<> | 149:156823d33999 | 129 | * @{ |
<> | 149:156823d33999 | 130 | */ |
<> | 149:156823d33999 | 131 | |
<> | 149:156823d33999 | 132 | /** |
<> | 149:156823d33999 | 133 | * @brief Initializes the PCD according to the specified |
<> | 149:156823d33999 | 134 | * parameters in the PCD_InitTypeDef and create the associated handle. |
<> | 149:156823d33999 | 135 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 136 | * @retval HAL status |
<> | 149:156823d33999 | 137 | */ |
<> | 149:156823d33999 | 138 | HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd) |
<> | 149:156823d33999 | 139 | { |
<> | 149:156823d33999 | 140 | uint32_t i = 0; |
<> | 149:156823d33999 | 141 | |
<> | 149:156823d33999 | 142 | uint32_t wInterrupt_Mask = 0; |
<> | 149:156823d33999 | 143 | |
<> | 149:156823d33999 | 144 | /* Check the PCD handle allocation */ |
<> | 149:156823d33999 | 145 | if(hpcd == NULL) |
<> | 149:156823d33999 | 146 | { |
<> | 149:156823d33999 | 147 | return HAL_ERROR; |
<> | 149:156823d33999 | 148 | } |
<> | 149:156823d33999 | 149 | |
<> | 149:156823d33999 | 150 | /* Check the parameters */ |
<> | 149:156823d33999 | 151 | assert_param(IS_PCD_ALL_INSTANCE(hpcd->Instance)); |
<> | 149:156823d33999 | 152 | |
<> | 149:156823d33999 | 153 | if(hpcd->State == HAL_PCD_STATE_RESET) |
<> | 149:156823d33999 | 154 | { |
<> | 149:156823d33999 | 155 | /* Allocate lock resource and initialize it */ |
<> | 149:156823d33999 | 156 | hpcd->Lock = HAL_UNLOCKED; |
<> | 149:156823d33999 | 157 | |
<> | 149:156823d33999 | 158 | /* Init the low level hardware : GPIO, CLOCK, NVIC... */ |
<> | 149:156823d33999 | 159 | HAL_PCD_MspInit(hpcd); |
<> | 149:156823d33999 | 160 | } |
<> | 149:156823d33999 | 161 | |
<> | 149:156823d33999 | 162 | hpcd->State = HAL_PCD_STATE_BUSY; |
<> | 149:156823d33999 | 163 | |
<> | 149:156823d33999 | 164 | /* Init endpoints structures */ |
<> | 149:156823d33999 | 165 | for (i = 0; i < hpcd->Init.dev_endpoints ; i++) |
<> | 149:156823d33999 | 166 | { |
<> | 149:156823d33999 | 167 | /* Init ep structure */ |
<> | 149:156823d33999 | 168 | hpcd->IN_ep[i].is_in = 1; |
<> | 149:156823d33999 | 169 | hpcd->IN_ep[i].num = i; |
<> | 149:156823d33999 | 170 | /* Control until ep is actvated */ |
<> | 149:156823d33999 | 171 | hpcd->IN_ep[i].type = PCD_EP_TYPE_CTRL; |
<> | 149:156823d33999 | 172 | hpcd->IN_ep[i].maxpacket = 0; |
<> | 149:156823d33999 | 173 | hpcd->IN_ep[i].xfer_buff = 0; |
<> | 149:156823d33999 | 174 | hpcd->IN_ep[i].xfer_len = 0; |
<> | 149:156823d33999 | 175 | } |
<> | 149:156823d33999 | 176 | |
<> | 149:156823d33999 | 177 | for (i = 0; i < hpcd->Init.dev_endpoints ; i++) |
<> | 149:156823d33999 | 178 | { |
<> | 149:156823d33999 | 179 | hpcd->OUT_ep[i].is_in = 0; |
<> | 149:156823d33999 | 180 | hpcd->OUT_ep[i].num = i; |
<> | 149:156823d33999 | 181 | /* Control until ep is activated */ |
<> | 149:156823d33999 | 182 | hpcd->OUT_ep[i].type = PCD_EP_TYPE_CTRL; |
<> | 149:156823d33999 | 183 | hpcd->OUT_ep[i].maxpacket = 0; |
<> | 149:156823d33999 | 184 | hpcd->OUT_ep[i].xfer_buff = 0; |
<> | 149:156823d33999 | 185 | hpcd->OUT_ep[i].xfer_len = 0; |
<> | 149:156823d33999 | 186 | } |
<> | 149:156823d33999 | 187 | |
<> | 149:156823d33999 | 188 | /* Init Device */ |
<> | 149:156823d33999 | 189 | /*CNTR_FRES = 1*/ |
<> | 149:156823d33999 | 190 | hpcd->Instance->CNTR = USB_CNTR_FRES; |
<> | 149:156823d33999 | 191 | |
<> | 149:156823d33999 | 192 | /*CNTR_FRES = 0*/ |
<> | 149:156823d33999 | 193 | hpcd->Instance->CNTR = 0; |
<> | 149:156823d33999 | 194 | |
<> | 149:156823d33999 | 195 | /*Clear pending interrupts*/ |
<> | 149:156823d33999 | 196 | hpcd->Instance->ISTR = 0; |
<> | 149:156823d33999 | 197 | |
<> | 149:156823d33999 | 198 | /*Set Btable Adress*/ |
<> | 149:156823d33999 | 199 | hpcd->Instance->BTABLE = BTABLE_ADDRESS; |
<> | 149:156823d33999 | 200 | |
<> | 149:156823d33999 | 201 | /*set wInterrupt_Mask global variable*/ |
<> | 149:156823d33999 | 202 | wInterrupt_Mask = USB_CNTR_CTRM | USB_CNTR_WKUPM | USB_CNTR_SUSPM | USB_CNTR_ERRM \ |
<> | 149:156823d33999 | 203 | | USB_CNTR_ESOFM | USB_CNTR_RESETM; |
<> | 149:156823d33999 | 204 | |
<> | 149:156823d33999 | 205 | /*Set interrupt mask*/ |
<> | 149:156823d33999 | 206 | hpcd->Instance->CNTR = wInterrupt_Mask; |
<> | 149:156823d33999 | 207 | |
<> | 149:156823d33999 | 208 | hpcd->USB_Address = 0; |
<> | 149:156823d33999 | 209 | hpcd->State= HAL_PCD_STATE_READY; |
<> | 149:156823d33999 | 210 | |
<> | 149:156823d33999 | 211 | return HAL_OK; |
<> | 149:156823d33999 | 212 | } |
<> | 149:156823d33999 | 213 | |
<> | 149:156823d33999 | 214 | /** |
<> | 149:156823d33999 | 215 | * @brief DeInitializes the PCD peripheral |
<> | 149:156823d33999 | 216 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 217 | * @retval HAL status |
<> | 149:156823d33999 | 218 | */ |
<> | 149:156823d33999 | 219 | HAL_StatusTypeDef HAL_PCD_DeInit(PCD_HandleTypeDef *hpcd) |
<> | 149:156823d33999 | 220 | { |
<> | 149:156823d33999 | 221 | /* Check the PCD handle allocation */ |
<> | 149:156823d33999 | 222 | if(hpcd == NULL) |
<> | 149:156823d33999 | 223 | { |
<> | 149:156823d33999 | 224 | return HAL_ERROR; |
<> | 149:156823d33999 | 225 | } |
<> | 149:156823d33999 | 226 | |
<> | 149:156823d33999 | 227 | hpcd->State = HAL_PCD_STATE_BUSY; |
<> | 149:156823d33999 | 228 | |
<> | 149:156823d33999 | 229 | /* Stop Device */ |
<> | 149:156823d33999 | 230 | HAL_PCD_Stop(hpcd); |
<> | 149:156823d33999 | 231 | |
<> | 149:156823d33999 | 232 | /* DeInit the low level hardware */ |
<> | 149:156823d33999 | 233 | HAL_PCD_MspDeInit(hpcd); |
<> | 149:156823d33999 | 234 | |
<> | 149:156823d33999 | 235 | hpcd->State = HAL_PCD_STATE_RESET; |
<> | 149:156823d33999 | 236 | |
<> | 149:156823d33999 | 237 | return HAL_OK; |
<> | 149:156823d33999 | 238 | } |
<> | 149:156823d33999 | 239 | |
<> | 149:156823d33999 | 240 | /** |
<> | 149:156823d33999 | 241 | * @brief Initializes the PCD MSP. |
<> | 149:156823d33999 | 242 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 243 | * @retval None |
<> | 149:156823d33999 | 244 | */ |
<> | 149:156823d33999 | 245 | __weak void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) |
<> | 149:156823d33999 | 246 | { |
<> | 149:156823d33999 | 247 | /* Prevent unused argument(s) compilation warning */ |
<> | 149:156823d33999 | 248 | UNUSED(hpcd); |
<> | 149:156823d33999 | 249 | |
<> | 149:156823d33999 | 250 | /* NOTE : This function should not be modified, when the callback is needed, |
<> | 149:156823d33999 | 251 | the HAL_PCD_MspInit could be implemented in the user file |
<> | 149:156823d33999 | 252 | */ |
<> | 149:156823d33999 | 253 | } |
<> | 149:156823d33999 | 254 | |
<> | 149:156823d33999 | 255 | /** |
<> | 149:156823d33999 | 256 | * @brief DeInitializes PCD MSP. |
<> | 149:156823d33999 | 257 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 258 | * @retval None |
<> | 149:156823d33999 | 259 | */ |
<> | 149:156823d33999 | 260 | __weak void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd) |
<> | 149:156823d33999 | 261 | { |
<> | 149:156823d33999 | 262 | /* Prevent unused argument(s) compilation warning */ |
<> | 149:156823d33999 | 263 | UNUSED(hpcd); |
<> | 149:156823d33999 | 264 | |
<> | 149:156823d33999 | 265 | /* NOTE : This function should not be modified, when the callback is needed, |
<> | 149:156823d33999 | 266 | the HAL_PCD_MspDeInit could be implemented in the user file |
<> | 149:156823d33999 | 267 | */ |
<> | 149:156823d33999 | 268 | } |
<> | 149:156823d33999 | 269 | |
<> | 149:156823d33999 | 270 | /** |
<> | 149:156823d33999 | 271 | * @} |
<> | 149:156823d33999 | 272 | */ |
<> | 149:156823d33999 | 273 | |
<> | 149:156823d33999 | 274 | /** @defgroup PCD_Exported_Functions_Group2 IO operation functions |
<> | 149:156823d33999 | 275 | * @brief Data transfers functions |
<> | 149:156823d33999 | 276 | * |
<> | 149:156823d33999 | 277 | @verbatim |
<> | 149:156823d33999 | 278 | =============================================================================== |
<> | 149:156823d33999 | 279 | ##### IO operation functions ##### |
<> | 149:156823d33999 | 280 | =============================================================================== |
<> | 149:156823d33999 | 281 | [..] |
<> | 149:156823d33999 | 282 | This subsection provides a set of functions allowing to manage the PCD data |
<> | 149:156823d33999 | 283 | transfers. |
<> | 149:156823d33999 | 284 | |
<> | 149:156823d33999 | 285 | @endverbatim |
<> | 149:156823d33999 | 286 | * @{ |
<> | 149:156823d33999 | 287 | */ |
<> | 149:156823d33999 | 288 | |
<> | 149:156823d33999 | 289 | /** |
<> | 149:156823d33999 | 290 | * @brief Start the USB device. |
<> | 149:156823d33999 | 291 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 292 | * @retval HAL status |
<> | 149:156823d33999 | 293 | */ |
<> | 149:156823d33999 | 294 | HAL_StatusTypeDef HAL_PCD_Start(PCD_HandleTypeDef *hpcd) |
<> | 149:156823d33999 | 295 | { |
<> | 149:156823d33999 | 296 | HAL_PCDEx_SetConnectionState (hpcd, 1); |
<> | 149:156823d33999 | 297 | |
<> | 149:156823d33999 | 298 | return HAL_OK; |
<> | 149:156823d33999 | 299 | } |
<> | 149:156823d33999 | 300 | |
<> | 149:156823d33999 | 301 | /** |
<> | 149:156823d33999 | 302 | * @brief Stop the USB device. |
<> | 149:156823d33999 | 303 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 304 | * @retval HAL status |
<> | 149:156823d33999 | 305 | */ |
<> | 149:156823d33999 | 306 | HAL_StatusTypeDef HAL_PCD_Stop(PCD_HandleTypeDef *hpcd) |
<> | 149:156823d33999 | 307 | { |
<> | 149:156823d33999 | 308 | __HAL_LOCK(hpcd); |
<> | 149:156823d33999 | 309 | |
<> | 149:156823d33999 | 310 | /* disable all interrupts and force USB reset */ |
<> | 149:156823d33999 | 311 | hpcd->Instance->CNTR = USB_CNTR_FRES; |
<> | 149:156823d33999 | 312 | |
<> | 149:156823d33999 | 313 | /* clear interrupt status register */ |
<> | 149:156823d33999 | 314 | hpcd->Instance->ISTR = 0; |
<> | 149:156823d33999 | 315 | |
<> | 149:156823d33999 | 316 | /* switch-off device */ |
<> | 149:156823d33999 | 317 | hpcd->Instance->CNTR = (USB_CNTR_FRES | USB_CNTR_PDWN); |
<> | 149:156823d33999 | 318 | |
<> | 149:156823d33999 | 319 | __HAL_UNLOCK(hpcd); |
<> | 149:156823d33999 | 320 | return HAL_OK; |
<> | 149:156823d33999 | 321 | } |
<> | 149:156823d33999 | 322 | /** |
<> | 149:156823d33999 | 323 | * @} |
<> | 149:156823d33999 | 324 | */ |
<> | 149:156823d33999 | 325 | |
<> | 149:156823d33999 | 326 | /** |
<> | 149:156823d33999 | 327 | * @} |
<> | 149:156823d33999 | 328 | */ |
<> | 149:156823d33999 | 329 | |
<> | 149:156823d33999 | 330 | /** @addtogroup PCD_Private_Functions PCD Private Functions |
<> | 149:156823d33999 | 331 | * @{ |
<> | 149:156823d33999 | 332 | */ |
<> | 149:156823d33999 | 333 | /** |
<> | 149:156823d33999 | 334 | * @brief This function handles PCD Endpoint interrupt request. |
<> | 149:156823d33999 | 335 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 336 | * @retval HAL status |
<> | 149:156823d33999 | 337 | */ |
<> | 149:156823d33999 | 338 | static HAL_StatusTypeDef PCD_EP_ISR_Handler(PCD_HandleTypeDef *hpcd) |
<> | 149:156823d33999 | 339 | { |
<> | 149:156823d33999 | 340 | PCD_EPTypeDef *ep; |
<> | 149:156823d33999 | 341 | uint16_t count=0; |
<> | 149:156823d33999 | 342 | uint8_t EPindex; |
<> | 149:156823d33999 | 343 | __IO uint16_t wIstr; |
<> | 149:156823d33999 | 344 | __IO uint16_t wEPVal = 0; |
<> | 149:156823d33999 | 345 | |
<> | 149:156823d33999 | 346 | /* stay in loop while pending interrupts */ |
<> | 149:156823d33999 | 347 | while (((wIstr = hpcd->Instance->ISTR) & USB_ISTR_CTR) != 0) |
<> | 149:156823d33999 | 348 | { |
<> | 149:156823d33999 | 349 | /* extract highest priority endpoint number */ |
<> | 149:156823d33999 | 350 | EPindex = (uint8_t)(wIstr & USB_ISTR_EP_ID); |
<> | 149:156823d33999 | 351 | |
<> | 149:156823d33999 | 352 | if (EPindex == 0) |
<> | 149:156823d33999 | 353 | { |
<> | 149:156823d33999 | 354 | /* Decode and service control endpoint interrupt */ |
<> | 149:156823d33999 | 355 | |
<> | 149:156823d33999 | 356 | /* DIR bit = origin of the interrupt */ |
<> | 149:156823d33999 | 357 | if ((wIstr & USB_ISTR_DIR) == 0) |
<> | 149:156823d33999 | 358 | { |
<> | 149:156823d33999 | 359 | /* DIR = 0 */ |
<> | 149:156823d33999 | 360 | |
<> | 149:156823d33999 | 361 | /* DIR = 0 => IN int */ |
<> | 149:156823d33999 | 362 | /* DIR = 0 implies that (EP_CTR_TX = 1) always */ |
<> | 149:156823d33999 | 363 | PCD_CLEAR_TX_EP_CTR(hpcd->Instance, PCD_ENDP0); |
<> | 149:156823d33999 | 364 | ep = &hpcd->IN_ep[0]; |
<> | 149:156823d33999 | 365 | |
<> | 149:156823d33999 | 366 | ep->xfer_count = PCD_GET_EP_TX_CNT(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 367 | ep->xfer_buff += ep->xfer_count; |
<> | 149:156823d33999 | 368 | |
<> | 149:156823d33999 | 369 | /* TX COMPLETE */ |
<> | 149:156823d33999 | 370 | HAL_PCD_DataInStageCallback(hpcd, 0); |
<> | 149:156823d33999 | 371 | |
<> | 149:156823d33999 | 372 | |
<> | 149:156823d33999 | 373 | if((hpcd->USB_Address > 0)&& ( ep->xfer_len == 0)) |
<> | 149:156823d33999 | 374 | { |
<> | 149:156823d33999 | 375 | hpcd->Instance->DADDR = (hpcd->USB_Address | USB_DADDR_EF); |
<> | 149:156823d33999 | 376 | hpcd->USB_Address = 0; |
<> | 149:156823d33999 | 377 | } |
<> | 149:156823d33999 | 378 | |
<> | 149:156823d33999 | 379 | } |
<> | 149:156823d33999 | 380 | else |
<> | 149:156823d33999 | 381 | { |
<> | 149:156823d33999 | 382 | /* DIR = 1 */ |
<> | 149:156823d33999 | 383 | |
<> | 149:156823d33999 | 384 | /* DIR = 1 & CTR_RX => SETUP or OUT int */ |
<> | 149:156823d33999 | 385 | /* DIR = 1 & (CTR_TX | CTR_RX) => 2 int pending */ |
<> | 149:156823d33999 | 386 | ep = &hpcd->OUT_ep[0]; |
<> | 149:156823d33999 | 387 | wEPVal = PCD_GET_ENDPOINT(hpcd->Instance, PCD_ENDP0); |
<> | 149:156823d33999 | 388 | |
<> | 149:156823d33999 | 389 | if ((wEPVal & USB_EP_SETUP) != 0) |
<> | 149:156823d33999 | 390 | { |
<> | 149:156823d33999 | 391 | /* Get SETUP Packet*/ |
<> | 149:156823d33999 | 392 | ep->xfer_count = PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 393 | PCD_ReadPMA(hpcd->Instance, (uint8_t*)hpcd->Setup ,ep->pmaadress , ep->xfer_count); |
<> | 149:156823d33999 | 394 | /* SETUP bit kept frozen while CTR_RX = 1*/ |
<> | 149:156823d33999 | 395 | PCD_CLEAR_RX_EP_CTR(hpcd->Instance, PCD_ENDP0); |
<> | 149:156823d33999 | 396 | |
<> | 149:156823d33999 | 397 | /* Process SETUP Packet*/ |
<> | 149:156823d33999 | 398 | HAL_PCD_SetupStageCallback(hpcd); |
<> | 149:156823d33999 | 399 | } |
<> | 149:156823d33999 | 400 | |
<> | 149:156823d33999 | 401 | else if ((wEPVal & USB_EP_CTR_RX) != 0) |
<> | 149:156823d33999 | 402 | { |
<> | 149:156823d33999 | 403 | PCD_CLEAR_RX_EP_CTR(hpcd->Instance, PCD_ENDP0); |
<> | 149:156823d33999 | 404 | /* Get Control Data OUT Packet*/ |
<> | 149:156823d33999 | 405 | ep->xfer_count = PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 406 | |
<> | 149:156823d33999 | 407 | if (ep->xfer_count != 0) |
<> | 149:156823d33999 | 408 | { |
<> | 149:156823d33999 | 409 | PCD_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaadress, ep->xfer_count); |
<> | 149:156823d33999 | 410 | ep->xfer_buff+=ep->xfer_count; |
<> | 149:156823d33999 | 411 | } |
<> | 149:156823d33999 | 412 | |
<> | 149:156823d33999 | 413 | /* Process Control Data OUT Packet*/ |
<> | 149:156823d33999 | 414 | HAL_PCD_DataOutStageCallback(hpcd, 0); |
<> | 149:156823d33999 | 415 | |
<> | 149:156823d33999 | 416 | PCD_SET_EP_RX_CNT(hpcd->Instance, PCD_ENDP0, ep->maxpacket); |
<> | 149:156823d33999 | 417 | PCD_SET_EP_RX_STATUS(hpcd->Instance, PCD_ENDP0, USB_EP_RX_VALID); |
<> | 149:156823d33999 | 418 | } |
<> | 149:156823d33999 | 419 | } |
<> | 149:156823d33999 | 420 | } |
<> | 149:156823d33999 | 421 | else |
<> | 149:156823d33999 | 422 | { |
<> | 149:156823d33999 | 423 | |
<> | 149:156823d33999 | 424 | /* Decode and service non control endpoints interrupt */ |
<> | 149:156823d33999 | 425 | |
<> | 149:156823d33999 | 426 | /* process related endpoint register */ |
<> | 149:156823d33999 | 427 | wEPVal = PCD_GET_ENDPOINT(hpcd->Instance, EPindex); |
<> | 149:156823d33999 | 428 | if ((wEPVal & USB_EP_CTR_RX) != 0) |
<> | 149:156823d33999 | 429 | { |
<> | 149:156823d33999 | 430 | /* clear int flag */ |
<> | 149:156823d33999 | 431 | PCD_CLEAR_RX_EP_CTR(hpcd->Instance, EPindex); |
<> | 149:156823d33999 | 432 | ep = &hpcd->OUT_ep[EPindex]; |
<> | 149:156823d33999 | 433 | |
<> | 149:156823d33999 | 434 | /* OUT double Buffering*/ |
<> | 149:156823d33999 | 435 | if (ep->doublebuffer == 0) |
<> | 149:156823d33999 | 436 | { |
<> | 149:156823d33999 | 437 | count = PCD_GET_EP_RX_CNT(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 438 | if (count != 0) |
<> | 149:156823d33999 | 439 | { |
<> | 149:156823d33999 | 440 | PCD_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaadress, count); |
<> | 149:156823d33999 | 441 | } |
<> | 149:156823d33999 | 442 | } |
<> | 149:156823d33999 | 443 | else |
<> | 149:156823d33999 | 444 | { |
<> | 149:156823d33999 | 445 | if (PCD_GET_ENDPOINT(hpcd->Instance, ep->num) & USB_EP_DTOG_RX) |
<> | 149:156823d33999 | 446 | { |
<> | 149:156823d33999 | 447 | /*read from endpoint BUF0Addr buffer*/ |
<> | 149:156823d33999 | 448 | count = PCD_GET_EP_DBUF0_CNT(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 449 | if (count != 0) |
<> | 149:156823d33999 | 450 | { |
<> | 149:156823d33999 | 451 | PCD_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr0, count); |
<> | 149:156823d33999 | 452 | } |
<> | 149:156823d33999 | 453 | } |
<> | 149:156823d33999 | 454 | else |
<> | 149:156823d33999 | 455 | { |
<> | 149:156823d33999 | 456 | /*read from endpoint BUF1Addr buffer*/ |
<> | 149:156823d33999 | 457 | count = PCD_GET_EP_DBUF1_CNT(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 458 | if (count != 0) |
<> | 149:156823d33999 | 459 | { |
<> | 149:156823d33999 | 460 | PCD_ReadPMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr1, count); |
<> | 149:156823d33999 | 461 | } |
<> | 149:156823d33999 | 462 | } |
<> | 149:156823d33999 | 463 | PCD_FreeUserBuffer(hpcd->Instance, ep->num, PCD_EP_DBUF_OUT); |
<> | 149:156823d33999 | 464 | } |
<> | 149:156823d33999 | 465 | /*multi-packet on the NON control OUT endpoint*/ |
<> | 149:156823d33999 | 466 | ep->xfer_count+=count; |
<> | 149:156823d33999 | 467 | ep->xfer_buff+=count; |
<> | 149:156823d33999 | 468 | |
<> | 149:156823d33999 | 469 | if ((ep->xfer_len == 0) || (count < ep->maxpacket)) |
<> | 149:156823d33999 | 470 | { |
<> | 149:156823d33999 | 471 | /* RX COMPLETE */ |
<> | 149:156823d33999 | 472 | HAL_PCD_DataOutStageCallback(hpcd, ep->num); |
<> | 149:156823d33999 | 473 | } |
<> | 149:156823d33999 | 474 | else |
<> | 149:156823d33999 | 475 | { |
<> | 149:156823d33999 | 476 | HAL_PCD_EP_Receive(hpcd, ep->num, ep->xfer_buff, ep->xfer_len); |
<> | 149:156823d33999 | 477 | } |
<> | 149:156823d33999 | 478 | |
<> | 149:156823d33999 | 479 | } /* if((wEPVal & EP_CTR_RX) */ |
<> | 149:156823d33999 | 480 | |
<> | 149:156823d33999 | 481 | if ((wEPVal & USB_EP_CTR_TX) != 0) |
<> | 149:156823d33999 | 482 | { |
<> | 149:156823d33999 | 483 | ep = &hpcd->IN_ep[EPindex]; |
<> | 149:156823d33999 | 484 | |
<> | 149:156823d33999 | 485 | /* clear int flag */ |
<> | 149:156823d33999 | 486 | PCD_CLEAR_TX_EP_CTR(hpcd->Instance, EPindex); |
<> | 149:156823d33999 | 487 | |
<> | 149:156823d33999 | 488 | /* IN double Buffering*/ |
<> | 149:156823d33999 | 489 | if (ep->doublebuffer == 0) |
<> | 149:156823d33999 | 490 | { |
<> | 149:156823d33999 | 491 | ep->xfer_count = PCD_GET_EP_TX_CNT(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 492 | if (ep->xfer_count != 0) |
<> | 149:156823d33999 | 493 | { |
<> | 149:156823d33999 | 494 | PCD_WritePMA(hpcd->Instance, ep->xfer_buff, ep->pmaadress, ep->xfer_count); |
<> | 149:156823d33999 | 495 | } |
<> | 149:156823d33999 | 496 | } |
<> | 149:156823d33999 | 497 | else |
<> | 149:156823d33999 | 498 | { |
<> | 149:156823d33999 | 499 | if (PCD_GET_ENDPOINT(hpcd->Instance, ep->num) & USB_EP_DTOG_TX) |
<> | 149:156823d33999 | 500 | { |
<> | 149:156823d33999 | 501 | /*read from endpoint BUF0Addr buffer*/ |
<> | 149:156823d33999 | 502 | ep->xfer_count = PCD_GET_EP_DBUF0_CNT(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 503 | if (ep->xfer_count != 0) |
<> | 149:156823d33999 | 504 | { |
<> | 149:156823d33999 | 505 | PCD_WritePMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr0, ep->xfer_count); |
<> | 149:156823d33999 | 506 | } |
<> | 149:156823d33999 | 507 | } |
<> | 149:156823d33999 | 508 | else |
<> | 149:156823d33999 | 509 | { |
<> | 149:156823d33999 | 510 | /*read from endpoint BUF1Addr buffer*/ |
<> | 149:156823d33999 | 511 | ep->xfer_count = PCD_GET_EP_DBUF1_CNT(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 512 | if (ep->xfer_count != 0) |
<> | 149:156823d33999 | 513 | { |
<> | 149:156823d33999 | 514 | PCD_WritePMA(hpcd->Instance, ep->xfer_buff, ep->pmaaddr1, ep->xfer_count); |
<> | 149:156823d33999 | 515 | } |
<> | 149:156823d33999 | 516 | } |
<> | 149:156823d33999 | 517 | PCD_FreeUserBuffer(hpcd->Instance, ep->num, PCD_EP_DBUF_IN); |
<> | 149:156823d33999 | 518 | } |
<> | 149:156823d33999 | 519 | /*multi-packet on the NON control IN endpoint*/ |
<> | 149:156823d33999 | 520 | ep->xfer_count = PCD_GET_EP_TX_CNT(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 521 | ep->xfer_buff+=ep->xfer_count; |
<> | 149:156823d33999 | 522 | |
<> | 149:156823d33999 | 523 | /* Zero Length Packet? */ |
<> | 149:156823d33999 | 524 | if (ep->xfer_len == 0) |
<> | 149:156823d33999 | 525 | { |
<> | 149:156823d33999 | 526 | /* TX COMPLETE */ |
<> | 149:156823d33999 | 527 | HAL_PCD_DataInStageCallback(hpcd, ep->num); |
<> | 149:156823d33999 | 528 | } |
<> | 149:156823d33999 | 529 | else |
<> | 149:156823d33999 | 530 | { |
<> | 149:156823d33999 | 531 | HAL_PCD_EP_Transmit(hpcd, ep->num, ep->xfer_buff, ep->xfer_len); |
<> | 149:156823d33999 | 532 | } |
<> | 149:156823d33999 | 533 | } |
<> | 149:156823d33999 | 534 | } |
<> | 149:156823d33999 | 535 | } |
<> | 149:156823d33999 | 536 | return HAL_OK; |
<> | 149:156823d33999 | 537 | } |
<> | 149:156823d33999 | 538 | |
<> | 149:156823d33999 | 539 | /** |
<> | 149:156823d33999 | 540 | * @brief Copy a buffer from user memory area to packet memory area (PMA) |
<> | 149:156823d33999 | 541 | * @param USBx = pointer to USB register. |
<> | 149:156823d33999 | 542 | * @param pbUsrBuf: pointer to user memory area. |
<> | 149:156823d33999 | 543 | * @param wPMABufAddr: address into PMA. |
<> | 149:156823d33999 | 544 | * @param wNBytes: no. of bytes to be copied. |
<> | 149:156823d33999 | 545 | * @retval None |
<> | 149:156823d33999 | 546 | */ |
<> | 149:156823d33999 | 547 | static void PCD_WritePMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes) |
<> | 149:156823d33999 | 548 | { |
<> | 149:156823d33999 | 549 | uint32_t n = (wNBytes + 1) >> 1; /* n = (wNBytes + 1) / 2 */ |
<> | 149:156823d33999 | 550 | uint32_t i, temp1, temp2; |
<> | 149:156823d33999 | 551 | uint16_t *pdwVal; |
<> | 149:156823d33999 | 552 | pdwVal = (uint16_t *)(wPMABufAddr * 2 + (uint32_t)USBx + 0x400); |
<> | 149:156823d33999 | 553 | for (i = n; i != 0; i--) |
<> | 149:156823d33999 | 554 | { |
<> | 149:156823d33999 | 555 | temp1 = (uint16_t) * pbUsrBuf; |
<> | 149:156823d33999 | 556 | pbUsrBuf++; |
<> | 149:156823d33999 | 557 | temp2 = temp1 | (uint16_t) * pbUsrBuf << 8; |
<> | 149:156823d33999 | 558 | *pdwVal++ = temp2; |
<> | 149:156823d33999 | 559 | pdwVal++; |
<> | 149:156823d33999 | 560 | pbUsrBuf++; |
<> | 149:156823d33999 | 561 | } |
<> | 149:156823d33999 | 562 | } |
<> | 149:156823d33999 | 563 | |
<> | 149:156823d33999 | 564 | /** |
<> | 149:156823d33999 | 565 | * @brief Copy a buffer from user memory area to packet memory area (PMA) |
<> | 149:156823d33999 | 566 | * @param USBx = pointer to USB register. |
<> | 149:156823d33999 | 567 | * @param pbUsrBuf = pointer to user memory area. |
<> | 149:156823d33999 | 568 | * @param wPMABufAddr: address into PMA. |
<> | 149:156823d33999 | 569 | * @param wNBytes: no. of bytes to be copied. |
<> | 149:156823d33999 | 570 | * @retval None |
<> | 149:156823d33999 | 571 | */ |
<> | 149:156823d33999 | 572 | static void PCD_ReadPMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes) |
<> | 149:156823d33999 | 573 | { |
<> | 149:156823d33999 | 574 | uint32_t n = (wNBytes + 1) >> 1;/* /2*/ |
<> | 149:156823d33999 | 575 | uint32_t i; |
<> | 149:156823d33999 | 576 | uint32_t *pdwVal; |
<> | 149:156823d33999 | 577 | pdwVal = (uint32_t *)(wPMABufAddr * 2 + (uint32_t)USBx + 0x400); |
<> | 149:156823d33999 | 578 | for (i = n; i != 0; i--) |
<> | 149:156823d33999 | 579 | { |
<> | 149:156823d33999 | 580 | *(uint16_t*)pbUsrBuf++ = *pdwVal++; |
<> | 149:156823d33999 | 581 | pbUsrBuf++; |
<> | 149:156823d33999 | 582 | } |
<> | 149:156823d33999 | 583 | } |
<> | 149:156823d33999 | 584 | |
<> | 149:156823d33999 | 585 | /** |
<> | 149:156823d33999 | 586 | * @} |
<> | 149:156823d33999 | 587 | */ |
<> | 149:156823d33999 | 588 | |
<> | 149:156823d33999 | 589 | /** @addtogroup PCD_Exported_Functions |
<> | 149:156823d33999 | 590 | * @{ |
<> | 149:156823d33999 | 591 | */ |
<> | 149:156823d33999 | 592 | |
<> | 149:156823d33999 | 593 | /** @defgroup PCD_Exported_Functions_Group2 IO operation functions |
<> | 149:156823d33999 | 594 | * @{ |
<> | 149:156823d33999 | 595 | */ |
<> | 149:156823d33999 | 596 | |
<> | 149:156823d33999 | 597 | /** |
<> | 149:156823d33999 | 598 | * @brief This function handles PCD interrupt request. |
<> | 149:156823d33999 | 599 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 600 | * @retval HAL status |
<> | 149:156823d33999 | 601 | */ |
<> | 149:156823d33999 | 602 | void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd) |
<> | 149:156823d33999 | 603 | { |
<> | 149:156823d33999 | 604 | uint32_t wInterrupt_Mask = 0; |
<> | 149:156823d33999 | 605 | |
<> | 149:156823d33999 | 606 | if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_CTR)) |
<> | 149:156823d33999 | 607 | { |
<> | 149:156823d33999 | 608 | /* servicing of the endpoint correct transfer interrupt */ |
<> | 149:156823d33999 | 609 | /* clear of the CTR flag into the sub */ |
<> | 149:156823d33999 | 610 | PCD_EP_ISR_Handler(hpcd); |
<> | 149:156823d33999 | 611 | } |
<> | 149:156823d33999 | 612 | |
<> | 149:156823d33999 | 613 | if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_RESET)) |
<> | 149:156823d33999 | 614 | { |
<> | 149:156823d33999 | 615 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_RESET); |
<> | 149:156823d33999 | 616 | HAL_PCD_ResetCallback(hpcd); |
<> | 149:156823d33999 | 617 | HAL_PCD_SetAddress(hpcd, 0); |
<> | 149:156823d33999 | 618 | } |
<> | 149:156823d33999 | 619 | |
<> | 149:156823d33999 | 620 | if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_PMAOVR)) |
<> | 149:156823d33999 | 621 | { |
<> | 149:156823d33999 | 622 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_PMAOVR); |
<> | 149:156823d33999 | 623 | } |
<> | 149:156823d33999 | 624 | if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_ERR)) |
<> | 149:156823d33999 | 625 | { |
<> | 149:156823d33999 | 626 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_ERR); |
<> | 149:156823d33999 | 627 | } |
<> | 149:156823d33999 | 628 | |
<> | 149:156823d33999 | 629 | if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_WKUP)) |
<> | 149:156823d33999 | 630 | { |
<> | 149:156823d33999 | 631 | hpcd->Instance->CNTR &= ~(USB_CNTR_LPMODE); |
<> | 149:156823d33999 | 632 | |
<> | 149:156823d33999 | 633 | /*set wInterrupt_Mask global variable*/ |
<> | 149:156823d33999 | 634 | wInterrupt_Mask = USB_CNTR_CTRM | USB_CNTR_WKUPM | USB_CNTR_SUSPM | USB_CNTR_ERRM \ |
<> | 149:156823d33999 | 635 | | USB_CNTR_ESOFM | USB_CNTR_RESETM; |
<> | 149:156823d33999 | 636 | |
<> | 149:156823d33999 | 637 | /*Set interrupt mask*/ |
<> | 149:156823d33999 | 638 | hpcd->Instance->CNTR = wInterrupt_Mask; |
<> | 149:156823d33999 | 639 | |
<> | 149:156823d33999 | 640 | HAL_PCD_ResumeCallback(hpcd); |
<> | 149:156823d33999 | 641 | |
<> | 149:156823d33999 | 642 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_WKUP); |
<> | 149:156823d33999 | 643 | } |
<> | 149:156823d33999 | 644 | |
<> | 149:156823d33999 | 645 | if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_SUSP)) |
<> | 149:156823d33999 | 646 | { |
<> | 149:156823d33999 | 647 | /* clear of the ISTR bit must be done after setting of CNTR_FSUSP */ |
<> | 149:156823d33999 | 648 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_SUSP); |
<> | 149:156823d33999 | 649 | |
<> | 149:156823d33999 | 650 | /* Force low-power mode in the macrocell */ |
<> | 149:156823d33999 | 651 | hpcd->Instance->CNTR |= USB_CNTR_FSUSP; |
<> | 149:156823d33999 | 652 | hpcd->Instance->CNTR |= USB_CNTR_LPMODE; |
<> | 149:156823d33999 | 653 | if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_WKUP) == 0) |
<> | 149:156823d33999 | 654 | { |
<> | 149:156823d33999 | 655 | HAL_PCD_SuspendCallback(hpcd); |
<> | 149:156823d33999 | 656 | } |
<> | 149:156823d33999 | 657 | } |
<> | 149:156823d33999 | 658 | |
<> | 149:156823d33999 | 659 | if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_SOF)) |
<> | 149:156823d33999 | 660 | { |
<> | 149:156823d33999 | 661 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_SOF); |
<> | 149:156823d33999 | 662 | HAL_PCD_SOFCallback(hpcd); |
<> | 149:156823d33999 | 663 | } |
<> | 149:156823d33999 | 664 | |
<> | 149:156823d33999 | 665 | if (__HAL_PCD_GET_FLAG (hpcd, USB_ISTR_ESOF)) |
<> | 149:156823d33999 | 666 | { |
<> | 149:156823d33999 | 667 | /* clear ESOF flag in ISTR */ |
<> | 149:156823d33999 | 668 | __HAL_PCD_CLEAR_FLAG(hpcd, USB_ISTR_ESOF); |
<> | 149:156823d33999 | 669 | } |
<> | 149:156823d33999 | 670 | } |
<> | 149:156823d33999 | 671 | |
<> | 149:156823d33999 | 672 | /** |
<> | 149:156823d33999 | 673 | * @brief Data out stage callbacks |
<> | 149:156823d33999 | 674 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 675 | * @param epnum: endpoint number |
<> | 149:156823d33999 | 676 | * @retval None |
<> | 149:156823d33999 | 677 | */ |
<> | 149:156823d33999 | 678 | __weak void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
<> | 149:156823d33999 | 679 | { |
<> | 149:156823d33999 | 680 | /* Prevent unused argument(s) compilation warning */ |
<> | 149:156823d33999 | 681 | UNUSED(hpcd); |
<> | 149:156823d33999 | 682 | UNUSED(epnum); |
<> | 149:156823d33999 | 683 | |
<> | 149:156823d33999 | 684 | /* NOTE : This function should not be modified, when the callback is needed, |
<> | 149:156823d33999 | 685 | the HAL_PCD_DataOutStageCallback could be implemented in the user file |
<> | 149:156823d33999 | 686 | */ |
<> | 149:156823d33999 | 687 | } |
<> | 149:156823d33999 | 688 | |
<> | 149:156823d33999 | 689 | /** |
<> | 149:156823d33999 | 690 | * @brief Data IN stage callbacks |
<> | 149:156823d33999 | 691 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 692 | * @param epnum: endpoint number |
<> | 149:156823d33999 | 693 | * @retval None |
<> | 149:156823d33999 | 694 | */ |
<> | 149:156823d33999 | 695 | __weak void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
<> | 149:156823d33999 | 696 | { |
<> | 149:156823d33999 | 697 | /* Prevent unused argument(s) compilation warning */ |
<> | 149:156823d33999 | 698 | UNUSED(hpcd); |
<> | 149:156823d33999 | 699 | UNUSED(epnum); |
<> | 149:156823d33999 | 700 | |
<> | 149:156823d33999 | 701 | /* NOTE : This function should not be modified, when the callback is needed, |
<> | 149:156823d33999 | 702 | the HAL_PCD_DataInStageCallback could be implemented in the user file |
<> | 149:156823d33999 | 703 | */ |
<> | 149:156823d33999 | 704 | } |
<> | 149:156823d33999 | 705 | /** |
<> | 149:156823d33999 | 706 | * @brief Setup stage callback |
<> | 149:156823d33999 | 707 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 708 | * @retval None |
<> | 149:156823d33999 | 709 | */ |
<> | 149:156823d33999 | 710 | __weak void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd) |
<> | 149:156823d33999 | 711 | { |
<> | 149:156823d33999 | 712 | /* Prevent unused argument(s) compilation warning */ |
<> | 149:156823d33999 | 713 | UNUSED(hpcd); |
<> | 149:156823d33999 | 714 | |
<> | 149:156823d33999 | 715 | /* NOTE : This function should not be modified, when the callback is needed, |
<> | 149:156823d33999 | 716 | the HAL_PCD_SetupStageCallback could be implemented in the user file |
<> | 149:156823d33999 | 717 | */ |
<> | 149:156823d33999 | 718 | } |
<> | 149:156823d33999 | 719 | |
<> | 149:156823d33999 | 720 | /** |
<> | 149:156823d33999 | 721 | * @brief USB Start Of Frame callbacks |
<> | 149:156823d33999 | 722 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 723 | * @retval None |
<> | 149:156823d33999 | 724 | */ |
<> | 149:156823d33999 | 725 | __weak void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd) |
<> | 149:156823d33999 | 726 | { |
<> | 149:156823d33999 | 727 | /* Prevent unused argument(s) compilation warning */ |
<> | 149:156823d33999 | 728 | UNUSED(hpcd); |
<> | 149:156823d33999 | 729 | |
<> | 149:156823d33999 | 730 | /* NOTE : This function should not be modified, when the callback is needed, |
<> | 149:156823d33999 | 731 | the HAL_PCD_SOFCallback could be implemented in the user file |
<> | 149:156823d33999 | 732 | */ |
<> | 149:156823d33999 | 733 | } |
<> | 149:156823d33999 | 734 | |
<> | 149:156823d33999 | 735 | /** |
<> | 149:156823d33999 | 736 | * @brief USB Reset callbacks |
<> | 149:156823d33999 | 737 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 738 | * @retval None |
<> | 149:156823d33999 | 739 | */ |
<> | 149:156823d33999 | 740 | __weak void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd) |
<> | 149:156823d33999 | 741 | { |
<> | 149:156823d33999 | 742 | /* Prevent unused argument(s) compilation warning */ |
<> | 149:156823d33999 | 743 | UNUSED(hpcd); |
<> | 149:156823d33999 | 744 | |
<> | 149:156823d33999 | 745 | /* NOTE : This function should not be modified, when the callback is needed, |
<> | 149:156823d33999 | 746 | the HAL_PCD_ResetCallback could be implemented in the user file |
<> | 149:156823d33999 | 747 | */ |
<> | 149:156823d33999 | 748 | } |
<> | 149:156823d33999 | 749 | |
<> | 149:156823d33999 | 750 | |
<> | 149:156823d33999 | 751 | /** |
<> | 149:156823d33999 | 752 | * @brief Suspend event callbacks |
<> | 149:156823d33999 | 753 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 754 | * @retval None |
<> | 149:156823d33999 | 755 | */ |
<> | 149:156823d33999 | 756 | __weak void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd) |
<> | 149:156823d33999 | 757 | { |
<> | 149:156823d33999 | 758 | /* Prevent unused argument(s) compilation warning */ |
<> | 149:156823d33999 | 759 | UNUSED(hpcd); |
<> | 149:156823d33999 | 760 | |
<> | 149:156823d33999 | 761 | /* NOTE : This function should not be modified, when the callback is needed, |
<> | 149:156823d33999 | 762 | the HAL_PCD_SuspendCallback could be implemented in the user file |
<> | 149:156823d33999 | 763 | */ |
<> | 149:156823d33999 | 764 | } |
<> | 149:156823d33999 | 765 | |
<> | 149:156823d33999 | 766 | /** |
<> | 149:156823d33999 | 767 | * @brief Resume event callbacks |
<> | 149:156823d33999 | 768 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 769 | * @retval None |
<> | 149:156823d33999 | 770 | */ |
<> | 149:156823d33999 | 771 | __weak void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd) |
<> | 149:156823d33999 | 772 | { |
<> | 149:156823d33999 | 773 | /* Prevent unused argument(s) compilation warning */ |
<> | 149:156823d33999 | 774 | UNUSED(hpcd); |
<> | 149:156823d33999 | 775 | |
<> | 149:156823d33999 | 776 | /* NOTE : This function should not be modified, when the callback is needed, |
<> | 149:156823d33999 | 777 | the HAL_PCD_ResumeCallback could be implemented in the user file |
<> | 149:156823d33999 | 778 | */ |
<> | 149:156823d33999 | 779 | } |
<> | 149:156823d33999 | 780 | |
<> | 149:156823d33999 | 781 | /** |
<> | 149:156823d33999 | 782 | * @brief Incomplete ISO OUT callbacks |
<> | 149:156823d33999 | 783 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 784 | * @param epnum: endpoint number |
<> | 149:156823d33999 | 785 | * @retval None |
<> | 149:156823d33999 | 786 | */ |
<> | 149:156823d33999 | 787 | __weak void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
<> | 149:156823d33999 | 788 | { |
<> | 149:156823d33999 | 789 | /* Prevent unused argument(s) compilation warning */ |
<> | 149:156823d33999 | 790 | UNUSED(hpcd); |
<> | 149:156823d33999 | 791 | UNUSED(epnum); |
<> | 149:156823d33999 | 792 | |
<> | 149:156823d33999 | 793 | /* NOTE : This function should not be modified, when the callback is needed, |
<> | 149:156823d33999 | 794 | the HAL_PCD_ISOOUTIncompleteCallback could be implemented in the user file |
<> | 149:156823d33999 | 795 | */ |
<> | 149:156823d33999 | 796 | } |
<> | 149:156823d33999 | 797 | |
<> | 149:156823d33999 | 798 | /** |
<> | 149:156823d33999 | 799 | * @brief Incomplete ISO IN callbacks |
<> | 149:156823d33999 | 800 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 801 | * @param epnum: endpoint number |
<> | 149:156823d33999 | 802 | * @retval None |
<> | 149:156823d33999 | 803 | */ |
<> | 149:156823d33999 | 804 | __weak void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum) |
<> | 149:156823d33999 | 805 | { |
<> | 149:156823d33999 | 806 | /* Prevent unused argument(s) compilation warning */ |
<> | 149:156823d33999 | 807 | UNUSED(hpcd); |
<> | 149:156823d33999 | 808 | UNUSED(epnum); |
<> | 149:156823d33999 | 809 | |
<> | 149:156823d33999 | 810 | /* NOTE : This function should not be modified, when the callback is needed, |
<> | 149:156823d33999 | 811 | the HAL_PCD_ISOINIncompleteCallback could be implemented in the user file |
<> | 149:156823d33999 | 812 | */ |
<> | 149:156823d33999 | 813 | } |
<> | 149:156823d33999 | 814 | |
<> | 149:156823d33999 | 815 | /** |
<> | 149:156823d33999 | 816 | * @brief Connection event callbacks |
<> | 149:156823d33999 | 817 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 818 | * @retval None |
<> | 149:156823d33999 | 819 | */ |
<> | 149:156823d33999 | 820 | __weak void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd) |
<> | 149:156823d33999 | 821 | { |
<> | 149:156823d33999 | 822 | /* Prevent unused argument(s) compilation warning */ |
<> | 149:156823d33999 | 823 | UNUSED(hpcd); |
<> | 149:156823d33999 | 824 | |
<> | 149:156823d33999 | 825 | /* NOTE : This function should not be modified, when the callback is needed, |
<> | 149:156823d33999 | 826 | the HAL_PCD_ConnectCallback could be implemented in the user file |
<> | 149:156823d33999 | 827 | */ |
<> | 149:156823d33999 | 828 | } |
<> | 149:156823d33999 | 829 | |
<> | 149:156823d33999 | 830 | /** |
<> | 149:156823d33999 | 831 | * @brief Disconnection event callbacks |
<> | 149:156823d33999 | 832 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 833 | * @retval None |
<> | 149:156823d33999 | 834 | */ |
<> | 149:156823d33999 | 835 | __weak void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd) |
<> | 149:156823d33999 | 836 | { |
<> | 149:156823d33999 | 837 | /* Prevent unused argument(s) compilation warning */ |
<> | 149:156823d33999 | 838 | UNUSED(hpcd); |
<> | 149:156823d33999 | 839 | |
<> | 149:156823d33999 | 840 | /* NOTE : This function should not be modified, when the callback is needed, |
<> | 149:156823d33999 | 841 | the HAL_PCD_DisconnectCallback could be implemented in the user file |
<> | 149:156823d33999 | 842 | */ |
<> | 149:156823d33999 | 843 | } |
<> | 149:156823d33999 | 844 | /** |
<> | 149:156823d33999 | 845 | * @} |
<> | 149:156823d33999 | 846 | */ |
<> | 149:156823d33999 | 847 | |
<> | 149:156823d33999 | 848 | /** @defgroup PCD_Exported_Functions_Group3 Peripheral Control functions |
<> | 149:156823d33999 | 849 | * @brief management functions |
<> | 149:156823d33999 | 850 | * |
<> | 149:156823d33999 | 851 | @verbatim |
<> | 149:156823d33999 | 852 | =============================================================================== |
<> | 149:156823d33999 | 853 | ##### Peripheral Control functions ##### |
<> | 149:156823d33999 | 854 | =============================================================================== |
<> | 149:156823d33999 | 855 | [..] |
<> | 149:156823d33999 | 856 | This subsection provides a set of functions allowing to control the PCD data |
<> | 149:156823d33999 | 857 | transfers. |
<> | 149:156823d33999 | 858 | |
<> | 149:156823d33999 | 859 | @endverbatim |
<> | 149:156823d33999 | 860 | * @{ |
<> | 149:156823d33999 | 861 | */ |
<> | 149:156823d33999 | 862 | |
<> | 149:156823d33999 | 863 | /** |
<> | 149:156823d33999 | 864 | * @brief Connect the USB device |
<> | 149:156823d33999 | 865 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 866 | * @retval HAL status |
<> | 149:156823d33999 | 867 | */ |
<> | 149:156823d33999 | 868 | HAL_StatusTypeDef HAL_PCD_DevConnect(PCD_HandleTypeDef *hpcd) |
<> | 149:156823d33999 | 869 | { |
<> | 149:156823d33999 | 870 | __HAL_LOCK(hpcd); |
<> | 149:156823d33999 | 871 | |
<> | 149:156823d33999 | 872 | /* Enabling DP Pull-Down bit to Connect internal pull-up on USB DP line */ |
<> | 149:156823d33999 | 873 | HAL_PCDEx_SetConnectionState (hpcd, 1); |
<> | 149:156823d33999 | 874 | |
<> | 149:156823d33999 | 875 | __HAL_UNLOCK(hpcd); |
<> | 149:156823d33999 | 876 | return HAL_OK; |
<> | 149:156823d33999 | 877 | } |
<> | 149:156823d33999 | 878 | |
<> | 149:156823d33999 | 879 | /** |
<> | 149:156823d33999 | 880 | * @brief Disconnect the USB device |
<> | 149:156823d33999 | 881 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 882 | * @retval HAL status |
<> | 149:156823d33999 | 883 | */ |
<> | 149:156823d33999 | 884 | HAL_StatusTypeDef HAL_PCD_DevDisconnect(PCD_HandleTypeDef *hpcd) |
<> | 149:156823d33999 | 885 | { |
<> | 149:156823d33999 | 886 | __HAL_LOCK(hpcd); |
<> | 149:156823d33999 | 887 | |
<> | 149:156823d33999 | 888 | /* Disable DP Pull-Down bit*/ |
<> | 149:156823d33999 | 889 | HAL_PCDEx_SetConnectionState (hpcd, 0); |
<> | 149:156823d33999 | 890 | |
<> | 149:156823d33999 | 891 | __HAL_UNLOCK(hpcd); |
<> | 149:156823d33999 | 892 | return HAL_OK; |
<> | 149:156823d33999 | 893 | } |
<> | 149:156823d33999 | 894 | |
<> | 149:156823d33999 | 895 | /** |
<> | 149:156823d33999 | 896 | * @brief Set the USB Device address |
<> | 149:156823d33999 | 897 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 898 | * @param address: new device address |
<> | 149:156823d33999 | 899 | * @retval HAL status |
<> | 149:156823d33999 | 900 | */ |
<> | 149:156823d33999 | 901 | HAL_StatusTypeDef HAL_PCD_SetAddress(PCD_HandleTypeDef *hpcd, uint8_t address) |
<> | 149:156823d33999 | 902 | { |
<> | 149:156823d33999 | 903 | __HAL_LOCK(hpcd); |
<> | 149:156823d33999 | 904 | |
<> | 149:156823d33999 | 905 | if(address == 0) |
<> | 149:156823d33999 | 906 | { |
<> | 149:156823d33999 | 907 | /* set device address and enable function */ |
<> | 149:156823d33999 | 908 | hpcd->Instance->DADDR = USB_DADDR_EF; |
<> | 149:156823d33999 | 909 | } |
<> | 149:156823d33999 | 910 | else /* USB Address will be applied later */ |
<> | 149:156823d33999 | 911 | { |
<> | 149:156823d33999 | 912 | hpcd->USB_Address = address; |
<> | 149:156823d33999 | 913 | } |
<> | 149:156823d33999 | 914 | |
<> | 149:156823d33999 | 915 | __HAL_UNLOCK(hpcd); |
<> | 149:156823d33999 | 916 | return HAL_OK; |
<> | 149:156823d33999 | 917 | } |
<> | 149:156823d33999 | 918 | /** |
<> | 149:156823d33999 | 919 | * @brief Open and configure an endpoint |
<> | 149:156823d33999 | 920 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 921 | * @param ep_addr: endpoint address |
<> | 149:156823d33999 | 922 | * @param ep_mps: endpoint max packet size |
<> | 149:156823d33999 | 923 | * @param ep_type: endpoint type |
<> | 149:156823d33999 | 924 | * @retval HAL status |
<> | 149:156823d33999 | 925 | */ |
<> | 149:156823d33999 | 926 | HAL_StatusTypeDef HAL_PCD_EP_Open(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type) |
<> | 149:156823d33999 | 927 | { |
<> | 149:156823d33999 | 928 | HAL_StatusTypeDef ret = HAL_OK; |
<> | 149:156823d33999 | 929 | PCD_EPTypeDef *ep; |
<> | 149:156823d33999 | 930 | |
<> | 149:156823d33999 | 931 | if ((ep_addr & 0x80) == 0x80) |
<> | 149:156823d33999 | 932 | { |
<> | 149:156823d33999 | 933 | ep = &hpcd->IN_ep[ep_addr & 0x7F]; |
<> | 149:156823d33999 | 934 | } |
<> | 149:156823d33999 | 935 | else |
<> | 149:156823d33999 | 936 | { |
<> | 149:156823d33999 | 937 | ep = &hpcd->OUT_ep[ep_addr & 0x7F]; |
<> | 149:156823d33999 | 938 | } |
<> | 149:156823d33999 | 939 | ep->num = ep_addr & 0x7F; |
<> | 149:156823d33999 | 940 | |
<> | 149:156823d33999 | 941 | ep->is_in = (0x80 & ep_addr) != 0; |
<> | 149:156823d33999 | 942 | ep->maxpacket = ep_mps; |
<> | 149:156823d33999 | 943 | ep->type = ep_type; |
<> | 149:156823d33999 | 944 | |
<> | 149:156823d33999 | 945 | __HAL_LOCK(hpcd); |
<> | 149:156823d33999 | 946 | |
<> | 149:156823d33999 | 947 | /* initialize Endpoint */ |
<> | 149:156823d33999 | 948 | switch (ep->type) |
<> | 149:156823d33999 | 949 | { |
<> | 149:156823d33999 | 950 | case PCD_EP_TYPE_CTRL: |
<> | 149:156823d33999 | 951 | PCD_SET_EPTYPE(hpcd->Instance, ep->num, USB_EP_CONTROL); |
<> | 149:156823d33999 | 952 | break; |
<> | 149:156823d33999 | 953 | case PCD_EP_TYPE_BULK: |
<> | 149:156823d33999 | 954 | PCD_SET_EPTYPE(hpcd->Instance, ep->num, USB_EP_BULK); |
<> | 149:156823d33999 | 955 | break; |
<> | 149:156823d33999 | 956 | case PCD_EP_TYPE_INTR: |
<> | 149:156823d33999 | 957 | PCD_SET_EPTYPE(hpcd->Instance, ep->num, USB_EP_INTERRUPT); |
<> | 149:156823d33999 | 958 | break; |
<> | 149:156823d33999 | 959 | case PCD_EP_TYPE_ISOC: |
<> | 149:156823d33999 | 960 | PCD_SET_EPTYPE(hpcd->Instance, ep->num, USB_EP_ISOCHRONOUS); |
<> | 149:156823d33999 | 961 | break; |
<> | 149:156823d33999 | 962 | default: |
<> | 149:156823d33999 | 963 | break; |
<> | 149:156823d33999 | 964 | } |
<> | 149:156823d33999 | 965 | |
<> | 149:156823d33999 | 966 | PCD_SET_EP_ADDRESS(hpcd->Instance, ep->num, ep->num); |
<> | 149:156823d33999 | 967 | |
<> | 149:156823d33999 | 968 | if (ep->doublebuffer == 0) |
<> | 149:156823d33999 | 969 | { |
<> | 149:156823d33999 | 970 | if (ep->is_in) |
<> | 149:156823d33999 | 971 | { |
<> | 149:156823d33999 | 972 | /*Set the endpoint Transmit buffer address */ |
<> | 149:156823d33999 | 973 | PCD_SET_EP_TX_ADDRESS(hpcd->Instance, ep->num, ep->pmaadress); |
<> | 149:156823d33999 | 974 | PCD_CLEAR_TX_DTOG(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 975 | /* Configure NAK status for the Endpoint*/ |
<> | 149:156823d33999 | 976 | PCD_SET_EP_TX_STATUS(hpcd->Instance, ep->num, USB_EP_TX_NAK); |
<> | 149:156823d33999 | 977 | } |
<> | 149:156823d33999 | 978 | else |
<> | 149:156823d33999 | 979 | { |
<> | 149:156823d33999 | 980 | /*Set the endpoint Receive buffer address */ |
<> | 149:156823d33999 | 981 | PCD_SET_EP_RX_ADDRESS(hpcd->Instance, ep->num, ep->pmaadress); |
<> | 149:156823d33999 | 982 | /*Set the endpoint Receive buffer counter*/ |
<> | 149:156823d33999 | 983 | PCD_SET_EP_RX_CNT(hpcd->Instance, ep->num, ep->maxpacket); |
<> | 149:156823d33999 | 984 | PCD_CLEAR_RX_DTOG(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 985 | /* Configure VALID status for the Endpoint*/ |
<> | 149:156823d33999 | 986 | PCD_SET_EP_RX_STATUS(hpcd->Instance, ep->num, USB_EP_RX_VALID); |
<> | 149:156823d33999 | 987 | } |
<> | 149:156823d33999 | 988 | } |
<> | 149:156823d33999 | 989 | /*Double Buffer*/ |
<> | 149:156823d33999 | 990 | else |
<> | 149:156823d33999 | 991 | { |
<> | 149:156823d33999 | 992 | /*Set the endpoint as double buffered*/ |
<> | 149:156823d33999 | 993 | PCD_SET_EP_DBUF(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 994 | /*Set buffer address for double buffered mode*/ |
<> | 149:156823d33999 | 995 | PCD_SET_EP_DBUF_ADDR(hpcd->Instance, ep->num,ep->pmaaddr0, ep->pmaaddr1); |
<> | 149:156823d33999 | 996 | |
<> | 149:156823d33999 | 997 | if (ep->is_in==0) |
<> | 149:156823d33999 | 998 | { |
<> | 149:156823d33999 | 999 | /* Clear the data toggle bits for the endpoint IN/OUT*/ |
<> | 149:156823d33999 | 1000 | PCD_CLEAR_RX_DTOG(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 1001 | PCD_CLEAR_TX_DTOG(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 1002 | |
<> | 149:156823d33999 | 1003 | /* Reset value of the data toggle bits for the endpoint out*/ |
<> | 149:156823d33999 | 1004 | PCD_TX_DTOG(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 1005 | |
<> | 149:156823d33999 | 1006 | PCD_SET_EP_RX_STATUS(hpcd->Instance, ep->num, USB_EP_RX_VALID); |
<> | 149:156823d33999 | 1007 | PCD_SET_EP_TX_STATUS(hpcd->Instance, ep->num, USB_EP_TX_DIS); |
<> | 149:156823d33999 | 1008 | } |
<> | 149:156823d33999 | 1009 | else |
<> | 149:156823d33999 | 1010 | { |
<> | 149:156823d33999 | 1011 | /* Clear the data toggle bits for the endpoint IN/OUT*/ |
<> | 149:156823d33999 | 1012 | PCD_CLEAR_RX_DTOG(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 1013 | PCD_CLEAR_TX_DTOG(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 1014 | PCD_RX_DTOG(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 1015 | /* Configure DISABLE status for the Endpoint*/ |
<> | 149:156823d33999 | 1016 | PCD_SET_EP_TX_STATUS(hpcd->Instance, ep->num, USB_EP_TX_DIS); |
<> | 149:156823d33999 | 1017 | PCD_SET_EP_RX_STATUS(hpcd->Instance, ep->num, USB_EP_RX_DIS); |
<> | 149:156823d33999 | 1018 | } |
<> | 149:156823d33999 | 1019 | } |
<> | 149:156823d33999 | 1020 | |
<> | 149:156823d33999 | 1021 | __HAL_UNLOCK(hpcd); |
<> | 149:156823d33999 | 1022 | return ret; |
<> | 149:156823d33999 | 1023 | } |
<> | 149:156823d33999 | 1024 | |
<> | 149:156823d33999 | 1025 | |
<> | 149:156823d33999 | 1026 | /** |
<> | 149:156823d33999 | 1027 | * @brief Deactivate an endpoint |
<> | 149:156823d33999 | 1028 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 1029 | * @param ep_addr: endpoint address |
<> | 149:156823d33999 | 1030 | * @retval HAL status |
<> | 149:156823d33999 | 1031 | */ |
<> | 149:156823d33999 | 1032 | HAL_StatusTypeDef HAL_PCD_EP_Close(PCD_HandleTypeDef *hpcd, uint8_t ep_addr) |
<> | 149:156823d33999 | 1033 | { |
<> | 149:156823d33999 | 1034 | PCD_EPTypeDef *ep; |
<> | 149:156823d33999 | 1035 | |
<> | 149:156823d33999 | 1036 | if ((ep_addr & 0x80) == 0x80) |
<> | 149:156823d33999 | 1037 | { |
<> | 149:156823d33999 | 1038 | ep = &hpcd->IN_ep[ep_addr & 0x7F]; |
<> | 149:156823d33999 | 1039 | } |
<> | 149:156823d33999 | 1040 | else |
<> | 149:156823d33999 | 1041 | { |
<> | 149:156823d33999 | 1042 | ep = &hpcd->OUT_ep[ep_addr & 0x7F]; |
<> | 149:156823d33999 | 1043 | } |
<> | 149:156823d33999 | 1044 | ep->num = ep_addr & 0x7F; |
<> | 149:156823d33999 | 1045 | |
<> | 149:156823d33999 | 1046 | ep->is_in = (0x80 & ep_addr) != 0; |
<> | 149:156823d33999 | 1047 | |
<> | 149:156823d33999 | 1048 | __HAL_LOCK(hpcd); |
<> | 149:156823d33999 | 1049 | |
<> | 149:156823d33999 | 1050 | if (ep->doublebuffer == 0) |
<> | 149:156823d33999 | 1051 | { |
<> | 149:156823d33999 | 1052 | if (ep->is_in) |
<> | 149:156823d33999 | 1053 | { |
<> | 149:156823d33999 | 1054 | PCD_CLEAR_TX_DTOG(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 1055 | /* Configure DISABLE status for the Endpoint*/ |
<> | 149:156823d33999 | 1056 | PCD_SET_EP_TX_STATUS(hpcd->Instance, ep->num, USB_EP_TX_DIS); |
<> | 149:156823d33999 | 1057 | } |
<> | 149:156823d33999 | 1058 | else |
<> | 149:156823d33999 | 1059 | { |
<> | 149:156823d33999 | 1060 | PCD_CLEAR_RX_DTOG(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 1061 | /* Configure DISABLE status for the Endpoint*/ |
<> | 149:156823d33999 | 1062 | PCD_SET_EP_RX_STATUS(hpcd->Instance, ep->num, USB_EP_RX_DIS); |
<> | 149:156823d33999 | 1063 | } |
<> | 149:156823d33999 | 1064 | } |
<> | 149:156823d33999 | 1065 | /*Double Buffer*/ |
<> | 149:156823d33999 | 1066 | else |
<> | 149:156823d33999 | 1067 | { |
<> | 149:156823d33999 | 1068 | if (ep->is_in==0) |
<> | 149:156823d33999 | 1069 | { |
<> | 149:156823d33999 | 1070 | /* Clear the data toggle bits for the endpoint IN/OUT*/ |
<> | 149:156823d33999 | 1071 | PCD_CLEAR_RX_DTOG(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 1072 | PCD_CLEAR_TX_DTOG(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 1073 | |
<> | 149:156823d33999 | 1074 | /* Reset value of the data toggle bits for the endpoint out*/ |
<> | 149:156823d33999 | 1075 | PCD_TX_DTOG(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 1076 | |
<> | 149:156823d33999 | 1077 | PCD_SET_EP_RX_STATUS(hpcd->Instance, ep->num, USB_EP_RX_DIS); |
<> | 149:156823d33999 | 1078 | PCD_SET_EP_TX_STATUS(hpcd->Instance, ep->num, USB_EP_TX_DIS); |
<> | 149:156823d33999 | 1079 | } |
<> | 149:156823d33999 | 1080 | else |
<> | 149:156823d33999 | 1081 | { |
<> | 149:156823d33999 | 1082 | /* Clear the data toggle bits for the endpoint IN/OUT*/ |
<> | 149:156823d33999 | 1083 | PCD_CLEAR_RX_DTOG(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 1084 | PCD_CLEAR_TX_DTOG(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 1085 | PCD_RX_DTOG(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 1086 | /* Configure DISABLE status for the Endpoint*/ |
<> | 149:156823d33999 | 1087 | PCD_SET_EP_TX_STATUS(hpcd->Instance, ep->num, USB_EP_TX_DIS); |
<> | 149:156823d33999 | 1088 | PCD_SET_EP_RX_STATUS(hpcd->Instance, ep->num, USB_EP_RX_DIS); |
<> | 149:156823d33999 | 1089 | } |
<> | 149:156823d33999 | 1090 | } |
<> | 149:156823d33999 | 1091 | |
<> | 149:156823d33999 | 1092 | __HAL_UNLOCK(hpcd); |
<> | 149:156823d33999 | 1093 | return HAL_OK; |
<> | 149:156823d33999 | 1094 | } |
<> | 149:156823d33999 | 1095 | |
<> | 149:156823d33999 | 1096 | |
<> | 149:156823d33999 | 1097 | /** |
<> | 149:156823d33999 | 1098 | * @brief Receive an amount of data |
<> | 149:156823d33999 | 1099 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 1100 | * @param ep_addr: endpoint address |
<> | 149:156823d33999 | 1101 | * @param pBuf: pointer to the reception buffer |
<> | 149:156823d33999 | 1102 | * @param len: amount of data to be received |
<> | 149:156823d33999 | 1103 | * @retval HAL status |
<> | 149:156823d33999 | 1104 | */ |
<> | 149:156823d33999 | 1105 | HAL_StatusTypeDef HAL_PCD_EP_Receive(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len) |
<> | 149:156823d33999 | 1106 | { |
<> | 149:156823d33999 | 1107 | |
<> | 149:156823d33999 | 1108 | PCD_EPTypeDef *ep; |
<> | 149:156823d33999 | 1109 | |
<> | 149:156823d33999 | 1110 | ep = &hpcd->OUT_ep[ep_addr & 0x7F]; |
<> | 149:156823d33999 | 1111 | |
<> | 149:156823d33999 | 1112 | /*setup and start the Xfer */ |
<> | 149:156823d33999 | 1113 | ep->xfer_buff = pBuf; |
<> | 149:156823d33999 | 1114 | ep->xfer_len = len; |
<> | 149:156823d33999 | 1115 | ep->xfer_count = 0; |
<> | 149:156823d33999 | 1116 | ep->is_in = 0; |
<> | 149:156823d33999 | 1117 | ep->num = ep_addr & 0x7F; |
<> | 149:156823d33999 | 1118 | |
<> | 149:156823d33999 | 1119 | __HAL_LOCK(hpcd); |
<> | 149:156823d33999 | 1120 | |
<> | 149:156823d33999 | 1121 | /* Multi packet transfer*/ |
<> | 149:156823d33999 | 1122 | if (ep->xfer_len > ep->maxpacket) |
<> | 149:156823d33999 | 1123 | { |
<> | 149:156823d33999 | 1124 | len=ep->maxpacket; |
<> | 149:156823d33999 | 1125 | ep->xfer_len-=len; |
<> | 149:156823d33999 | 1126 | } |
<> | 149:156823d33999 | 1127 | else |
<> | 149:156823d33999 | 1128 | { |
<> | 149:156823d33999 | 1129 | len=ep->xfer_len; |
<> | 149:156823d33999 | 1130 | ep->xfer_len =0; |
<> | 149:156823d33999 | 1131 | } |
<> | 149:156823d33999 | 1132 | |
<> | 149:156823d33999 | 1133 | /* configure and validate Rx endpoint */ |
<> | 149:156823d33999 | 1134 | if (ep->doublebuffer == 0) |
<> | 149:156823d33999 | 1135 | { |
<> | 149:156823d33999 | 1136 | /*Set RX buffer count*/ |
<> | 149:156823d33999 | 1137 | PCD_SET_EP_RX_CNT(hpcd->Instance, ep->num, len); |
<> | 149:156823d33999 | 1138 | } |
<> | 149:156823d33999 | 1139 | else |
<> | 149:156823d33999 | 1140 | { |
<> | 149:156823d33999 | 1141 | /*Set the Double buffer counter*/ |
<> | 149:156823d33999 | 1142 | PCD_SET_EP_DBUF_CNT(hpcd->Instance, ep->num, ep->is_in, len); |
<> | 149:156823d33999 | 1143 | } |
<> | 149:156823d33999 | 1144 | |
<> | 149:156823d33999 | 1145 | PCD_SET_EP_RX_STATUS(hpcd->Instance, ep->num, USB_EP_RX_VALID); |
<> | 149:156823d33999 | 1146 | |
<> | 149:156823d33999 | 1147 | __HAL_UNLOCK(hpcd); |
<> | 149:156823d33999 | 1148 | |
<> | 149:156823d33999 | 1149 | return HAL_OK; |
<> | 149:156823d33999 | 1150 | } |
<> | 149:156823d33999 | 1151 | |
<> | 149:156823d33999 | 1152 | /** |
<> | 149:156823d33999 | 1153 | * @brief Get Received Data Size |
<> | 149:156823d33999 | 1154 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 1155 | * @param ep_addr: endpoint address |
<> | 149:156823d33999 | 1156 | * @retval Data Size |
<> | 149:156823d33999 | 1157 | */ |
<> | 149:156823d33999 | 1158 | uint16_t HAL_PCD_EP_GetRxCount(PCD_HandleTypeDef *hpcd, uint8_t ep_addr) |
<> | 149:156823d33999 | 1159 | { |
<> | 149:156823d33999 | 1160 | return hpcd->OUT_ep[ep_addr & 0x7F].xfer_count; |
<> | 149:156823d33999 | 1161 | } |
<> | 149:156823d33999 | 1162 | /** |
<> | 149:156823d33999 | 1163 | * @brief Send an amount of data |
<> | 149:156823d33999 | 1164 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 1165 | * @param ep_addr: endpoint address |
<> | 149:156823d33999 | 1166 | * @param pBuf: pointer to the transmission buffer |
<> | 149:156823d33999 | 1167 | * @param len: amount of data to be sent |
<> | 149:156823d33999 | 1168 | * @retval HAL status |
<> | 149:156823d33999 | 1169 | */ |
<> | 149:156823d33999 | 1170 | HAL_StatusTypeDef HAL_PCD_EP_Transmit(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len) |
<> | 149:156823d33999 | 1171 | { |
<> | 149:156823d33999 | 1172 | PCD_EPTypeDef *ep; |
<> | 149:156823d33999 | 1173 | uint16_t pmabuffer = 0; |
<> | 149:156823d33999 | 1174 | |
<> | 149:156823d33999 | 1175 | ep = &hpcd->IN_ep[ep_addr & 0x7F]; |
<> | 149:156823d33999 | 1176 | |
<> | 149:156823d33999 | 1177 | /*setup and start the Xfer */ |
<> | 149:156823d33999 | 1178 | ep->xfer_buff = pBuf; |
<> | 149:156823d33999 | 1179 | ep->xfer_len = len; |
<> | 149:156823d33999 | 1180 | ep->xfer_count = 0; |
<> | 149:156823d33999 | 1181 | ep->is_in = 1; |
<> | 149:156823d33999 | 1182 | ep->num = ep_addr & 0x7F; |
<> | 149:156823d33999 | 1183 | |
<> | 149:156823d33999 | 1184 | __HAL_LOCK(hpcd); |
<> | 149:156823d33999 | 1185 | |
<> | 149:156823d33999 | 1186 | /*Multi packet transfer*/ |
<> | 149:156823d33999 | 1187 | if (ep->xfer_len > ep->maxpacket) |
<> | 149:156823d33999 | 1188 | { |
<> | 149:156823d33999 | 1189 | len=ep->maxpacket; |
<> | 149:156823d33999 | 1190 | ep->xfer_len-=len; |
<> | 149:156823d33999 | 1191 | } |
<> | 149:156823d33999 | 1192 | else |
<> | 149:156823d33999 | 1193 | { |
<> | 149:156823d33999 | 1194 | len=ep->xfer_len; |
<> | 149:156823d33999 | 1195 | ep->xfer_len =0; |
<> | 149:156823d33999 | 1196 | } |
<> | 149:156823d33999 | 1197 | |
<> | 149:156823d33999 | 1198 | /* configure and validate Tx endpoint */ |
<> | 149:156823d33999 | 1199 | if (ep->doublebuffer == 0) |
<> | 149:156823d33999 | 1200 | { |
<> | 149:156823d33999 | 1201 | PCD_WritePMA(hpcd->Instance, ep->xfer_buff, ep->pmaadress, len); |
<> | 149:156823d33999 | 1202 | PCD_SET_EP_TX_CNT(hpcd->Instance, ep->num, len); |
<> | 149:156823d33999 | 1203 | } |
<> | 149:156823d33999 | 1204 | else |
<> | 149:156823d33999 | 1205 | { |
<> | 149:156823d33999 | 1206 | /*Set the Double buffer counter */ |
<> | 149:156823d33999 | 1207 | PCD_SET_EP_DBUF_CNT(hpcd->Instance, ep->num, ep->is_in, len); |
<> | 149:156823d33999 | 1208 | |
<> | 149:156823d33999 | 1209 | /*Write the data to the USB endpoint*/ |
<> | 149:156823d33999 | 1210 | if (PCD_GET_ENDPOINT(hpcd->Instance, ep->num)& USB_EP_DTOG_TX) |
<> | 149:156823d33999 | 1211 | { |
<> | 149:156823d33999 | 1212 | pmabuffer = ep->pmaaddr1; |
<> | 149:156823d33999 | 1213 | } |
<> | 149:156823d33999 | 1214 | else |
<> | 149:156823d33999 | 1215 | { |
<> | 149:156823d33999 | 1216 | pmabuffer = ep->pmaaddr0; |
<> | 149:156823d33999 | 1217 | } |
<> | 149:156823d33999 | 1218 | |
<> | 149:156823d33999 | 1219 | PCD_WritePMA(hpcd->Instance, ep->xfer_buff, pmabuffer, len); |
<> | 149:156823d33999 | 1220 | PCD_FreeUserBuffer(hpcd->Instance, ep->num, ep->is_in); |
<> | 149:156823d33999 | 1221 | } |
<> | 149:156823d33999 | 1222 | |
<> | 149:156823d33999 | 1223 | PCD_SET_EP_TX_STATUS(hpcd->Instance, ep->num, USB_EP_TX_VALID); |
<> | 149:156823d33999 | 1224 | |
<> | 149:156823d33999 | 1225 | __HAL_UNLOCK(hpcd); |
<> | 149:156823d33999 | 1226 | |
<> | 149:156823d33999 | 1227 | return HAL_OK; |
<> | 149:156823d33999 | 1228 | } |
<> | 149:156823d33999 | 1229 | |
<> | 149:156823d33999 | 1230 | /** |
<> | 149:156823d33999 | 1231 | * @brief Set a STALL condition over an endpoint |
<> | 149:156823d33999 | 1232 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 1233 | * @param ep_addr: endpoint address |
<> | 149:156823d33999 | 1234 | * @retval HAL status |
<> | 149:156823d33999 | 1235 | */ |
<> | 149:156823d33999 | 1236 | HAL_StatusTypeDef HAL_PCD_EP_SetStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr) |
<> | 149:156823d33999 | 1237 | { |
<> | 149:156823d33999 | 1238 | PCD_EPTypeDef *ep; |
<> | 149:156823d33999 | 1239 | |
<> | 149:156823d33999 | 1240 | __HAL_LOCK(hpcd); |
<> | 149:156823d33999 | 1241 | |
<> | 149:156823d33999 | 1242 | if ((0x80 & ep_addr) == 0x80) |
<> | 149:156823d33999 | 1243 | { |
<> | 149:156823d33999 | 1244 | ep = &hpcd->IN_ep[ep_addr & 0x7F]; |
<> | 149:156823d33999 | 1245 | } |
<> | 149:156823d33999 | 1246 | else |
<> | 149:156823d33999 | 1247 | { |
<> | 149:156823d33999 | 1248 | ep = &hpcd->OUT_ep[ep_addr]; |
<> | 149:156823d33999 | 1249 | } |
<> | 149:156823d33999 | 1250 | |
<> | 149:156823d33999 | 1251 | ep->is_stall = 1; |
<> | 149:156823d33999 | 1252 | ep->num = ep_addr & 0x7F; |
<> | 149:156823d33999 | 1253 | ep->is_in = ((ep_addr & 0x80) == 0x80); |
<> | 149:156823d33999 | 1254 | |
<> | 149:156823d33999 | 1255 | if (ep->num == 0) |
<> | 149:156823d33999 | 1256 | { |
<> | 149:156823d33999 | 1257 | /* This macro sets STALL status for RX & TX*/ |
<> | 149:156823d33999 | 1258 | PCD_SET_EP_TXRX_STATUS(hpcd->Instance, ep->num, USB_EP_RX_STALL, USB_EP_TX_STALL); |
<> | 149:156823d33999 | 1259 | } |
<> | 149:156823d33999 | 1260 | else |
<> | 149:156823d33999 | 1261 | { |
<> | 149:156823d33999 | 1262 | if (ep->is_in) |
<> | 149:156823d33999 | 1263 | { |
<> | 149:156823d33999 | 1264 | PCD_SET_EP_TX_STATUS(hpcd->Instance, ep->num , USB_EP_TX_STALL); |
<> | 149:156823d33999 | 1265 | } |
<> | 149:156823d33999 | 1266 | else |
<> | 149:156823d33999 | 1267 | { |
<> | 149:156823d33999 | 1268 | PCD_SET_EP_RX_STATUS(hpcd->Instance, ep->num , USB_EP_RX_STALL); |
<> | 149:156823d33999 | 1269 | } |
<> | 149:156823d33999 | 1270 | } |
<> | 149:156823d33999 | 1271 | __HAL_UNLOCK(hpcd); |
<> | 149:156823d33999 | 1272 | |
<> | 149:156823d33999 | 1273 | return HAL_OK; |
<> | 149:156823d33999 | 1274 | } |
<> | 149:156823d33999 | 1275 | |
<> | 149:156823d33999 | 1276 | /** |
<> | 149:156823d33999 | 1277 | * @brief Clear a STALL condition over in an endpoint |
<> | 149:156823d33999 | 1278 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 1279 | * @param ep_addr: endpoint address |
<> | 149:156823d33999 | 1280 | * @retval HAL status |
<> | 149:156823d33999 | 1281 | */ |
<> | 149:156823d33999 | 1282 | HAL_StatusTypeDef HAL_PCD_EP_ClrStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr) |
<> | 149:156823d33999 | 1283 | { |
<> | 149:156823d33999 | 1284 | PCD_EPTypeDef *ep; |
<> | 149:156823d33999 | 1285 | |
<> | 149:156823d33999 | 1286 | if ((0x80 & ep_addr) == 0x80) |
<> | 149:156823d33999 | 1287 | { |
<> | 149:156823d33999 | 1288 | ep = &hpcd->IN_ep[ep_addr & 0x7F]; |
<> | 149:156823d33999 | 1289 | } |
<> | 149:156823d33999 | 1290 | else |
<> | 149:156823d33999 | 1291 | { |
<> | 149:156823d33999 | 1292 | ep = &hpcd->OUT_ep[ep_addr]; |
<> | 149:156823d33999 | 1293 | } |
<> | 149:156823d33999 | 1294 | |
<> | 149:156823d33999 | 1295 | ep->is_stall = 0; |
<> | 149:156823d33999 | 1296 | ep->num = ep_addr & 0x7F; |
<> | 149:156823d33999 | 1297 | ep->is_in = ((ep_addr & 0x80) == 0x80); |
<> | 149:156823d33999 | 1298 | |
<> | 149:156823d33999 | 1299 | __HAL_LOCK(hpcd); |
<> | 149:156823d33999 | 1300 | |
<> | 149:156823d33999 | 1301 | if (ep->is_in) |
<> | 149:156823d33999 | 1302 | { |
<> | 149:156823d33999 | 1303 | PCD_CLEAR_TX_DTOG(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 1304 | PCD_SET_EP_TX_STATUS(hpcd->Instance, ep->num, USB_EP_TX_VALID); |
<> | 149:156823d33999 | 1305 | } |
<> | 149:156823d33999 | 1306 | else |
<> | 149:156823d33999 | 1307 | { |
<> | 149:156823d33999 | 1308 | PCD_CLEAR_RX_DTOG(hpcd->Instance, ep->num); |
<> | 149:156823d33999 | 1309 | PCD_SET_EP_RX_STATUS(hpcd->Instance, ep->num, USB_EP_RX_VALID); |
<> | 149:156823d33999 | 1310 | } |
<> | 149:156823d33999 | 1311 | __HAL_UNLOCK(hpcd); |
<> | 149:156823d33999 | 1312 | |
<> | 149:156823d33999 | 1313 | return HAL_OK; |
<> | 149:156823d33999 | 1314 | } |
<> | 149:156823d33999 | 1315 | |
<> | 149:156823d33999 | 1316 | /** |
<> | 149:156823d33999 | 1317 | * @brief Flush an endpoint |
<> | 149:156823d33999 | 1318 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 1319 | * @param ep_addr: endpoint address |
<> | 149:156823d33999 | 1320 | * @retval HAL status |
<> | 149:156823d33999 | 1321 | */ |
<> | 149:156823d33999 | 1322 | HAL_StatusTypeDef HAL_PCD_EP_Flush(PCD_HandleTypeDef *hpcd, uint8_t ep_addr) |
<> | 149:156823d33999 | 1323 | { |
<> | 149:156823d33999 | 1324 | return HAL_OK; |
<> | 149:156823d33999 | 1325 | } |
<> | 149:156823d33999 | 1326 | |
<> | 149:156823d33999 | 1327 | /** |
<> | 149:156823d33999 | 1328 | * @brief HAL_PCD_ActivateRemoteWakeup : active remote wakeup signalling |
<> | 149:156823d33999 | 1329 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 1330 | * @retval HAL status |
<> | 149:156823d33999 | 1331 | */ |
<> | 149:156823d33999 | 1332 | HAL_StatusTypeDef HAL_PCD_ActivateRemoteWakeup(PCD_HandleTypeDef *hpcd) |
<> | 149:156823d33999 | 1333 | { |
<> | 149:156823d33999 | 1334 | hpcd->Instance->CNTR |= USB_CNTR_RESUME; |
<> | 149:156823d33999 | 1335 | return HAL_OK; |
<> | 149:156823d33999 | 1336 | } |
<> | 149:156823d33999 | 1337 | |
<> | 149:156823d33999 | 1338 | /** |
<> | 149:156823d33999 | 1339 | * @brief HAL_PCD_DeActivateRemoteWakeup : de-active remote wakeup signalling |
<> | 149:156823d33999 | 1340 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 1341 | * @retval HAL status |
<> | 149:156823d33999 | 1342 | */ |
<> | 149:156823d33999 | 1343 | HAL_StatusTypeDef HAL_PCD_DeActivateRemoteWakeup(PCD_HandleTypeDef *hpcd) |
<> | 149:156823d33999 | 1344 | { |
<> | 149:156823d33999 | 1345 | hpcd->Instance->CNTR &= ~(USB_CNTR_RESUME); |
<> | 149:156823d33999 | 1346 | return HAL_OK; |
<> | 149:156823d33999 | 1347 | } |
<> | 149:156823d33999 | 1348 | |
<> | 149:156823d33999 | 1349 | /** |
<> | 149:156823d33999 | 1350 | * @} |
<> | 149:156823d33999 | 1351 | */ |
<> | 149:156823d33999 | 1352 | |
<> | 149:156823d33999 | 1353 | /** @defgroup PCD_Exported_Functions_Group4 Peripheral State functions |
<> | 149:156823d33999 | 1354 | * @brief Peripheral State functions |
<> | 149:156823d33999 | 1355 | * |
<> | 149:156823d33999 | 1356 | @verbatim |
<> | 149:156823d33999 | 1357 | =============================================================================== |
<> | 149:156823d33999 | 1358 | ##### Peripheral State functions ##### |
<> | 149:156823d33999 | 1359 | =============================================================================== |
<> | 149:156823d33999 | 1360 | [..] |
<> | 149:156823d33999 | 1361 | This subsection permits to get in run-time the status of the peripheral |
<> | 149:156823d33999 | 1362 | and the data flow. |
<> | 149:156823d33999 | 1363 | |
<> | 149:156823d33999 | 1364 | @endverbatim |
<> | 149:156823d33999 | 1365 | * @{ |
<> | 149:156823d33999 | 1366 | */ |
<> | 149:156823d33999 | 1367 | |
<> | 149:156823d33999 | 1368 | |
<> | 149:156823d33999 | 1369 | /** |
<> | 149:156823d33999 | 1370 | * @brief Return the PCD state |
<> | 149:156823d33999 | 1371 | * @param hpcd : PCD handle |
<> | 149:156823d33999 | 1372 | * @retval HAL state |
<> | 149:156823d33999 | 1373 | */ |
<> | 149:156823d33999 | 1374 | PCD_StateTypeDef HAL_PCD_GetState(PCD_HandleTypeDef *hpcd) |
<> | 149:156823d33999 | 1375 | { |
<> | 149:156823d33999 | 1376 | return hpcd->State; |
<> | 149:156823d33999 | 1377 | } |
<> | 149:156823d33999 | 1378 | |
<> | 149:156823d33999 | 1379 | |
<> | 149:156823d33999 | 1380 | /** |
<> | 149:156823d33999 | 1381 | * @brief Software Device Connection |
<> | 149:156823d33999 | 1382 | * @param hpcd: PCD handle |
<> | 149:156823d33999 | 1383 | * @param state: Device state |
<> | 149:156823d33999 | 1384 | * @retval None |
<> | 149:156823d33999 | 1385 | */ |
<> | 149:156823d33999 | 1386 | __weak void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state) |
<> | 149:156823d33999 | 1387 | { |
<> | 149:156823d33999 | 1388 | /* Prevent unused argument(s) compilation warning */ |
<> | 149:156823d33999 | 1389 | UNUSED(hpcd); |
<> | 149:156823d33999 | 1390 | UNUSED(state); |
<> | 149:156823d33999 | 1391 | |
<> | 149:156823d33999 | 1392 | /* NOTE : This function should not be modified, when the callback is needed, |
<> | 149:156823d33999 | 1393 | the HAL_PCDEx_SetConnectionState could be implenetd in the user file |
<> | 149:156823d33999 | 1394 | */ |
<> | 149:156823d33999 | 1395 | } |
<> | 149:156823d33999 | 1396 | |
<> | 149:156823d33999 | 1397 | /** |
<> | 149:156823d33999 | 1398 | * @} |
<> | 149:156823d33999 | 1399 | */ |
<> | 149:156823d33999 | 1400 | |
<> | 149:156823d33999 | 1401 | /** |
<> | 149:156823d33999 | 1402 | * @} |
<> | 149:156823d33999 | 1403 | */ |
<> | 149:156823d33999 | 1404 | |
<> | 149:156823d33999 | 1405 | |
<> | 149:156823d33999 | 1406 | #endif /* HAL_PCD_MODULE_ENABLED */ |
<> | 149:156823d33999 | 1407 | /** |
<> | 149:156823d33999 | 1408 | * @} |
<> | 149:156823d33999 | 1409 | */ |
<> | 149:156823d33999 | 1410 | |
<> | 149:156823d33999 | 1411 | /** |
<> | 149:156823d33999 | 1412 | * @} |
<> | 149:156823d33999 | 1413 | */ |
<> | 149:156823d33999 | 1414 | |
<> | 149:156823d33999 | 1415 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |