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