Fork of the official mbed C/C SDK provides the software platform and libraries to build your applications for RenBED.

Dependents:   1-RenBuggyTimed RenBED_RGB RenBED_RGB_PWM RenBED_RGB

Fork of mbed by mbed official

Committer:
elijahorr
Date:
Thu Apr 14 07:28:54 2016 +0000
Revision:
121:672067c3ada4
Parent:
109:9296ab0bfc11
.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 109:9296ab0bfc11 1 /**
Kojto 109:9296ab0bfc11 2 ******************************************************************************
Kojto 109:9296ab0bfc11 3 * @file stm32f3xx_hal_pcd.h
Kojto 109:9296ab0bfc11 4 * @author MCD Application Team
Kojto 109:9296ab0bfc11 5 * @version V1.1.0
Kojto 109:9296ab0bfc11 6 * @date 12-Sept-2014
Kojto 109:9296ab0bfc11 7 * @brief Header file of PCD HAL module.
Kojto 109:9296ab0bfc11 8 ******************************************************************************
Kojto 109:9296ab0bfc11 9 * @attention
Kojto 109:9296ab0bfc11 10 *
Kojto 109:9296ab0bfc11 11 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
Kojto 109:9296ab0bfc11 12 *
Kojto 109:9296ab0bfc11 13 * Redistribution and use in source and binary forms, with or without modification,
Kojto 109:9296ab0bfc11 14 * are permitted provided that the following conditions are met:
Kojto 109:9296ab0bfc11 15 * 1. Redistributions of source code must retain the above copyright notice,
Kojto 109:9296ab0bfc11 16 * this list of conditions and the following disclaimer.
Kojto 109:9296ab0bfc11 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
Kojto 109:9296ab0bfc11 18 * this list of conditions and the following disclaimer in the documentation
Kojto 109:9296ab0bfc11 19 * and/or other materials provided with the distribution.
Kojto 109:9296ab0bfc11 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Kojto 109:9296ab0bfc11 21 * may be used to endorse or promote products derived from this software
Kojto 109:9296ab0bfc11 22 * without specific prior written permission.
Kojto 109:9296ab0bfc11 23 *
Kojto 109:9296ab0bfc11 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Kojto 109:9296ab0bfc11 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Kojto 109:9296ab0bfc11 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Kojto 109:9296ab0bfc11 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Kojto 109:9296ab0bfc11 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Kojto 109:9296ab0bfc11 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Kojto 109:9296ab0bfc11 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Kojto 109:9296ab0bfc11 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Kojto 109:9296ab0bfc11 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Kojto 109:9296ab0bfc11 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Kojto 109:9296ab0bfc11 34 *
Kojto 109:9296ab0bfc11 35 ******************************************************************************
Kojto 109:9296ab0bfc11 36 */
Kojto 109:9296ab0bfc11 37
Kojto 109:9296ab0bfc11 38 /* Define to prevent recursive inclusion -------------------------------------*/
Kojto 109:9296ab0bfc11 39 #ifndef __STM32F3xx_HAL_PCD_H
Kojto 109:9296ab0bfc11 40 #define __STM32F3xx_HAL_PCD_H
Kojto 109:9296ab0bfc11 41
Kojto 109:9296ab0bfc11 42 #ifdef __cplusplus
Kojto 109:9296ab0bfc11 43 extern "C" {
Kojto 109:9296ab0bfc11 44 #endif
Kojto 109:9296ab0bfc11 45
Kojto 109:9296ab0bfc11 46 #if defined(STM32F302xE) || defined(STM32F303xE) || \
Kojto 109:9296ab0bfc11 47 defined(STM32F302xC) || defined(STM32F303xC) || \
Kojto 109:9296ab0bfc11 48 defined(STM32F302x8) || \
Kojto 109:9296ab0bfc11 49 defined(STM32F373xC)
Kojto 109:9296ab0bfc11 50
Kojto 109:9296ab0bfc11 51 /* Includes ------------------------------------------------------------------*/
Kojto 109:9296ab0bfc11 52 #include "stm32f3xx_hal_def.h"
Kojto 109:9296ab0bfc11 53
Kojto 109:9296ab0bfc11 54 /** @addtogroup STM32F3xx_HAL_Driver
Kojto 109:9296ab0bfc11 55 * @{
Kojto 109:9296ab0bfc11 56 */
Kojto 109:9296ab0bfc11 57
Kojto 109:9296ab0bfc11 58 /** @addtogroup PCD
Kojto 109:9296ab0bfc11 59 * @{
Kojto 109:9296ab0bfc11 60 */
Kojto 109:9296ab0bfc11 61
Kojto 109:9296ab0bfc11 62 /* Exported types ------------------------------------------------------------*/
Kojto 109:9296ab0bfc11 63 /** @defgroup PCD_Exported_Types PCD Exported Types
Kojto 109:9296ab0bfc11 64 * @{
Kojto 109:9296ab0bfc11 65 */
Kojto 109:9296ab0bfc11 66
Kojto 109:9296ab0bfc11 67 /**
Kojto 109:9296ab0bfc11 68 * @brief PCD State structures definition
Kojto 109:9296ab0bfc11 69 */
Kojto 109:9296ab0bfc11 70 typedef enum
Kojto 109:9296ab0bfc11 71 {
Kojto 109:9296ab0bfc11 72 PCD_READY = 0x00,
Kojto 109:9296ab0bfc11 73 PCD_ERROR = 0x01,
Kojto 109:9296ab0bfc11 74 PCD_BUSY = 0x02,
Kojto 109:9296ab0bfc11 75 PCD_TIMEOUT = 0x03
Kojto 109:9296ab0bfc11 76 } PCD_StateTypeDef;
Kojto 109:9296ab0bfc11 77
Kojto 109:9296ab0bfc11 78 typedef enum
Kojto 109:9296ab0bfc11 79 {
Kojto 109:9296ab0bfc11 80 /* double buffered endpoint direction */
Kojto 109:9296ab0bfc11 81 PCD_EP_DBUF_OUT,
Kojto 109:9296ab0bfc11 82 PCD_EP_DBUF_IN,
Kojto 109:9296ab0bfc11 83 PCD_EP_DBUF_ERR,
Kojto 109:9296ab0bfc11 84 }PCD_EP_DBUF_DIR;
Kojto 109:9296ab0bfc11 85
Kojto 109:9296ab0bfc11 86 /* endpoint buffer number */
Kojto 109:9296ab0bfc11 87 typedef enum
Kojto 109:9296ab0bfc11 88 {
Kojto 109:9296ab0bfc11 89 PCD_EP_NOBUF,
Kojto 109:9296ab0bfc11 90 PCD_EP_BUF0,
Kojto 109:9296ab0bfc11 91 PCD_EP_BUF1
Kojto 109:9296ab0bfc11 92 }PCD_EP_BUF_NUM;
Kojto 109:9296ab0bfc11 93
Kojto 109:9296ab0bfc11 94 /**
Kojto 109:9296ab0bfc11 95 * @brief PCD Initialization Structure definition
Kojto 109:9296ab0bfc11 96 */
Kojto 109:9296ab0bfc11 97 typedef struct
Kojto 109:9296ab0bfc11 98 {
Kojto 109:9296ab0bfc11 99 uint32_t dev_endpoints; /*!< Device Endpoints number.
Kojto 109:9296ab0bfc11 100 This parameter depends on the used USB core.
Kojto 109:9296ab0bfc11 101 This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
Kojto 109:9296ab0bfc11 102
Kojto 109:9296ab0bfc11 103 uint32_t speed; /*!< USB Core speed.
Kojto 109:9296ab0bfc11 104 This parameter can be any value of @ref USB_Core_Speed */
Kojto 109:9296ab0bfc11 105
Kojto 109:9296ab0bfc11 106 uint32_t ep0_mps; /*!< Set the Endpoint 0 Max Packet size.
Kojto 109:9296ab0bfc11 107 This parameter can be any value of @ref USB_EP0_MPS */
Kojto 109:9296ab0bfc11 108
Kojto 109:9296ab0bfc11 109 uint32_t phy_itface; /*!< Select the used PHY interface.
Kojto 109:9296ab0bfc11 110 This parameter can be any value of @ref USB_Core_PHY */
Kojto 109:9296ab0bfc11 111
Kojto 109:9296ab0bfc11 112 uint32_t Sof_enable; /*!< Enable or disable the output of the SOF signal. */
Kojto 109:9296ab0bfc11 113
Kojto 109:9296ab0bfc11 114 uint32_t low_power_enable; /*!< Enable or disable Low Power mode */
Kojto 109:9296ab0bfc11 115
Kojto 109:9296ab0bfc11 116 uint32_t lpm_enable; /*!< Enable or disable Battery charging. */
Kojto 109:9296ab0bfc11 117
Kojto 109:9296ab0bfc11 118 uint32_t battery_charging_enable; /*!< Enable or disable Battery charging. */
Kojto 109:9296ab0bfc11 119
Kojto 109:9296ab0bfc11 120 }PCD_InitTypeDef;
Kojto 109:9296ab0bfc11 121
Kojto 109:9296ab0bfc11 122 typedef struct
Kojto 109:9296ab0bfc11 123 {
Kojto 109:9296ab0bfc11 124 uint8_t num; /*!< Endpoint number
Kojto 109:9296ab0bfc11 125 This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
Kojto 109:9296ab0bfc11 126
Kojto 109:9296ab0bfc11 127 uint8_t is_in; /*!< Endpoint direction
Kojto 109:9296ab0bfc11 128 This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
Kojto 109:9296ab0bfc11 129
Kojto 109:9296ab0bfc11 130 uint8_t is_stall; /*!< Endpoint stall condition
Kojto 109:9296ab0bfc11 131 This parameter must be a number between Min_Data = 0 and Max_Data = 1 */
Kojto 109:9296ab0bfc11 132
Kojto 109:9296ab0bfc11 133 uint8_t type; /*!< Endpoint type
Kojto 109:9296ab0bfc11 134 This parameter can be any value of @ref USB_EP_Type */
Kojto 109:9296ab0bfc11 135
Kojto 109:9296ab0bfc11 136 uint16_t pmaadress; /*!< PMA Address
Kojto 109:9296ab0bfc11 137 This parameter can be any value between Min_addr = 0 and Max_addr = 1K */
Kojto 109:9296ab0bfc11 138
Kojto 109:9296ab0bfc11 139
Kojto 109:9296ab0bfc11 140 uint16_t pmaaddr0; /*!< PMA Address0
Kojto 109:9296ab0bfc11 141 This parameter can be any value between Min_addr = 0 and Max_addr = 1K */
Kojto 109:9296ab0bfc11 142
Kojto 109:9296ab0bfc11 143
Kojto 109:9296ab0bfc11 144 uint16_t pmaaddr1; /*!< PMA Address1
Kojto 109:9296ab0bfc11 145 This parameter can be any value between Min_addr = 0 and Max_addr = 1K */
Kojto 109:9296ab0bfc11 146
Kojto 109:9296ab0bfc11 147
Kojto 109:9296ab0bfc11 148 uint8_t doublebuffer; /*!< Double buffer enable
Kojto 109:9296ab0bfc11 149 This parameter can be 0 or 1 */
Kojto 109:9296ab0bfc11 150
Kojto 109:9296ab0bfc11 151 uint32_t maxpacket; /*!< Endpoint Max packet size
Kojto 109:9296ab0bfc11 152 This parameter must be a number between Min_Data = 0 and Max_Data = 64KB */
Kojto 109:9296ab0bfc11 153
Kojto 109:9296ab0bfc11 154 uint8_t *xfer_buff; /*!< Pointer to transfer buffer */
Kojto 109:9296ab0bfc11 155
Kojto 109:9296ab0bfc11 156
Kojto 109:9296ab0bfc11 157 uint32_t xfer_len; /*!< Current transfer length */
Kojto 109:9296ab0bfc11 158
Kojto 109:9296ab0bfc11 159 uint32_t xfer_count; /*!< Partial transfer length in case of multi packet transfer */
Kojto 109:9296ab0bfc11 160
Kojto 109:9296ab0bfc11 161 }PCD_EPTypeDef;
Kojto 109:9296ab0bfc11 162
Kojto 109:9296ab0bfc11 163 typedef USB_TypeDef PCD_TypeDef;
Kojto 109:9296ab0bfc11 164
Kojto 109:9296ab0bfc11 165 /**
Kojto 109:9296ab0bfc11 166 * @brief PCD Handle Structure definition
Kojto 109:9296ab0bfc11 167 */
Kojto 109:9296ab0bfc11 168 typedef struct
Kojto 109:9296ab0bfc11 169 {
Kojto 109:9296ab0bfc11 170 PCD_TypeDef *Instance; /*!< Register base address */
Kojto 109:9296ab0bfc11 171 PCD_InitTypeDef Init; /*!< PCD required parameters */
Kojto 109:9296ab0bfc11 172 __IO uint8_t USB_Address; /*!< USB Address */
Kojto 109:9296ab0bfc11 173 PCD_EPTypeDef IN_ep[8]; /*!< IN endpoint parameters */
Kojto 109:9296ab0bfc11 174 PCD_EPTypeDef OUT_ep[8]; /*!< OUT endpoint parameters */
Kojto 109:9296ab0bfc11 175 HAL_LockTypeDef Lock; /*!< PCD peripheral status */
Kojto 109:9296ab0bfc11 176 __IO PCD_StateTypeDef State; /*!< PCD communication state */
Kojto 109:9296ab0bfc11 177 uint32_t Setup[12]; /*!< Setup packet buffer */
Kojto 109:9296ab0bfc11 178 void *pData; /*!< Pointer to upper stack Handler */
Kojto 109:9296ab0bfc11 179
Kojto 109:9296ab0bfc11 180 } PCD_HandleTypeDef;
Kojto 109:9296ab0bfc11 181
Kojto 109:9296ab0bfc11 182 /**
Kojto 109:9296ab0bfc11 183 * @}
Kojto 109:9296ab0bfc11 184 */
Kojto 109:9296ab0bfc11 185
Kojto 109:9296ab0bfc11 186 #include "stm32f3xx_hal_pcd_ex.h"
Kojto 109:9296ab0bfc11 187 /* Exported constants --------------------------------------------------------*/
Kojto 109:9296ab0bfc11 188 /** @defgroup PCD_Exported_Constants PCD Exported Constants
Kojto 109:9296ab0bfc11 189 * @{
Kojto 109:9296ab0bfc11 190 */
Kojto 109:9296ab0bfc11 191
Kojto 109:9296ab0bfc11 192 /** @defgroup USB_Core_Speed USB Core Speed
Kojto 109:9296ab0bfc11 193 * @{
Kojto 109:9296ab0bfc11 194 */
Kojto 109:9296ab0bfc11 195 #define PCD_SPEED_HIGH 0 /* Not Supported */
Kojto 109:9296ab0bfc11 196 #define PCD_SPEED_FULL 2
Kojto 109:9296ab0bfc11 197 /**
Kojto 109:9296ab0bfc11 198 * @}
Kojto 109:9296ab0bfc11 199 */
Kojto 109:9296ab0bfc11 200
Kojto 109:9296ab0bfc11 201 /** @defgroup USB_Core_PHY USB Core PHY
Kojto 109:9296ab0bfc11 202 * @{
Kojto 109:9296ab0bfc11 203 */
Kojto 109:9296ab0bfc11 204 #define PCD_PHY_EMBEDDED 2
Kojto 109:9296ab0bfc11 205 /**
Kojto 109:9296ab0bfc11 206 * @}
Kojto 109:9296ab0bfc11 207 */
Kojto 109:9296ab0bfc11 208
Kojto 109:9296ab0bfc11 209 /** @defgroup USB_EP0_MPS USB EP0 MPS
Kojto 109:9296ab0bfc11 210 * @{
Kojto 109:9296ab0bfc11 211 */
Kojto 109:9296ab0bfc11 212 #define DEP0CTL_MPS_64 0
Kojto 109:9296ab0bfc11 213 #define DEP0CTL_MPS_32 1
Kojto 109:9296ab0bfc11 214 #define DEP0CTL_MPS_16 2
Kojto 109:9296ab0bfc11 215 #define DEP0CTL_MPS_8 3
Kojto 109:9296ab0bfc11 216
Kojto 109:9296ab0bfc11 217 #define PCD_EP0MPS_64 DEP0CTL_MPS_64
Kojto 109:9296ab0bfc11 218 #define PCD_EP0MPS_32 DEP0CTL_MPS_32
Kojto 109:9296ab0bfc11 219 #define PCD_EP0MPS_16 DEP0CTL_MPS_16
Kojto 109:9296ab0bfc11 220 #define PCD_EP0MPS_08 DEP0CTL_MPS_8
Kojto 109:9296ab0bfc11 221 /**
Kojto 109:9296ab0bfc11 222 * @}
Kojto 109:9296ab0bfc11 223 */
Kojto 109:9296ab0bfc11 224
Kojto 109:9296ab0bfc11 225 /** @defgroup USB_EP_Type USB EP Type
Kojto 109:9296ab0bfc11 226 * @{
Kojto 109:9296ab0bfc11 227 */
Kojto 109:9296ab0bfc11 228 #define PCD_EP_TYPE_CTRL 0
Kojto 109:9296ab0bfc11 229 #define PCD_EP_TYPE_ISOC 1
Kojto 109:9296ab0bfc11 230 #define PCD_EP_TYPE_BULK 2
Kojto 109:9296ab0bfc11 231 #define PCD_EP_TYPE_INTR 3
Kojto 109:9296ab0bfc11 232 /**
Kojto 109:9296ab0bfc11 233 * @}
Kojto 109:9296ab0bfc11 234 */
Kojto 109:9296ab0bfc11 235
Kojto 109:9296ab0bfc11 236 /** @defgroup USB_ENDP USB ENDP
Kojto 109:9296ab0bfc11 237 * @{
Kojto 109:9296ab0bfc11 238 */
Kojto 109:9296ab0bfc11 239
Kojto 109:9296ab0bfc11 240 #define PCD_ENDP0 ((uint8_t)0)
Kojto 109:9296ab0bfc11 241 #define PCD_ENDP1 ((uint8_t)1)
Kojto 109:9296ab0bfc11 242 #define PCD_ENDP2 ((uint8_t)2)
Kojto 109:9296ab0bfc11 243 #define PCD_ENDP3 ((uint8_t)3)
Kojto 109:9296ab0bfc11 244 #define PCD_ENDP4 ((uint8_t)4)
Kojto 109:9296ab0bfc11 245 #define PCD_ENDP5 ((uint8_t)5)
Kojto 109:9296ab0bfc11 246 #define PCD_ENDP6 ((uint8_t)6)
Kojto 109:9296ab0bfc11 247 #define PCD_ENDP7 ((uint8_t)7)
Kojto 109:9296ab0bfc11 248
Kojto 109:9296ab0bfc11 249 /* Endpoint Kind */
Kojto 109:9296ab0bfc11 250 #define PCD_SNG_BUF 0
Kojto 109:9296ab0bfc11 251 #define PCD_DBL_BUF 1
Kojto 109:9296ab0bfc11 252
Kojto 109:9296ab0bfc11 253 #define IS_PCD_ALL_INSTANCE IS_USB_ALL_INSTANCE
Kojto 109:9296ab0bfc11 254
Kojto 109:9296ab0bfc11 255 /**
Kojto 109:9296ab0bfc11 256 * @}
Kojto 109:9296ab0bfc11 257 */
Kojto 109:9296ab0bfc11 258
Kojto 109:9296ab0bfc11 259 /**
Kojto 109:9296ab0bfc11 260 * @}
Kojto 109:9296ab0bfc11 261 */
Kojto 109:9296ab0bfc11 262
Kojto 109:9296ab0bfc11 263 /* Exported macros -----------------------------------------------------------*/
Kojto 109:9296ab0bfc11 264
Kojto 109:9296ab0bfc11 265 /** @defgroup PCD_Exported_Macros PCD Exported Macros
Kojto 109:9296ab0bfc11 266 * @brief macros to handle interrupts and specific clock configurations
Kojto 109:9296ab0bfc11 267 * @{
Kojto 109:9296ab0bfc11 268 */
Kojto 109:9296ab0bfc11 269 #define __HAL_PCD_GET_FLAG(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->ISTR) & (__INTERRUPT__)) == (__INTERRUPT__))
Kojto 109:9296ab0bfc11 270 #define __HAL_PCD_CLEAR_FLAG(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->ISTR) = ~(__INTERRUPT__))
Kojto 109:9296ab0bfc11 271
Kojto 109:9296ab0bfc11 272 #define USB_EXTI_LINE_WAKEUP ((uint32_t)0x00040000) /*!< External interrupt line 18 Connected to the USB FS EXTI Line */
Kojto 109:9296ab0bfc11 273
Kojto 109:9296ab0bfc11 274 #define __HAL_USB_EXTI_ENABLE_IT() EXTI->IMR |= USB_EXTI_LINE_WAKEUP
Kojto 109:9296ab0bfc11 275 #define __HAL_USB_EXTI_DISABLE_IT() EXTI->IMR &= ~(USB_EXTI_LINE_WAKEUP)
Kojto 109:9296ab0bfc11 276 #define __HAL_USB_EXTI_GENERATE_SWIT(__EXTILINE__) (EXTI->SWIER |= (__EXTILINE__))
Kojto 109:9296ab0bfc11 277
Kojto 109:9296ab0bfc11 278 #define __HAL_USB_EXTI_GET_FLAG() EXTI->PR & (USB_EXTI_LINE_WAKEUP)
Kojto 109:9296ab0bfc11 279 #define __HAL_USB_EXTI_CLEAR_FLAG() EXTI->PR = USB_EXTI_LINE_WAKEUP
Kojto 109:9296ab0bfc11 280
Kojto 109:9296ab0bfc11 281 #define __HAL_USB_EXTI_SET_RISING_EDGE_TRIGGER() do {\
Kojto 109:9296ab0bfc11 282 EXTI->FTSR &= ~(USB_EXTI_LINE_WAKEUP);\
Kojto 109:9296ab0bfc11 283 EXTI->RTSR |= USB_EXTI_LINE_WAKEUP;\
Kojto 109:9296ab0bfc11 284 } while(0)
Kojto 109:9296ab0bfc11 285
Kojto 109:9296ab0bfc11 286 #define __HAL_USB_EXTI_SET_FALLING_EDGE_TRIGGER() do {\
Kojto 109:9296ab0bfc11 287 EXTI->FTSR |= (USB_EXTI_LINE_WAKEUP);\
Kojto 109:9296ab0bfc11 288 EXTI->RTSR &= ~(USB_EXTI_LINE_WAKEUP);\
Kojto 109:9296ab0bfc11 289 } while(0)
Kojto 109:9296ab0bfc11 290
Kojto 109:9296ab0bfc11 291 #define __HAL_USB_EXTI_SET_FALLINGRISING_TRIGGER() do {\
Kojto 109:9296ab0bfc11 292 EXTI->RTSR &= ~(USB_EXTI_LINE_WAKEUP);\
Kojto 109:9296ab0bfc11 293 EXTI->FTSR &= ~(USB_EXTI_LINE_WAKEUP);\
Kojto 109:9296ab0bfc11 294 EXTI->RTSR |= USB_EXTI_LINE_WAKEUP;\
Kojto 109:9296ab0bfc11 295 EXTI->FTSR |= USB_EXTI_LINE_WAKEUP;\
Kojto 109:9296ab0bfc11 296 } while(0)
Kojto 109:9296ab0bfc11 297 /**
Kojto 109:9296ab0bfc11 298 * @}
Kojto 109:9296ab0bfc11 299 */
Kojto 109:9296ab0bfc11 300
Kojto 109:9296ab0bfc11 301 /* Internal macros -----------------------------------------------------------*/
Kojto 109:9296ab0bfc11 302
Kojto 109:9296ab0bfc11 303 /** @defgroup PCD_Private_Macros PCD Private Macros
Kojto 109:9296ab0bfc11 304 * @brief macros to handle interrupts and specific clock configurations
Kojto 109:9296ab0bfc11 305 * @{
Kojto 109:9296ab0bfc11 306 */
Kojto 109:9296ab0bfc11 307
Kojto 109:9296ab0bfc11 308 /* SetENDPOINT */
Kojto 109:9296ab0bfc11 309 #define PCD_SET_ENDPOINT(USBx, bEpNum,wRegValue) (*(&USBx->EP0R + bEpNum * 2)= (uint16_t)wRegValue)
Kojto 109:9296ab0bfc11 310
Kojto 109:9296ab0bfc11 311 /* GetENDPOINT */
Kojto 109:9296ab0bfc11 312 #define PCD_GET_ENDPOINT(USBx, bEpNum) (*(&USBx->EP0R + bEpNum * 2))
Kojto 109:9296ab0bfc11 313
Kojto 109:9296ab0bfc11 314
Kojto 109:9296ab0bfc11 315
Kojto 109:9296ab0bfc11 316 /**
Kojto 109:9296ab0bfc11 317 * @brief sets the type in the endpoint register(bits EP_TYPE[1:0])
Kojto 109:9296ab0bfc11 318 * @param USBx: USB peripheral instance register address.
Kojto 109:9296ab0bfc11 319 * @param bEpNum: Endpoint Number.
Kojto 109:9296ab0bfc11 320 * @param wType: Endpoint Type.
Kojto 109:9296ab0bfc11 321 * @retval None
Kojto 109:9296ab0bfc11 322 */
Kojto 109:9296ab0bfc11 323 #define PCD_SET_EPTYPE(USBx, bEpNum,wType) (PCD_SET_ENDPOINT(USBx, bEpNum,\
Kojto 109:9296ab0bfc11 324 ((PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EP_T_MASK) | wType )))
Kojto 109:9296ab0bfc11 325
Kojto 109:9296ab0bfc11 326 /**
Kojto 109:9296ab0bfc11 327 * @brief gets the type in the endpoint register(bits EP_TYPE[1:0])
Kojto 109:9296ab0bfc11 328 * @param USBx: USB peripheral instance register address.
Kojto 109:9296ab0bfc11 329 * @param bEpNum: Endpoint Number.
Kojto 109:9296ab0bfc11 330 * @retval Endpoint Type
Kojto 109:9296ab0bfc11 331 */
Kojto 109:9296ab0bfc11 332 #define PCD_GET_EPTYPE(USBx, bEpNum) (PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EP_T_FIELD)
Kojto 109:9296ab0bfc11 333
Kojto 109:9296ab0bfc11 334
Kojto 109:9296ab0bfc11 335 /**
Kojto 109:9296ab0bfc11 336 * @brief free buffer used from the application realizing it to the line
Kojto 109:9296ab0bfc11 337 toggles bit SW_BUF in the double buffered endpoint register
Kojto 109:9296ab0bfc11 338 * @param USBx: USB peripheral instance register address.
Kojto 109:9296ab0bfc11 339 * @param bEpNum: Endpoint Number.
Kojto 109:9296ab0bfc11 340 * @param bDir: Direction
Kojto 109:9296ab0bfc11 341 * @retval None
Kojto 109:9296ab0bfc11 342 */
Kojto 109:9296ab0bfc11 343 #define PCD_FreeUserBuffer(USBx, bEpNum, bDir)\
Kojto 109:9296ab0bfc11 344 {\
Kojto 109:9296ab0bfc11 345 if (bDir == PCD_EP_DBUF_OUT)\
Kojto 109:9296ab0bfc11 346 { /* OUT double buffered endpoint */\
Kojto 109:9296ab0bfc11 347 PCD_TX_DTOG(USBx, bEpNum);\
Kojto 109:9296ab0bfc11 348 }\
Kojto 109:9296ab0bfc11 349 else if (bDir == PCD_EP_DBUF_IN)\
Kojto 109:9296ab0bfc11 350 { /* IN double buffered endpoint */\
Kojto 109:9296ab0bfc11 351 PCD_RX_DTOG(USBx, bEpNum);\
Kojto 109:9296ab0bfc11 352 }\
Kojto 109:9296ab0bfc11 353 }
Kojto 109:9296ab0bfc11 354
Kojto 109:9296ab0bfc11 355 /**
Kojto 109:9296ab0bfc11 356 * @brief gets direction of the double buffered endpoint
Kojto 109:9296ab0bfc11 357 * @param USBx: USB peripheral instance register address.
Kojto 109:9296ab0bfc11 358 * @param bEpNum: Endpoint Number.
Kojto 109:9296ab0bfc11 359 * @retval EP_DBUF_OUT, EP_DBUF_IN,
Kojto 109:9296ab0bfc11 360 * EP_DBUF_ERR if the endpoint counter not yet programmed.
Kojto 109:9296ab0bfc11 361 */
Kojto 109:9296ab0bfc11 362 #define PCD_GET_DB_DIR(USBx, bEpNum)\
Kojto 109:9296ab0bfc11 363 {\
Kojto 109:9296ab0bfc11 364 if ((uint16_t)(*PCD_EP_RX_CNT(USBx, bEpNum) & 0xFC00) != 0)\
Kojto 109:9296ab0bfc11 365 return(PCD_EP_DBUF_OUT);\
Kojto 109:9296ab0bfc11 366 else if (((uint16_t)(*PCD_EP_TX_CNT(USBx, bEpNum)) & 0x03FF) != 0)\
Kojto 109:9296ab0bfc11 367 return(PCD_EP_DBUF_IN);\
Kojto 109:9296ab0bfc11 368 else\
Kojto 109:9296ab0bfc11 369 return(PCD_EP_DBUF_ERR);\
Kojto 109:9296ab0bfc11 370 }
Kojto 109:9296ab0bfc11 371
Kojto 109:9296ab0bfc11 372 /**
Kojto 109:9296ab0bfc11 373 * @brief sets the status for tx transfer (bits STAT_TX[1:0]).
Kojto 109:9296ab0bfc11 374 * @param USBx: USB peripheral instance register address.
Kojto 109:9296ab0bfc11 375 * @param bEpNum: Endpoint Number.
Kojto 109:9296ab0bfc11 376 * @param wState: new state
Kojto 109:9296ab0bfc11 377 * @retval None
Kojto 109:9296ab0bfc11 378 */
Kojto 109:9296ab0bfc11 379 #define PCD_SET_EP_TX_STATUS(USBx, bEpNum, wState) {\
Kojto 109:9296ab0bfc11 380 register uint16_t _wRegVal; \
Kojto 109:9296ab0bfc11 381 \
Kojto 109:9296ab0bfc11 382 _wRegVal = PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EPTX_DTOGMASK;\
Kojto 109:9296ab0bfc11 383 /* toggle first bit ? */ \
Kojto 109:9296ab0bfc11 384 if((USB_EPTX_DTOG1 & wState)!= 0) \
Kojto 109:9296ab0bfc11 385 _wRegVal ^= USB_EPTX_DTOG1; \
Kojto 109:9296ab0bfc11 386 /* toggle second bit ? */ \
Kojto 109:9296ab0bfc11 387 if((USB_EPTX_DTOG2 & wState)!= 0) \
Kojto 109:9296ab0bfc11 388 _wRegVal ^= USB_EPTX_DTOG2; \
Kojto 109:9296ab0bfc11 389 PCD_SET_ENDPOINT(USBx, bEpNum, (_wRegVal | USB_EP_CTR_RX|USB_EP_CTR_TX)); \
Kojto 109:9296ab0bfc11 390 } /* PCD_SET_EP_TX_STATUS */
Kojto 109:9296ab0bfc11 391
Kojto 109:9296ab0bfc11 392 /**
Kojto 109:9296ab0bfc11 393 * @brief sets the status for rx transfer (bits STAT_TX[1:0])
Kojto 109:9296ab0bfc11 394 * @param USBx: USB peripheral instance register address.
Kojto 109:9296ab0bfc11 395 * @param bEpNum: Endpoint Number.
Kojto 109:9296ab0bfc11 396 * @param wState: new state
Kojto 109:9296ab0bfc11 397 * @retval None
Kojto 109:9296ab0bfc11 398 */
Kojto 109:9296ab0bfc11 399 #define PCD_SET_EP_RX_STATUS(USBx, bEpNum,wState) {\
Kojto 109:9296ab0bfc11 400 register uint16_t _wRegVal; \
Kojto 109:9296ab0bfc11 401 \
Kojto 109:9296ab0bfc11 402 _wRegVal = PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EPRX_DTOGMASK;\
Kojto 109:9296ab0bfc11 403 /* toggle first bit ? */ \
Kojto 109:9296ab0bfc11 404 if((USB_EPRX_DTOG1 & wState)!= 0) \
Kojto 109:9296ab0bfc11 405 _wRegVal ^= USB_EPRX_DTOG1; \
Kojto 109:9296ab0bfc11 406 /* toggle second bit ? */ \
Kojto 109:9296ab0bfc11 407 if((USB_EPRX_DTOG2 & wState)!= 0) \
Kojto 109:9296ab0bfc11 408 _wRegVal ^= USB_EPRX_DTOG2; \
Kojto 109:9296ab0bfc11 409 PCD_SET_ENDPOINT(USBx, bEpNum, (_wRegVal | USB_EP_CTR_RX|USB_EP_CTR_TX)); \
Kojto 109:9296ab0bfc11 410 } /* PCD_SET_EP_RX_STATUS */
Kojto 109:9296ab0bfc11 411
Kojto 109:9296ab0bfc11 412 /**
Kojto 109:9296ab0bfc11 413 * @brief sets the status for rx & tx (bits STAT_TX[1:0] & STAT_RX[1:0])
Kojto 109:9296ab0bfc11 414 * @param USBx: USB peripheral instance register address.
Kojto 109:9296ab0bfc11 415 * @param bEpNum: Endpoint Number.
Kojto 109:9296ab0bfc11 416 * @param wStaterx: new state.
Kojto 109:9296ab0bfc11 417 * @param wStatetx: new state.
Kojto 109:9296ab0bfc11 418 * @retval None
Kojto 109:9296ab0bfc11 419 */
Kojto 109:9296ab0bfc11 420 #define PCD_SET_EP_TXRX_STATUS(USBx,bEpNum,wStaterx,wStatetx) {\
Kojto 109:9296ab0bfc11 421 register uint32_t _wRegVal; \
Kojto 109:9296ab0bfc11 422 \
Kojto 109:9296ab0bfc11 423 _wRegVal = PCD_GET_ENDPOINT(USBx, bEpNum) & (USB_EPRX_DTOGMASK |USB_EPTX_STAT) ;\
Kojto 109:9296ab0bfc11 424 /* toggle first bit ? */ \
Kojto 109:9296ab0bfc11 425 if((USB_EPRX_DTOG1 & wStaterx)!= 0) \
Kojto 109:9296ab0bfc11 426 _wRegVal ^= USB_EPRX_DTOG1; \
Kojto 109:9296ab0bfc11 427 /* toggle second bit ? */ \
Kojto 109:9296ab0bfc11 428 if((USB_EPRX_DTOG2 & wStaterx)!= 0) \
Kojto 109:9296ab0bfc11 429 _wRegVal ^= USB_EPRX_DTOG2; \
Kojto 109:9296ab0bfc11 430 /* toggle first bit ? */ \
Kojto 109:9296ab0bfc11 431 if((USB_EPTX_DTOG1 & wStatetx)!= 0) \
Kojto 109:9296ab0bfc11 432 _wRegVal ^= USB_EPTX_DTOG1; \
Kojto 109:9296ab0bfc11 433 /* toggle second bit ? */ \
Kojto 109:9296ab0bfc11 434 if((USB_EPTX_DTOG2 & wStatetx)!= 0) \
Kojto 109:9296ab0bfc11 435 _wRegVal ^= USB_EPTX_DTOG2; \
Kojto 109:9296ab0bfc11 436 PCD_SET_ENDPOINT(USBx, bEpNum, _wRegVal | USB_EP_CTR_RX|USB_EP_CTR_TX); \
Kojto 109:9296ab0bfc11 437 } /* PCD_SET_EP_TXRX_STATUS */
Kojto 109:9296ab0bfc11 438
Kojto 109:9296ab0bfc11 439 /**
Kojto 109:9296ab0bfc11 440 * @brief gets the status for tx/rx transfer (bits STAT_TX[1:0]
Kojto 109:9296ab0bfc11 441 * /STAT_RX[1:0])
Kojto 109:9296ab0bfc11 442 * @param USBx: USB peripheral instance register address.
Kojto 109:9296ab0bfc11 443 * @param bEpNum: Endpoint Number.
Kojto 109:9296ab0bfc11 444 * @retval status
Kojto 109:9296ab0bfc11 445 */
Kojto 109:9296ab0bfc11 446 #define PCD_GET_EP_TX_STATUS(USBx, bEpNum) ((uint16_t)PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EPTX_STAT)
Kojto 109:9296ab0bfc11 447
Kojto 109:9296ab0bfc11 448 #define PCD_GET_EP_RX_STATUS(USBx, bEpNum) ((uint16_t)PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EPRX_STAT)
Kojto 109:9296ab0bfc11 449
Kojto 109:9296ab0bfc11 450 /**
Kojto 109:9296ab0bfc11 451 * @brief sets directly the VALID tx/rx-status into the endpoint register
Kojto 109:9296ab0bfc11 452 * @param USBx: USB peripheral instance register address.
Kojto 109:9296ab0bfc11 453 * @param bEpNum: Endpoint Number.
Kojto 109:9296ab0bfc11 454 * @retval None
Kojto 109:9296ab0bfc11 455 */
Kojto 109:9296ab0bfc11 456 #define PCD_SET_EP_TX_VALID(USBx, bEpNum) (PCD_SET_EP_TX_STATUS(USBx, bEpNum, USB_EP_TX_VALID))
Kojto 109:9296ab0bfc11 457
Kojto 109:9296ab0bfc11 458 #define PCD_SET_EP_RX_VALID(USBx, bEpNum) (PCD_SET_EP_RX_STATUS(USBx, bEpNum, USB_EP_RX_VALID))
Kojto 109:9296ab0bfc11 459
Kojto 109:9296ab0bfc11 460 /**
Kojto 109:9296ab0bfc11 461 * @brief checks stall condition in an endpoint.
Kojto 109:9296ab0bfc11 462 * @param USBx: USB peripheral instance register address.
Kojto 109:9296ab0bfc11 463 * @param bEpNum: Endpoint Number.
Kojto 109:9296ab0bfc11 464 * @retval TRUE = endpoint in stall condition.
Kojto 109:9296ab0bfc11 465 */
Kojto 109:9296ab0bfc11 466 #define PCD_GET_EP_TX_STALL_STATUS(USBx, bEpNum) (PCD_GET_EP_TX_STATUS(USBx, bEpNum) \
Kojto 109:9296ab0bfc11 467 == USB_EP_TX_STALL)
Kojto 109:9296ab0bfc11 468 #define PCD_GET_EP_RX_STALL_STATUS(USBx, bEpNum) (PCD_GET_EP_RX_STATUS(USBx, bEpNum) \
Kojto 109:9296ab0bfc11 469 == USB_EP_RX_STALL)
Kojto 109:9296ab0bfc11 470
Kojto 109:9296ab0bfc11 471 /**
Kojto 109:9296ab0bfc11 472 * @brief set & clear EP_KIND bit.
Kojto 109:9296ab0bfc11 473 * @param USBx: USB peripheral instance register address.
Kojto 109:9296ab0bfc11 474 * @param bEpNum: Endpoint Number.
Kojto 109:9296ab0bfc11 475 * @retval None
Kojto 109:9296ab0bfc11 476 */
Kojto 109:9296ab0bfc11 477 #define PCD_SET_EP_KIND(USBx, bEpNum) (PCD_SET_ENDPOINT(USBx, bEpNum, \
Kojto 109:9296ab0bfc11 478 (USB_EP_CTR_RX|USB_EP_CTR_TX|((PCD_GET_ENDPOINT(USBx, bEpNum) | USB_EP_KIND) & USB_EPREG_MASK))))
Kojto 109:9296ab0bfc11 479 #define PCD_CLEAR_EP_KIND(USBx, bEpNum) (PCD_SET_ENDPOINT(USBx, bEpNum, \
Kojto 109:9296ab0bfc11 480 (USB_EP_CTR_RX|USB_EP_CTR_TX|(PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EPKIND_MASK))))
Kojto 109:9296ab0bfc11 481
Kojto 109:9296ab0bfc11 482 /**
Kojto 109:9296ab0bfc11 483 * @brief Sets/clears directly STATUS_OUT bit in the endpoint register.
Kojto 109:9296ab0bfc11 484 * @param USBx: USB peripheral instance register address.
Kojto 109:9296ab0bfc11 485 * @param bEpNum: Endpoint Number.
Kojto 109:9296ab0bfc11 486 * @retval None
Kojto 109:9296ab0bfc11 487 */
Kojto 109:9296ab0bfc11 488 #define PCD_SET_OUT_STATUS(USBx, bEpNum) PCD_SET_EP_KIND(USBx, bEpNum)
Kojto 109:9296ab0bfc11 489 #define PCD_CLEAR_OUT_STATUS(USBx, bEpNum) PCD_CLEAR_EP_KIND(USBx, bEpNum)
Kojto 109:9296ab0bfc11 490
Kojto 109:9296ab0bfc11 491 /**
Kojto 109:9296ab0bfc11 492 * @brief Sets/clears directly EP_KIND bit in the endpoint register.
Kojto 109:9296ab0bfc11 493 * @param USBx: USB peripheral instance register address.
Kojto 109:9296ab0bfc11 494 * @param bEpNum: Endpoint Number.
Kojto 109:9296ab0bfc11 495 * @retval None
Kojto 109:9296ab0bfc11 496 */
Kojto 109:9296ab0bfc11 497 #define PCD_SET_EP_DBUF(USBx, bEpNum) PCD_SET_EP_KIND(USBx, bEpNum)
Kojto 109:9296ab0bfc11 498 #define PCD_CLEAR_EP_DBUF(USBx, bEpNum) PCD_CLEAR_EP_KIND(USBx, bEpNum)
Kojto 109:9296ab0bfc11 499
Kojto 109:9296ab0bfc11 500 /**
Kojto 109:9296ab0bfc11 501 * @brief Clears bit CTR_RX / CTR_TX in the endpoint register.
Kojto 109:9296ab0bfc11 502 * @param USBx: USB peripheral instance register address.
Kojto 109:9296ab0bfc11 503 * @param bEpNum: Endpoint Number.
Kojto 109:9296ab0bfc11 504 * @retval None
Kojto 109:9296ab0bfc11 505 */
Kojto 109:9296ab0bfc11 506 #define PCD_CLEAR_RX_EP_CTR(USBx, bEpNum) (PCD_SET_ENDPOINT(USBx, bEpNum,\
Kojto 109:9296ab0bfc11 507 PCD_GET_ENDPOINT(USBx, bEpNum) & 0x7FFF & USB_EPREG_MASK))
Kojto 109:9296ab0bfc11 508 #define PCD_CLEAR_TX_EP_CTR(USBx, bEpNum) (PCD_SET_ENDPOINT(USBx, bEpNum,\
Kojto 109:9296ab0bfc11 509 PCD_GET_ENDPOINT(USBx, bEpNum) & 0xFF7F & USB_EPREG_MASK))
Kojto 109:9296ab0bfc11 510
Kojto 109:9296ab0bfc11 511 /**
Kojto 109:9296ab0bfc11 512 * @brief Toggles DTOG_RX / DTOG_TX bit in the endpoint register.
Kojto 109:9296ab0bfc11 513 * @param USBx: USB peripheral instance register address.
Kojto 109:9296ab0bfc11 514 * @param bEpNum: Endpoint Number.
Kojto 109:9296ab0bfc11 515 * @retval None
Kojto 109:9296ab0bfc11 516 */
Kojto 109:9296ab0bfc11 517 #define PCD_RX_DTOG(USBx, bEpNum) (PCD_SET_ENDPOINT(USBx, bEpNum, \
Kojto 109:9296ab0bfc11 518 USB_EP_CTR_RX|USB_EP_CTR_TX|USB_EP_DTOG_RX | (PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EPREG_MASK)))
Kojto 109:9296ab0bfc11 519 #define PCD_TX_DTOG(USBx, bEpNum) (PCD_SET_ENDPOINT(USBx, bEpNum, \
Kojto 109:9296ab0bfc11 520 USB_EP_CTR_RX|USB_EP_CTR_TX|USB_EP_DTOG_TX | (PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EPREG_MASK)))
Kojto 109:9296ab0bfc11 521
Kojto 109:9296ab0bfc11 522 /**
Kojto 109:9296ab0bfc11 523 * @brief Clears DTOG_RX / DTOG_TX bit in the endpoint register.
Kojto 109:9296ab0bfc11 524 * @param USBx: USB peripheral instance register address.
Kojto 109:9296ab0bfc11 525 * @param bEpNum: Endpoint Number.
Kojto 109:9296ab0bfc11 526 * @retval None
Kojto 109:9296ab0bfc11 527 */
Kojto 109:9296ab0bfc11 528 #define PCD_CLEAR_RX_DTOG(USBx, bEpNum) if((PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EP_DTOG_RX) != 0)\
Kojto 109:9296ab0bfc11 529 PCD_RX_DTOG(USBx, bEpNum)
Kojto 109:9296ab0bfc11 530 #define PCD_CLEAR_TX_DTOG(USBx, bEpNum) if((PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EP_DTOG_TX) != 0)\
Kojto 109:9296ab0bfc11 531 PCD_TX_DTOG(USBx, bEpNum)
Kojto 109:9296ab0bfc11 532
Kojto 109:9296ab0bfc11 533 /**
Kojto 109:9296ab0bfc11 534 * @brief Sets address in an endpoint register.
Kojto 109:9296ab0bfc11 535 * @param USBx: USB peripheral instance register address.
Kojto 109:9296ab0bfc11 536 * @param bEpNum: Endpoint Number.
Kojto 109:9296ab0bfc11 537 * @param bAddr: Address.
Kojto 109:9296ab0bfc11 538 * @retval None
Kojto 109:9296ab0bfc11 539 */
Kojto 109:9296ab0bfc11 540 #define PCD_SET_EP_ADDRESS(USBx, bEpNum,bAddr) PCD_SET_ENDPOINT(USBx, bEpNum,\
Kojto 109:9296ab0bfc11 541 USB_EP_CTR_RX|USB_EP_CTR_TX|(PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EPREG_MASK) | bAddr)
Kojto 109:9296ab0bfc11 542
Kojto 109:9296ab0bfc11 543 #define PCD_GET_EP_ADDRESS(USBx, bEpNum) ((uint8_t)(PCD_GET_ENDPOINT(USBx, bEpNum) & USB_EPADDR_FIELD))
Kojto 109:9296ab0bfc11 544
Kojto 109:9296ab0bfc11 545 /**
Kojto 109:9296ab0bfc11 546 * @brief sets address of the tx/rx buffer.
Kojto 109:9296ab0bfc11 547 * @param USBx: USB peripheral instance register address.
Kojto 109:9296ab0bfc11 548 * @param bEpNum: Endpoint Number.
Kojto 109:9296ab0bfc11 549 * @param wAddr: address to be set (must be word aligned).
Kojto 109:9296ab0bfc11 550 * @retval None
Kojto 109:9296ab0bfc11 551 */
Kojto 109:9296ab0bfc11 552 #define PCD_SET_EP_TX_ADDRESS(USBx, bEpNum,wAddr) (*PCD_EP_TX_ADDRESS(USBx, bEpNum) = ((wAddr >> 1) << 1))
Kojto 109:9296ab0bfc11 553 #define PCD_SET_EP_RX_ADDRESS(USBx, bEpNum,wAddr) (*PCD_EP_RX_ADDRESS(USBx, bEpNum) = ((wAddr >> 1) << 1))
Kojto 109:9296ab0bfc11 554
Kojto 109:9296ab0bfc11 555 /**
Kojto 109:9296ab0bfc11 556 * @brief Gets address of the tx/rx buffer.
Kojto 109:9296ab0bfc11 557 * @param USBx: USB peripheral instance register address.
Kojto 109:9296ab0bfc11 558 * @param bEpNum: Endpoint Number.
Kojto 109:9296ab0bfc11 559 * @retval address of the buffer.
Kojto 109:9296ab0bfc11 560 */
Kojto 109:9296ab0bfc11 561 #define PCD_GET_EP_TX_ADDRESS(USBx, bEpNum) ((uint16_t)*PCD_EP_TX_ADDRESS(USBx, bEpNum))
Kojto 109:9296ab0bfc11 562 #define PCD_GET_EP_RX_ADDRESS(USBx, bEpNum) ((uint16_t)*PCD_EP_RX_ADDRESS(USBx, bEpNum))
Kojto 109:9296ab0bfc11 563
Kojto 109:9296ab0bfc11 564 /**
Kojto 109:9296ab0bfc11 565 * @brief Sets counter of rx buffer with no. of blocks.
Kojto 109:9296ab0bfc11 566 * @param dwReg: Register
Kojto 109:9296ab0bfc11 567 * @param wCount: Counter.
Kojto 109:9296ab0bfc11 568 * @param wNBlocks: no. of Blocks.
Kojto 109:9296ab0bfc11 569 * @retval None
Kojto 109:9296ab0bfc11 570 */
Kojto 109:9296ab0bfc11 571 #define PCD_CALC_BLK32(dwReg,wCount,wNBlocks) {\
Kojto 109:9296ab0bfc11 572 wNBlocks = wCount >> 5;\
Kojto 109:9296ab0bfc11 573 if((wCount & 0x1f) == 0)\
Kojto 109:9296ab0bfc11 574 wNBlocks--;\
Kojto 109:9296ab0bfc11 575 *pdwReg = (uint16_t)((wNBlocks << 10) | 0x8000);\
Kojto 109:9296ab0bfc11 576 }/* PCD_CALC_BLK32 */
Kojto 109:9296ab0bfc11 577
Kojto 109:9296ab0bfc11 578 #define PCD_CALC_BLK2(dwReg,wCount,wNBlocks) {\
Kojto 109:9296ab0bfc11 579 wNBlocks = wCount >> 1;\
Kojto 109:9296ab0bfc11 580 if((wCount & 0x1) != 0)\
Kojto 109:9296ab0bfc11 581 wNBlocks++;\
Kojto 109:9296ab0bfc11 582 *pdwReg = (uint16_t)(wNBlocks << 10);\
Kojto 109:9296ab0bfc11 583 }/* PCD_CALC_BLK2 */
Kojto 109:9296ab0bfc11 584
Kojto 109:9296ab0bfc11 585 #define PCD_SET_EP_CNT_RX_REG(dwReg,wCount) {\
Kojto 109:9296ab0bfc11 586 uint16_t wNBlocks;\
Kojto 109:9296ab0bfc11 587 if(wCount > 62){PCD_CALC_BLK32(dwReg,wCount,wNBlocks);}\
Kojto 109:9296ab0bfc11 588 else {PCD_CALC_BLK2(dwReg,wCount,wNBlocks);}\
Kojto 109:9296ab0bfc11 589 }/* PCD_SET_EP_CNT_RX_REG */
Kojto 109:9296ab0bfc11 590
Kojto 109:9296ab0bfc11 591 #define PCD_SET_EP_RX_DBUF0_CNT(USBx, bEpNum,wCount) {\
Kojto 109:9296ab0bfc11 592 uint16_t *pdwReg = PCD_EP_TX_CNT(USBx, bEpNum); \
Kojto 109:9296ab0bfc11 593 PCD_SET_EP_CNT_RX_REG(pdwReg, wCount);\
Kojto 109:9296ab0bfc11 594 }
Kojto 109:9296ab0bfc11 595 /**
Kojto 109:9296ab0bfc11 596 * @brief sets counter for the tx/rx buffer.
Kojto 109:9296ab0bfc11 597 * @param USBx: USB peripheral instance register address.
Kojto 109:9296ab0bfc11 598 * @param bEpNum: Endpoint Number.
Kojto 109:9296ab0bfc11 599 * @param wCount: Counter value.
Kojto 109:9296ab0bfc11 600 * @retval None
Kojto 109:9296ab0bfc11 601 */
Kojto 109:9296ab0bfc11 602 #define PCD_SET_EP_TX_CNT(USBx, bEpNum,wCount) (*PCD_EP_TX_CNT(USBx, bEpNum) = wCount)
Kojto 109:9296ab0bfc11 603
Kojto 109:9296ab0bfc11 604
Kojto 109:9296ab0bfc11 605 /**
Kojto 109:9296ab0bfc11 606 * @brief gets counter of the tx buffer.
Kojto 109:9296ab0bfc11 607 * @param USBx: USB peripheral instance register address.
Kojto 109:9296ab0bfc11 608 * @param bEpNum: Endpoint Number.
Kojto 109:9296ab0bfc11 609 * @retval Counter value
Kojto 109:9296ab0bfc11 610 */
Kojto 109:9296ab0bfc11 611 #define PCD_GET_EP_TX_CNT(USBx, bEpNum)((uint16_t)(*PCD_EP_TX_CNT(USBx, bEpNum)) & 0x3ff)
Kojto 109:9296ab0bfc11 612 #define PCD_GET_EP_RX_CNT(USBx, bEpNum)((uint16_t)(*PCD_EP_RX_CNT(USBx, bEpNum)) & 0x3ff)
Kojto 109:9296ab0bfc11 613
Kojto 109:9296ab0bfc11 614 /**
Kojto 109:9296ab0bfc11 615 * @brief Sets buffer 0/1 address in a double buffer endpoint.
Kojto 109:9296ab0bfc11 616 * @param USBx: USB peripheral instance register address.
Kojto 109:9296ab0bfc11 617 * @param bEpNum: Endpoint Number.
Kojto 109:9296ab0bfc11 618 * @param wBuf0Addr: buffer 0 address.
Kojto 109:9296ab0bfc11 619 * @retval Counter value
Kojto 109:9296ab0bfc11 620 */
Kojto 109:9296ab0bfc11 621 #define PCD_SET_EP_DBUF0_ADDR(USBx, bEpNum,wBuf0Addr) {PCD_SET_EP_TX_ADDRESS(USBx, bEpNum, wBuf0Addr);}
Kojto 109:9296ab0bfc11 622 #define PCD_SET_EP_DBUF1_ADDR(USBx, bEpNum,wBuf1Addr) {PCD_SET_EP_RX_ADDRESS(USBx, bEpNum, wBuf1Addr);}
Kojto 109:9296ab0bfc11 623
Kojto 109:9296ab0bfc11 624 /**
Kojto 109:9296ab0bfc11 625 * @brief Sets addresses in a double buffer endpoint.
Kojto 109:9296ab0bfc11 626 * @param USBx: USB peripheral instance register address.
Kojto 109:9296ab0bfc11 627 * @param bEpNum: Endpoint Number.
Kojto 109:9296ab0bfc11 628 * @param wBuf0Addr: buffer 0 address.
Kojto 109:9296ab0bfc11 629 * @param wBuf1Addr = buffer 1 address.
Kojto 109:9296ab0bfc11 630 * @retval None
Kojto 109:9296ab0bfc11 631 */
Kojto 109:9296ab0bfc11 632 #define PCD_SET_EP_DBUF_ADDR(USBx, bEpNum,wBuf0Addr,wBuf1Addr) { \
Kojto 109:9296ab0bfc11 633 PCD_SET_EP_DBUF0_ADDR(USBx, bEpNum, wBuf0Addr);\
Kojto 109:9296ab0bfc11 634 PCD_SET_EP_DBUF1_ADDR(USBx, bEpNum, wBuf1Addr);\
Kojto 109:9296ab0bfc11 635 } /* PCD_SET_EP_DBUF_ADDR */
Kojto 109:9296ab0bfc11 636
Kojto 109:9296ab0bfc11 637 /**
Kojto 109:9296ab0bfc11 638 * @brief Gets buffer 0/1 address of a double buffer endpoint.
Kojto 109:9296ab0bfc11 639 * @param USBx: USB peripheral instance register address.
Kojto 109:9296ab0bfc11 640 * @param bEpNum: Endpoint Number.
Kojto 109:9296ab0bfc11 641 * @retval None
Kojto 109:9296ab0bfc11 642 */
Kojto 109:9296ab0bfc11 643 #define PCD_GET_EP_DBUF0_ADDR(USBx, bEpNum) (PCD_GET_EP_TX_ADDRESS(USBx, bEpNum))
Kojto 109:9296ab0bfc11 644 #define PCD_GET_EP_DBUF1_ADDR(USBx, bEpNum) (PCD_GET_EP_RX_ADDRESS(USBx, bEpNum))
Kojto 109:9296ab0bfc11 645
Kojto 109:9296ab0bfc11 646 /**
Kojto 109:9296ab0bfc11 647 * @brief Gets buffer 0/1 address of a double buffer endpoint.
Kojto 109:9296ab0bfc11 648 * @param USBx: USB peripheral instance register address.
Kojto 109:9296ab0bfc11 649 * @param bEpNum: Endpoint Number.
Kojto 109:9296ab0bfc11 650 * @param bDir: endpoint dir EP_DBUF_OUT = OUT
Kojto 109:9296ab0bfc11 651 * EP_DBUF_IN = IN
Kojto 109:9296ab0bfc11 652 * @param wCount: Counter value
Kojto 109:9296ab0bfc11 653 * @retval None
Kojto 109:9296ab0bfc11 654 */
Kojto 109:9296ab0bfc11 655 #define PCD_SET_EP_DBUF0_CNT(USBx, bEpNum, bDir, wCount) { \
Kojto 109:9296ab0bfc11 656 if(bDir == PCD_EP_DBUF_OUT)\
Kojto 109:9296ab0bfc11 657 /* OUT endpoint */ \
Kojto 109:9296ab0bfc11 658 {PCD_SET_EP_RX_DBUF0_CNT(USBx, bEpNum,wCount);} \
Kojto 109:9296ab0bfc11 659 else if(bDir == PCD_EP_DBUF_IN)\
Kojto 109:9296ab0bfc11 660 /* IN endpoint */ \
Kojto 109:9296ab0bfc11 661 *PCD_EP_TX_CNT(USBx, bEpNum) = (uint32_t)wCount; \
Kojto 109:9296ab0bfc11 662 } /* SetEPDblBuf0Count*/
Kojto 109:9296ab0bfc11 663
Kojto 109:9296ab0bfc11 664 #define PCD_SET_EP_DBUF1_CNT(USBx, bEpNum, bDir, wCount) { \
Kojto 109:9296ab0bfc11 665 if(bDir == PCD_EP_DBUF_OUT)\
Kojto 109:9296ab0bfc11 666 /* OUT endpoint */ \
Kojto 109:9296ab0bfc11 667 {PCD_SET_EP_RX_CNT(USBx, bEpNum,wCount);}\
Kojto 109:9296ab0bfc11 668 else if(bDir == PCD_EP_DBUF_IN)\
Kojto 109:9296ab0bfc11 669 /* IN endpoint */\
Kojto 109:9296ab0bfc11 670 *PCD_EP_RX_CNT(USBx, bEpNum) = (uint32_t)wCount; \
Kojto 109:9296ab0bfc11 671 } /* SetEPDblBuf1Count */
Kojto 109:9296ab0bfc11 672
Kojto 109:9296ab0bfc11 673 #define PCD_SET_EP_DBUF_CNT(USBx, bEpNum, bDir, wCount) {\
Kojto 109:9296ab0bfc11 674 PCD_SET_EP_DBUF0_CNT(USBx, bEpNum, bDir, wCount); \
Kojto 109:9296ab0bfc11 675 PCD_SET_EP_DBUF1_CNT(USBx, bEpNum, bDir, wCount); \
Kojto 109:9296ab0bfc11 676 } /* PCD_SET_EP_DBUF_CNT */
Kojto 109:9296ab0bfc11 677
Kojto 109:9296ab0bfc11 678 /**
Kojto 109:9296ab0bfc11 679 * @brief Gets buffer 0/1 rx/tx counter for double buffering.
Kojto 109:9296ab0bfc11 680 * @param USBx: USB peripheral instance register address.
Kojto 109:9296ab0bfc11 681 * @param bEpNum: Endpoint Number.
Kojto 109:9296ab0bfc11 682 * @retval None
Kojto 109:9296ab0bfc11 683 */
Kojto 109:9296ab0bfc11 684 #define PCD_GET_EP_DBUF0_CNT(USBx, bEpNum) (PCD_GET_EP_TX_CNT(USBx, bEpNum))
Kojto 109:9296ab0bfc11 685 #define PCD_GET_EP_DBUF1_CNT(USBx, bEpNum) (PCD_GET_EP_RX_CNT(USBx, bEpNum))
Kojto 109:9296ab0bfc11 686
Kojto 109:9296ab0bfc11 687
Kojto 109:9296ab0bfc11 688 /**
Kojto 109:9296ab0bfc11 689 * @}
Kojto 109:9296ab0bfc11 690 */
Kojto 109:9296ab0bfc11 691
Kojto 109:9296ab0bfc11 692 /* Exported functions --------------------------------------------------------*/
Kojto 109:9296ab0bfc11 693
Kojto 109:9296ab0bfc11 694 /** @addtogroup PCD_Exported_Functions
Kojto 109:9296ab0bfc11 695 * @{
Kojto 109:9296ab0bfc11 696 */
Kojto 109:9296ab0bfc11 697
Kojto 109:9296ab0bfc11 698 /** @addtogroup PCD_Exported_Functions_Group1 Initialization and de-initialization functions
Kojto 109:9296ab0bfc11 699 * @{
Kojto 109:9296ab0bfc11 700 */
Kojto 109:9296ab0bfc11 701 /* Initialization/de-initialization functions **********************************/
Kojto 109:9296ab0bfc11 702 HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd);
Kojto 109:9296ab0bfc11 703 HAL_StatusTypeDef HAL_PCD_DeInit (PCD_HandleTypeDef *hpcd);
Kojto 109:9296ab0bfc11 704 void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd);
Kojto 109:9296ab0bfc11 705 void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd);
Kojto 109:9296ab0bfc11 706
Kojto 109:9296ab0bfc11 707 /**
Kojto 109:9296ab0bfc11 708 * @}
Kojto 109:9296ab0bfc11 709 */
Kojto 109:9296ab0bfc11 710
Kojto 109:9296ab0bfc11 711 /** @addtogroup PCD_Exported_Functions_Group2 Input and Output operation functions
Kojto 109:9296ab0bfc11 712 * @{
Kojto 109:9296ab0bfc11 713 */
Kojto 109:9296ab0bfc11 714 /* I/O operation functions *****************************************************/
Kojto 109:9296ab0bfc11 715 /* Non-Blocking mode: Interrupt */
Kojto 109:9296ab0bfc11 716 HAL_StatusTypeDef HAL_PCD_Start(PCD_HandleTypeDef *hpcd);
Kojto 109:9296ab0bfc11 717 HAL_StatusTypeDef HAL_PCD_Stop(PCD_HandleTypeDef *hpcd);
Kojto 109:9296ab0bfc11 718 void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd);
Kojto 109:9296ab0bfc11 719
Kojto 109:9296ab0bfc11 720 void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
Kojto 109:9296ab0bfc11 721 void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
Kojto 109:9296ab0bfc11 722 void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd);
Kojto 109:9296ab0bfc11 723 void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd);
Kojto 109:9296ab0bfc11 724 void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd);
Kojto 109:9296ab0bfc11 725 void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd);
Kojto 109:9296ab0bfc11 726 void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd);
Kojto 109:9296ab0bfc11 727 void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
Kojto 109:9296ab0bfc11 728 void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
Kojto 109:9296ab0bfc11 729 void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd);
Kojto 109:9296ab0bfc11 730 void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd);
Kojto 109:9296ab0bfc11 731
Kojto 109:9296ab0bfc11 732 /**
Kojto 109:9296ab0bfc11 733 * @}
Kojto 109:9296ab0bfc11 734 */
Kojto 109:9296ab0bfc11 735
Kojto 109:9296ab0bfc11 736 /** @addtogroup PCD_Exported_Functions_Group3 Peripheral Control functions
Kojto 109:9296ab0bfc11 737 * @{
Kojto 109:9296ab0bfc11 738 */
Kojto 109:9296ab0bfc11 739 /* Peripheral Control functions ************************************************/
Kojto 109:9296ab0bfc11 740 HAL_StatusTypeDef HAL_PCD_DevConnect(PCD_HandleTypeDef *hpcd);
Kojto 109:9296ab0bfc11 741 HAL_StatusTypeDef HAL_PCD_DevDisconnect(PCD_HandleTypeDef *hpcd);
Kojto 109:9296ab0bfc11 742 HAL_StatusTypeDef HAL_PCD_SetAddress(PCD_HandleTypeDef *hpcd, uint8_t address);
Kojto 109:9296ab0bfc11 743 HAL_StatusTypeDef HAL_PCD_EP_Open(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type);
Kojto 109:9296ab0bfc11 744 HAL_StatusTypeDef HAL_PCD_EP_Close(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
Kojto 109:9296ab0bfc11 745 HAL_StatusTypeDef HAL_PCD_EP_Receive(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len);
Kojto 109:9296ab0bfc11 746 HAL_StatusTypeDef HAL_PCD_EP_Transmit(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len);
Kojto 109:9296ab0bfc11 747 uint16_t HAL_PCD_EP_GetRxCount(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
Kojto 109:9296ab0bfc11 748 HAL_StatusTypeDef HAL_PCD_EP_SetStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
Kojto 109:9296ab0bfc11 749 HAL_StatusTypeDef HAL_PCD_EP_ClrStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
Kojto 109:9296ab0bfc11 750 HAL_StatusTypeDef HAL_PCD_EP_Flush(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
Kojto 109:9296ab0bfc11 751 HAL_StatusTypeDef HAL_PCD_ActiveRemoteWakeup(PCD_HandleTypeDef *hpcd);
Kojto 109:9296ab0bfc11 752 HAL_StatusTypeDef HAL_PCD_DeActiveRemoteWakeup(PCD_HandleTypeDef *hpcd);
Kojto 109:9296ab0bfc11 753 /**
Kojto 109:9296ab0bfc11 754 * @}
Kojto 109:9296ab0bfc11 755 */
Kojto 109:9296ab0bfc11 756
Kojto 109:9296ab0bfc11 757 /** @addtogroup PCD_Exported_Functions_Group4 Peripheral State functions
Kojto 109:9296ab0bfc11 758 * @{
Kojto 109:9296ab0bfc11 759 */
Kojto 109:9296ab0bfc11 760 /* Peripheral State functions **************************************************/
Kojto 109:9296ab0bfc11 761 PCD_StateTypeDef HAL_PCD_GetState(PCD_HandleTypeDef *hpcd);
Kojto 109:9296ab0bfc11 762 /**
Kojto 109:9296ab0bfc11 763 * @}
Kojto 109:9296ab0bfc11 764 */
Kojto 109:9296ab0bfc11 765
Kojto 109:9296ab0bfc11 766 /** @addtogroup PCDEx_Private_Functions PCD Extended Private Functions
Kojto 109:9296ab0bfc11 767 * @{
Kojto 109:9296ab0bfc11 768 */
Kojto 109:9296ab0bfc11 769 void PCD_WritePMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes);
Kojto 109:9296ab0bfc11 770 void PCD_ReadPMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes);
Kojto 109:9296ab0bfc11 771 /**
Kojto 109:9296ab0bfc11 772 * @}
Kojto 109:9296ab0bfc11 773 */
Kojto 109:9296ab0bfc11 774
Kojto 109:9296ab0bfc11 775 /**
Kojto 109:9296ab0bfc11 776 * @}
Kojto 109:9296ab0bfc11 777 */
Kojto 109:9296ab0bfc11 778
Kojto 109:9296ab0bfc11 779 /**
Kojto 109:9296ab0bfc11 780 * @}
Kojto 109:9296ab0bfc11 781 */
Kojto 109:9296ab0bfc11 782
Kojto 109:9296ab0bfc11 783 /**
Kojto 109:9296ab0bfc11 784 * @}
Kojto 109:9296ab0bfc11 785 */
Kojto 109:9296ab0bfc11 786 #endif /* STM32F302xE || STM32F303xE || */
Kojto 109:9296ab0bfc11 787 /* STM32F302xC || STM32F303xC || */
Kojto 109:9296ab0bfc11 788 /* STM32F302x8 || */
Kojto 109:9296ab0bfc11 789 /* STM32F373xC */
Kojto 109:9296ab0bfc11 790
Kojto 109:9296ab0bfc11 791 #ifdef __cplusplus
Kojto 109:9296ab0bfc11 792 }
Kojto 109:9296ab0bfc11 793 #endif
Kojto 109:9296ab0bfc11 794
Kojto 109:9296ab0bfc11 795
Kojto 109:9296ab0bfc11 796 #endif /* __STM32F3xx_HAL_PCD_H */
Kojto 109:9296ab0bfc11 797
Kojto 109:9296ab0bfc11 798 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/