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