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