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