2 ******************************************************************************
\r
3 * @file stm32l4xx_hal_pcd.h
\r
4 * @author MCD Application Team
\r
5 * @brief Header file of PCD HAL module.
\r
6 ******************************************************************************
\r
9 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
\r
10 * All rights reserved.</center></h2>
\r
12 * This software component is licensed by ST under BSD 3-Clause license,
\r
13 * the "License"; You may not use this file except in compliance with the
\r
14 * License. You may obtain a copy of the License at:
\r
15 * opensource.org/licenses/BSD-3-Clause
\r
17 ******************************************************************************
\r
20 /* Define to prevent recursive inclusion -------------------------------------*/
\r
21 #ifndef STM32L4xx_HAL_PCD_H
\r
22 #define STM32L4xx_HAL_PCD_H
\r
28 /* Includes ------------------------------------------------------------------*/
\r
29 #include "stm32l4xx_ll_usb.h"
\r
31 #if defined (USB) || defined (USB_OTG_FS)
\r
33 /** @addtogroup STM32L4xx_HAL_Driver
\r
41 /* Exported types ------------------------------------------------------------*/
\r
42 /** @defgroup PCD_Exported_Types PCD Exported Types
\r
47 * @brief PCD State structure definition
\r
51 HAL_PCD_STATE_RESET = 0x00,
\r
52 HAL_PCD_STATE_READY = 0x01,
\r
53 HAL_PCD_STATE_ERROR = 0x02,
\r
54 HAL_PCD_STATE_BUSY = 0x03,
\r
55 HAL_PCD_STATE_TIMEOUT = 0x04
\r
58 /* Device LPM suspend state */
\r
61 LPM_L0 = 0x00, /* on */
\r
62 LPM_L1 = 0x01, /* LPM L1 sleep */
\r
63 LPM_L2 = 0x02, /* suspend */
\r
64 LPM_L3 = 0x03, /* off */
\r
65 } PCD_LPM_StateTypeDef;
\r
69 PCD_LPM_L0_ACTIVE = 0x00, /* on */
\r
70 PCD_LPM_L1_ACTIVE = 0x01, /* LPM L1 sleep */
\r
71 } PCD_LPM_MsgTypeDef;
\r
75 PCD_BCD_ERROR = 0xFF,
\r
76 PCD_BCD_CONTACT_DETECTION = 0xFE,
\r
77 PCD_BCD_STD_DOWNSTREAM_PORT = 0xFD,
\r
78 PCD_BCD_CHARGING_DOWNSTREAM_PORT = 0xFC,
\r
79 PCD_BCD_DEDICATED_CHARGING_PORT = 0xFB,
\r
80 PCD_BCD_DISCOVERY_COMPLETED = 0x00,
\r
82 } PCD_BCD_MsgTypeDef;
\r
86 #endif /* defined (USB) */
\r
87 #if defined (USB_OTG_FS)
\r
88 typedef USB_OTG_GlobalTypeDef PCD_TypeDef;
\r
89 typedef USB_OTG_CfgTypeDef PCD_InitTypeDef;
\r
90 typedef USB_OTG_EPTypeDef PCD_EPTypeDef;
\r
91 #endif /* defined (USB_OTG_FS) */
\r
93 typedef USB_TypeDef PCD_TypeDef;
\r
94 typedef USB_CfgTypeDef PCD_InitTypeDef;
\r
95 typedef USB_EPTypeDef PCD_EPTypeDef;
\r
96 #endif /* defined (USB) */
\r
99 * @brief PCD Handle Structure definition
\r
101 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
\r
102 typedef struct __PCD_HandleTypeDef
\r
105 #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
\r
107 PCD_TypeDef *Instance; /*!< Register base address */
\r
108 PCD_InitTypeDef Init; /*!< PCD required parameters */
\r
109 __IO uint8_t USB_Address; /*!< USB Address */
\r
110 #if defined (USB_OTG_FS)
\r
111 PCD_EPTypeDef IN_ep[16]; /*!< IN endpoint parameters */
\r
112 PCD_EPTypeDef OUT_ep[16]; /*!< OUT endpoint parameters */
\r
113 #endif /* defined (USB_OTG_FS) */
\r
115 PCD_EPTypeDef IN_ep[8]; /*!< IN endpoint parameters */
\r
116 PCD_EPTypeDef OUT_ep[8]; /*!< OUT endpoint parameters */
\r
117 #endif /* defined (USB) */
\r
118 HAL_LockTypeDef Lock; /*!< PCD peripheral status */
\r
119 __IO PCD_StateTypeDef State; /*!< PCD communication state */
\r
120 __IO uint32_t ErrorCode; /*!< PCD Error code */
\r
121 uint32_t Setup[12]; /*!< Setup packet buffer */
\r
122 PCD_LPM_StateTypeDef LPM_State; /*!< LPM State */
\r
126 uint32_t lpm_active; /*!< Enable or disable the Link Power Management .
\r
127 This parameter can be set to ENABLE or DISABLE */
\r
129 uint32_t battery_charging_active; /*!< Enable or disable Battery charging.
\r
130 This parameter can be set to ENABLE or DISABLE */
\r
131 void *pData; /*!< Pointer to upper stack Handler */
\r
133 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
\r
134 void (* SOFCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD SOF callback */
\r
135 void (* SetupStageCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Setup Stage callback */
\r
136 void (* ResetCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Reset callback */
\r
137 void (* SuspendCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Suspend callback */
\r
138 void (* ResumeCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Resume callback */
\r
139 void (* ConnectCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Connect callback */
\r
140 void (* DisconnectCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Disconnect callback */
\r
142 void (* DataOutStageCallback)(struct __PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< USB OTG PCD Data OUT Stage callback */
\r
143 void (* DataInStageCallback)(struct __PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< USB OTG PCD Data IN Stage callback */
\r
144 void (* ISOOUTIncompleteCallback)(struct __PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< USB OTG PCD ISO OUT Incomplete callback */
\r
145 void (* ISOINIncompleteCallback)(struct __PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< USB OTG PCD ISO IN Incomplete callback */
\r
146 void (* BCDCallback)(struct __PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg); /*!< USB OTG PCD BCD callback */
\r
147 void (* LPMCallback)(struct __PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg); /*!< USB OTG PCD LPM callback */
\r
149 void (* MspInitCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Msp Init callback */
\r
150 void (* MspDeInitCallback)(struct __PCD_HandleTypeDef *hpcd); /*!< USB OTG PCD Msp DeInit callback */
\r
151 #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
\r
152 } PCD_HandleTypeDef;
\r
158 /* Include PCD HAL Extended module */
\r
159 #include "stm32l4xx_hal_pcd_ex.h"
\r
161 /* Exported constants --------------------------------------------------------*/
\r
162 /** @defgroup PCD_Exported_Constants PCD Exported Constants
\r
166 /** @defgroup PCD_Speed PCD Speed
\r
169 #define PCD_SPEED_FULL USBD_FS_SPEED
\r
174 /** @defgroup PCD_PHY_Module PCD PHY Module
\r
177 #define PCD_PHY_ULPI 1U
\r
178 #define PCD_PHY_EMBEDDED 2U
\r
179 #define PCD_PHY_UTMI 3U
\r
184 /** @defgroup PCD_Error_Code_definition PCD Error Code definition
\r
185 * @brief PCD Error Code definition
\r
188 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
\r
189 #define HAL_PCD_ERROR_INVALID_CALLBACK (0x00000010U) /*!< Invalid Callback error */
\r
190 #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
\r
200 /* Exported macros -----------------------------------------------------------*/
\r
201 /** @defgroup PCD_Exported_Macros PCD Exported Macros
\r
202 * @brief macros to handle interrupts and specific clock configurations
\r
205 #if defined (USB_OTG_FS)
\r
206 #define __HAL_PCD_ENABLE(__HANDLE__) (void)USB_EnableGlobalInt ((__HANDLE__)->Instance)
\r
207 #define __HAL_PCD_DISABLE(__HANDLE__) (void)USB_DisableGlobalInt ((__HANDLE__)->Instance)
\r
209 #define __HAL_PCD_GET_FLAG(__HANDLE__, __INTERRUPT__) ((USB_ReadInterrupts((__HANDLE__)->Instance) & (__INTERRUPT__)) == (__INTERRUPT__))
\r
210 #define __HAL_PCD_CLEAR_FLAG(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->GINTSTS) &= (__INTERRUPT__))
\r
211 #define __HAL_PCD_IS_INVALID_INTERRUPT(__HANDLE__) (USB_ReadInterrupts((__HANDLE__)->Instance) == 0U)
\r
214 #define __HAL_PCD_UNGATE_PHYCLOCK(__HANDLE__) *(__IO uint32_t *)((uint32_t)((__HANDLE__)->Instance) + USB_OTG_PCGCCTL_BASE) &= \
\r
215 ~(USB_OTG_PCGCCTL_STOPCLK)
\r
217 #define __HAL_PCD_GATE_PHYCLOCK(__HANDLE__) *(__IO uint32_t *)((uint32_t)((__HANDLE__)->Instance) + USB_OTG_PCGCCTL_BASE) |= USB_OTG_PCGCCTL_STOPCLK
\r
219 #define __HAL_PCD_IS_PHY_SUSPENDED(__HANDLE__) ((*(__IO uint32_t *)((uint32_t)((__HANDLE__)->Instance) + USB_OTG_PCGCCTL_BASE)) & 0x10U)
\r
221 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_IT() EXTI->IMR1 |= USB_OTG_FS_WAKEUP_EXTI_LINE
\r
222 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_DISABLE_IT() EXTI->IMR1 &= ~(USB_OTG_FS_WAKEUP_EXTI_LINE)
\r
223 #endif /* defined (USB_OTG_FS) */
\r
226 #define __HAL_PCD_ENABLE(__HANDLE__) (void)USB_EnableGlobalInt ((__HANDLE__)->Instance)
\r
227 #define __HAL_PCD_DISABLE(__HANDLE__) (void)USB_DisableGlobalInt ((__HANDLE__)->Instance)
\r
228 #define __HAL_PCD_GET_FLAG(__HANDLE__, __INTERRUPT__) ((USB_ReadInterrupts((__HANDLE__)->Instance) & (__INTERRUPT__)) == (__INTERRUPT__))
\r
229 #define __HAL_PCD_CLEAR_FLAG(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->ISTR) &= ~(__INTERRUPT__))
\r
231 #define __HAL_USB_WAKEUP_EXTI_ENABLE_IT() EXTI->IMR1 |= USB_WAKEUP_EXTI_LINE
\r
232 #define __HAL_USB_WAKEUP_EXTI_DISABLE_IT() EXTI->IMR1 &= ~(USB_WAKEUP_EXTI_LINE)
\r
233 #endif /* defined (USB) */
\r
239 /* Exported functions --------------------------------------------------------*/
\r
240 /** @addtogroup PCD_Exported_Functions PCD Exported Functions
\r
244 /* Initialization/de-initialization functions ********************************/
\r
245 /** @addtogroup PCD_Exported_Functions_Group1 Initialization and de-initialization functions
\r
248 HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd);
\r
249 HAL_StatusTypeDef HAL_PCD_DeInit(PCD_HandleTypeDef *hpcd);
\r
250 void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd);
\r
251 void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd);
\r
253 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
\r
254 /** @defgroup HAL_PCD_Callback_ID_enumeration_definition HAL USB OTG PCD Callback ID enumeration definition
\r
255 * @brief HAL USB OTG PCD Callback ID enumeration definition
\r
260 HAL_PCD_SOF_CB_ID = 0x01, /*!< USB PCD SOF callback ID */
\r
261 HAL_PCD_SETUPSTAGE_CB_ID = 0x02, /*!< USB PCD Setup Stage callback ID */
\r
262 HAL_PCD_RESET_CB_ID = 0x03, /*!< USB PCD Reset callback ID */
\r
263 HAL_PCD_SUSPEND_CB_ID = 0x04, /*!< USB PCD Suspend callback ID */
\r
264 HAL_PCD_RESUME_CB_ID = 0x05, /*!< USB PCD Resume callback ID */
\r
265 HAL_PCD_CONNECT_CB_ID = 0x06, /*!< USB PCD Connect callback ID */
\r
266 HAL_PCD_DISCONNECT_CB_ID = 0x07, /*!< USB PCD Disconnect callback ID */
\r
268 HAL_PCD_MSPINIT_CB_ID = 0x08, /*!< USB PCD MspInit callback ID */
\r
269 HAL_PCD_MSPDEINIT_CB_ID = 0x09 /*!< USB PCD MspDeInit callback ID */
\r
271 } HAL_PCD_CallbackIDTypeDef;
\r
276 /** @defgroup HAL_PCD_Callback_pointer_definition HAL USB OTG PCD Callback pointer definition
\r
277 * @brief HAL USB OTG PCD Callback pointer definition
\r
281 typedef void (*pPCD_CallbackTypeDef)(PCD_HandleTypeDef *hpcd); /*!< pointer to a common USB OTG PCD callback function */
\r
282 typedef void (*pPCD_DataOutStageCallbackTypeDef)(PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< pointer to USB OTG PCD Data OUT Stage callback */
\r
283 typedef void (*pPCD_DataInStageCallbackTypeDef)(PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< pointer to USB OTG PCD Data IN Stage callback */
\r
284 typedef void (*pPCD_IsoOutIncpltCallbackTypeDef)(PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< pointer to USB OTG PCD ISO OUT Incomplete callback */
\r
285 typedef void (*pPCD_IsoInIncpltCallbackTypeDef)(PCD_HandleTypeDef *hpcd, uint8_t epnum); /*!< pointer to USB OTG PCD ISO IN Incomplete callback */
\r
286 typedef void (*pPCD_LpmCallbackTypeDef)(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg); /*!< pointer to USB OTG PCD LPM callback */
\r
287 typedef void (*pPCD_BcdCallbackTypeDef)(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg); /*!< pointer to USB OTG PCD BCD callback */
\r
293 HAL_StatusTypeDef HAL_PCD_RegisterCallback(PCD_HandleTypeDef *hpcd, HAL_PCD_CallbackIDTypeDef CallbackID, pPCD_CallbackTypeDef pCallback);
\r
294 HAL_StatusTypeDef HAL_PCD_UnRegisterCallback(PCD_HandleTypeDef *hpcd, HAL_PCD_CallbackIDTypeDef CallbackID);
\r
296 HAL_StatusTypeDef HAL_PCD_RegisterDataOutStageCallback(PCD_HandleTypeDef *hpcd, pPCD_DataOutStageCallbackTypeDef pCallback);
\r
297 HAL_StatusTypeDef HAL_PCD_UnRegisterDataOutStageCallback(PCD_HandleTypeDef *hpcd);
\r
299 HAL_StatusTypeDef HAL_PCD_RegisterDataInStageCallback(PCD_HandleTypeDef *hpcd, pPCD_DataInStageCallbackTypeDef pCallback);
\r
300 HAL_StatusTypeDef HAL_PCD_UnRegisterDataInStageCallback(PCD_HandleTypeDef *hpcd);
\r
302 HAL_StatusTypeDef HAL_PCD_RegisterIsoOutIncpltCallback(PCD_HandleTypeDef *hpcd, pPCD_IsoOutIncpltCallbackTypeDef pCallback);
\r
303 HAL_StatusTypeDef HAL_PCD_UnRegisterIsoOutIncpltCallback(PCD_HandleTypeDef *hpcd);
\r
305 HAL_StatusTypeDef HAL_PCD_RegisterIsoInIncpltCallback(PCD_HandleTypeDef *hpcd, pPCD_IsoInIncpltCallbackTypeDef pCallback);
\r
306 HAL_StatusTypeDef HAL_PCD_UnRegisterIsoInIncpltCallback(PCD_HandleTypeDef *hpcd);
\r
308 HAL_StatusTypeDef HAL_PCD_RegisterBcdCallback(PCD_HandleTypeDef *hpcd, pPCD_BcdCallbackTypeDef pCallback);
\r
309 HAL_StatusTypeDef HAL_PCD_UnRegisterBcdCallback(PCD_HandleTypeDef *hpcd);
\r
311 HAL_StatusTypeDef HAL_PCD_RegisterLpmCallback(PCD_HandleTypeDef *hpcd, pPCD_LpmCallbackTypeDef pCallback);
\r
312 HAL_StatusTypeDef HAL_PCD_UnRegisterLpmCallback(PCD_HandleTypeDef *hpcd);
\r
313 #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
\r
318 /* I/O operation functions ***************************************************/
\r
319 /* Non-Blocking mode: Interrupt */
\r
320 /** @addtogroup PCD_Exported_Functions_Group2 Input and Output operation functions
\r
323 HAL_StatusTypeDef HAL_PCD_Start(PCD_HandleTypeDef *hpcd);
\r
324 HAL_StatusTypeDef HAL_PCD_Stop(PCD_HandleTypeDef *hpcd);
\r
325 void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd);
\r
327 void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd);
\r
328 void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd);
\r
329 void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd);
\r
330 void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd);
\r
331 void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd);
\r
332 void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd);
\r
333 void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd);
\r
335 void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
\r
336 void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
\r
337 void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
\r
338 void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
\r
343 /* Peripheral Control functions **********************************************/
\r
344 /** @addtogroup PCD_Exported_Functions_Group3 Peripheral Control functions
\r
347 HAL_StatusTypeDef HAL_PCD_DevConnect(PCD_HandleTypeDef *hpcd);
\r
348 HAL_StatusTypeDef HAL_PCD_DevDisconnect(PCD_HandleTypeDef *hpcd);
\r
349 HAL_StatusTypeDef HAL_PCD_SetAddress(PCD_HandleTypeDef *hpcd, uint8_t address);
\r
350 HAL_StatusTypeDef HAL_PCD_EP_Open(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type);
\r
351 HAL_StatusTypeDef HAL_PCD_EP_Close(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
\r
352 HAL_StatusTypeDef HAL_PCD_EP_Receive(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len);
\r
353 HAL_StatusTypeDef HAL_PCD_EP_Transmit(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len);
\r
354 uint32_t HAL_PCD_EP_GetRxCount(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
\r
355 HAL_StatusTypeDef HAL_PCD_EP_SetStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
\r
356 HAL_StatusTypeDef HAL_PCD_EP_ClrStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
\r
357 HAL_StatusTypeDef HAL_PCD_EP_Flush(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
\r
358 HAL_StatusTypeDef HAL_PCD_ActivateRemoteWakeup(PCD_HandleTypeDef *hpcd);
\r
359 HAL_StatusTypeDef HAL_PCD_DeActivateRemoteWakeup(PCD_HandleTypeDef *hpcd);
\r
364 /* Peripheral State functions ************************************************/
\r
365 /** @addtogroup PCD_Exported_Functions_Group4 Peripheral State functions
\r
368 PCD_StateTypeDef HAL_PCD_GetState(PCD_HandleTypeDef *hpcd);
\r
377 /* Private constants ---------------------------------------------------------*/
\r
378 /** @defgroup PCD_Private_Constants PCD Private Constants
\r
381 /** @defgroup USB_EXTI_Line_Interrupt USB EXTI line interrupt
\r
384 #if defined (USB_OTG_FS)
\r
385 #define USB_OTG_FS_WAKEUP_EXTI_RISING_EDGE 0x08U
\r
386 #define USB_OTG_FS_WAKEUP_EXTI_FALLING_EDGE 0x0CU
\r
387 #define USB_OTG_FS_WAKEUP_EXTI_RISING_FALLING_EDGE 0x10U
\r
389 #define USB_OTG_FS_WAKEUP_EXTI_LINE (0x1U << 17) /*!< USB FS EXTI Line WakeUp Interrupt */
\r
390 #endif /* defined (USB_OTG_FS) */
\r
393 #define USB_WAKEUP_EXTI_LINE (0x1U << 17) /*!< USB FS EXTI Line WakeUp Interrupt */
\r
394 #endif /* defined (USB) */
\r
400 /** @defgroup PCD_EP0_MPS PCD EP0 MPS
\r
403 #define PCD_EP0MPS_64 DEP0CTL_MPS_64
\r
404 #define PCD_EP0MPS_32 DEP0CTL_MPS_32
\r
405 #define PCD_EP0MPS_16 DEP0CTL_MPS_16
\r
406 #define PCD_EP0MPS_08 DEP0CTL_MPS_8
\r
411 /** @defgroup PCD_ENDP PCD ENDP
\r
414 #define PCD_ENDP0 0U
\r
415 #define PCD_ENDP1 1U
\r
416 #define PCD_ENDP2 2U
\r
417 #define PCD_ENDP3 3U
\r
418 #define PCD_ENDP4 4U
\r
419 #define PCD_ENDP5 5U
\r
420 #define PCD_ENDP6 6U
\r
421 #define PCD_ENDP7 7U
\r
426 /** @defgroup PCD_ENDP_Kind PCD Endpoint Kind
\r
429 #define PCD_SNG_BUF 0U
\r
430 #define PCD_DBL_BUF 1U
\r
434 #endif /* defined (USB) */
\r
439 #if defined (USB_OTG_FS)
\r
440 #ifndef USB_OTG_DOEPINT_OTEPSPR
\r
441 #define USB_OTG_DOEPINT_OTEPSPR (0x1UL << 5) /*!< Status Phase Received interrupt */
\r
444 #ifndef USB_OTG_DOEPMSK_OTEPSPRM
\r
445 #define USB_OTG_DOEPMSK_OTEPSPRM (0x1UL << 5) /*!< Setup Packet Received interrupt mask */
\r
448 #ifndef USB_OTG_DOEPINT_NAK
\r
449 #define USB_OTG_DOEPINT_NAK (0x1UL << 13) /*!< NAK interrupt */
\r
452 #ifndef USB_OTG_DOEPMSK_NAKM
\r
453 #define USB_OTG_DOEPMSK_NAKM (0x1UL << 13) /*!< OUT Packet NAK interrupt mask */
\r
456 #ifndef USB_OTG_DOEPINT_STPKTRX
\r
457 #define USB_OTG_DOEPINT_STPKTRX (0x1UL << 15) /*!< Setup Packet Received interrupt */
\r
460 #ifndef USB_OTG_DOEPMSK_NYETM
\r
461 #define USB_OTG_DOEPMSK_NYETM (0x1UL << 14) /*!< Setup Packet Received interrupt mask */
\r
463 #endif /* defined (USB_OTG_FS) */
\r
465 /* Private macros ------------------------------------------------------------*/
\r
466 /** @defgroup PCD_Private_Macros PCD Private Macros
\r
470 /******************** Bit definition for USB_COUNTn_RX register *************/
\r
471 #define USB_CNTRX_NBLK_MSK (0x1FU << 10)
\r
472 #define USB_CNTRX_BLSIZE (0x1U << 15)
\r
475 #define PCD_SET_ENDPOINT(USBx, bEpNum, wRegValue) (*(__IO uint16_t *)(&(USBx)->EP0R + ((bEpNum) * 2U)) = (uint16_t)(wRegValue))
\r
478 #define PCD_GET_ENDPOINT(USBx, bEpNum) (*(__IO uint16_t *)(&(USBx)->EP0R + ((bEpNum) * 2U)))
\r
480 /* ENDPOINT transfer */
\r
481 #define USB_EP0StartXfer USB_EPStartXfer
\r
484 * @brief sets the type in the endpoint register(bits EP_TYPE[1:0])
\r
485 * @param USBx USB peripheral instance register address.
\r
486 * @param bEpNum Endpoint Number.
\r
487 * @param wType Endpoint Type.
\r
490 #define PCD_SET_EPTYPE(USBx, bEpNum, wType) (PCD_SET_ENDPOINT((USBx), (bEpNum), \
\r
491 ((PCD_GET_ENDPOINT((USBx), (bEpNum)) & USB_EP_T_MASK) | (wType) | USB_EP_CTR_TX | USB_EP_CTR_RX)))
\r
494 * @brief gets the type in the endpoint register(bits EP_TYPE[1:0])
\r
495 * @param USBx USB peripheral instance register address.
\r
496 * @param bEpNum Endpoint Number.
\r
497 * @retval Endpoint Type
\r
499 #define PCD_GET_EPTYPE(USBx, bEpNum) (PCD_GET_ENDPOINT((USBx), (bEpNum)) & USB_EP_T_FIELD)
\r
502 * @brief free buffer used from the application realizing it to the line
\r
503 * toggles bit SW_BUF in the double buffered endpoint register
\r
504 * @param USBx USB device.
\r
505 * @param bEpNum, bDir
\r
508 #define PCD_FreeUserBuffer(USBx, bEpNum, bDir) do { \
\r
509 if ((bDir) == 0U) \
\r
511 /* OUT double buffered endpoint */ \
\r
512 PCD_TX_DTOG((USBx), (bEpNum)); \
\r
514 else if ((bDir) == 1U) \
\r
516 /* IN double buffered endpoint */ \
\r
517 PCD_RX_DTOG((USBx), (bEpNum)); \
\r
522 * @brief sets the status for tx transfer (bits STAT_TX[1:0]).
\r
523 * @param USBx USB peripheral instance register address.
\r
524 * @param bEpNum Endpoint Number.
\r
525 * @param wState new state
\r
528 #define PCD_SET_EP_TX_STATUS(USBx, bEpNum, wState) do { \
\r
529 register uint16_t _wRegVal; \
\r
531 _wRegVal = PCD_GET_ENDPOINT((USBx), (bEpNum)) & USB_EPTX_DTOGMASK; \
\r
532 /* toggle first bit ? */ \
\r
533 if ((USB_EPTX_DTOG1 & (wState))!= 0U) \
\r
535 _wRegVal ^= USB_EPTX_DTOG1; \
\r
537 /* toggle second bit ? */ \
\r
538 if ((USB_EPTX_DTOG2 & (wState))!= 0U) \
\r
540 _wRegVal ^= USB_EPTX_DTOG2; \
\r
542 PCD_SET_ENDPOINT((USBx), (bEpNum), (_wRegVal | USB_EP_CTR_RX | USB_EP_CTR_TX)); \
\r
543 } while(0) /* PCD_SET_EP_TX_STATUS */
\r
546 * @brief sets the status for rx transfer (bits STAT_TX[1:0])
\r
547 * @param USBx USB peripheral instance register address.
\r
548 * @param bEpNum Endpoint Number.
\r
549 * @param wState new state
\r
552 #define PCD_SET_EP_RX_STATUS(USBx, bEpNum,wState) do { \
\r
553 register uint16_t _wRegVal; \
\r
555 _wRegVal = PCD_GET_ENDPOINT((USBx), (bEpNum)) & USB_EPRX_DTOGMASK; \
\r
556 /* toggle first bit ? */ \
\r
557 if ((USB_EPRX_DTOG1 & (wState))!= 0U) \
\r
559 _wRegVal ^= USB_EPRX_DTOG1; \
\r
561 /* toggle second bit ? */ \
\r
562 if ((USB_EPRX_DTOG2 & (wState))!= 0U) \
\r
564 _wRegVal ^= USB_EPRX_DTOG2; \
\r
566 PCD_SET_ENDPOINT((USBx), (bEpNum), (_wRegVal | USB_EP_CTR_RX | USB_EP_CTR_TX)); \
\r
567 } while(0) /* PCD_SET_EP_RX_STATUS */
\r
570 * @brief sets the status for rx & tx (bits STAT_TX[1:0] & STAT_RX[1:0])
\r
571 * @param USBx USB peripheral instance register address.
\r
572 * @param bEpNum Endpoint Number.
\r
573 * @param wStaterx new state.
\r
574 * @param wStatetx new state.
\r
577 #define PCD_SET_EP_TXRX_STATUS(USBx, bEpNum, wStaterx, wStatetx) do { \
\r
578 register uint16_t _wRegVal; \
\r
580 _wRegVal = PCD_GET_ENDPOINT((USBx), (bEpNum)) & (USB_EPRX_DTOGMASK | USB_EPTX_STAT); \
\r
581 /* toggle first bit ? */ \
\r
582 if ((USB_EPRX_DTOG1 & (wStaterx))!= 0U) \
\r
584 _wRegVal ^= USB_EPRX_DTOG1; \
\r
586 /* toggle second bit ? */ \
\r
587 if ((USB_EPRX_DTOG2 & (wStaterx))!= 0U) \
\r
589 _wRegVal ^= USB_EPRX_DTOG2; \
\r
591 /* toggle first bit ? */ \
\r
592 if ((USB_EPTX_DTOG1 & (wStatetx))!= 0U) \
\r
594 _wRegVal ^= USB_EPTX_DTOG1; \
\r
596 /* toggle second bit ? */ \
\r
597 if ((USB_EPTX_DTOG2 & (wStatetx))!= 0U) \
\r
599 _wRegVal ^= USB_EPTX_DTOG2; \
\r
602 PCD_SET_ENDPOINT((USBx), (bEpNum), (_wRegVal | USB_EP_CTR_RX | USB_EP_CTR_TX)); \
\r
603 } while(0) /* PCD_SET_EP_TXRX_STATUS */
\r
606 * @brief gets the status for tx/rx transfer (bits STAT_TX[1:0]
\r
608 * @param USBx USB peripheral instance register address.
\r
609 * @param bEpNum Endpoint Number.
\r
612 #define PCD_GET_EP_TX_STATUS(USBx, bEpNum) ((uint16_t)PCD_GET_ENDPOINT((USBx), (bEpNum)) & USB_EPTX_STAT)
\r
613 #define PCD_GET_EP_RX_STATUS(USBx, bEpNum) ((uint16_t)PCD_GET_ENDPOINT((USBx), (bEpNum)) & USB_EPRX_STAT)
\r
616 * @brief sets directly the VALID tx/rx-status into the endpoint register
\r
617 * @param USBx USB peripheral instance register address.
\r
618 * @param bEpNum Endpoint Number.
\r
621 #define PCD_SET_EP_TX_VALID(USBx, bEpNum) (PCD_SET_EP_TX_STATUS((USBx), (bEpNum), USB_EP_TX_VALID))
\r
622 #define PCD_SET_EP_RX_VALID(USBx, bEpNum) (PCD_SET_EP_RX_STATUS((USBx), (bEpNum), USB_EP_RX_VALID))
\r
625 * @brief checks stall condition in an endpoint.
\r
626 * @param USBx USB peripheral instance register address.
\r
627 * @param bEpNum Endpoint Number.
\r
628 * @retval TRUE = endpoint in stall condition.
\r
630 #define PCD_GET_EP_TX_STALL_STATUS(USBx, bEpNum) (PCD_GET_EP_TX_STATUS((USBx), (bEpNum)) \
\r
631 == USB_EP_TX_STALL)
\r
632 #define PCD_GET_EP_RX_STALL_STATUS(USBx, bEpNum) (PCD_GET_EP_RX_STATUS((USBx), (bEpNum)) \
\r
633 == USB_EP_RX_STALL)
\r
636 * @brief set & clear EP_KIND bit.
\r
637 * @param USBx USB peripheral instance register address.
\r
638 * @param bEpNum Endpoint Number.
\r
641 #define PCD_SET_EP_KIND(USBx, bEpNum) do { \
\r
642 register uint16_t _wRegVal; \
\r
644 _wRegVal = PCD_GET_ENDPOINT((USBx), (bEpNum)) & USB_EPREG_MASK; \
\r
646 PCD_SET_ENDPOINT((USBx), (bEpNum), (_wRegVal | USB_EP_CTR_RX | USB_EP_CTR_TX | USB_EP_KIND)); \
\r
647 } while(0) /* PCD_SET_EP_KIND */
\r
649 #define PCD_CLEAR_EP_KIND(USBx, bEpNum) do { \
\r
650 register uint16_t _wRegVal; \
\r
652 _wRegVal = PCD_GET_ENDPOINT((USBx), (bEpNum)) & USB_EPKIND_MASK; \
\r
654 PCD_SET_ENDPOINT((USBx), (bEpNum), (_wRegVal | USB_EP_CTR_RX | USB_EP_CTR_TX)); \
\r
655 } while(0) /* PCD_CLEAR_EP_KIND */
\r
658 * @brief Sets/clears directly STATUS_OUT bit in the endpoint register.
\r
659 * @param USBx USB peripheral instance register address.
\r
660 * @param bEpNum Endpoint Number.
\r
663 #define PCD_SET_OUT_STATUS(USBx, bEpNum) PCD_SET_EP_KIND((USBx), (bEpNum))
\r
664 #define PCD_CLEAR_OUT_STATUS(USBx, bEpNum) PCD_CLEAR_EP_KIND((USBx), (bEpNum))
\r
667 * @brief Sets/clears directly EP_KIND bit in the endpoint register.
\r
668 * @param USBx USB peripheral instance register address.
\r
669 * @param bEpNum Endpoint Number.
\r
672 #define PCD_SET_EP_DBUF(USBx, bEpNum) PCD_SET_EP_KIND((USBx), (bEpNum))
\r
673 #define PCD_CLEAR_EP_DBUF(USBx, bEpNum) PCD_CLEAR_EP_KIND((USBx), (bEpNum))
\r
676 * @brief Clears bit CTR_RX / CTR_TX in the endpoint register.
\r
677 * @param USBx USB peripheral instance register address.
\r
678 * @param bEpNum Endpoint Number.
\r
681 #define PCD_CLEAR_RX_EP_CTR(USBx, bEpNum) do { \
\r
682 register uint16_t _wRegVal; \
\r
684 _wRegVal = PCD_GET_ENDPOINT((USBx), (bEpNum)) & (0x7FFFU & USB_EPREG_MASK); \
\r
686 PCD_SET_ENDPOINT((USBx), (bEpNum), (_wRegVal | USB_EP_CTR_TX)); \
\r
687 } while(0) /* PCD_CLEAR_RX_EP_CTR */
\r
689 #define PCD_CLEAR_TX_EP_CTR(USBx, bEpNum) do { \
\r
690 register uint16_t _wRegVal; \
\r
692 _wRegVal = PCD_GET_ENDPOINT((USBx), (bEpNum)) & (0xFF7FU & USB_EPREG_MASK); \
\r
694 PCD_SET_ENDPOINT((USBx), (bEpNum), (_wRegVal | USB_EP_CTR_RX)); \
\r
695 } while(0) /* PCD_CLEAR_TX_EP_CTR */
\r
698 * @brief Toggles DTOG_RX / DTOG_TX bit in the endpoint register.
\r
699 * @param USBx USB peripheral instance register address.
\r
700 * @param bEpNum Endpoint Number.
\r
703 #define PCD_RX_DTOG(USBx, bEpNum) do { \
\r
704 register uint16_t _wEPVal; \
\r
706 _wEPVal = PCD_GET_ENDPOINT((USBx), (bEpNum)) & USB_EPREG_MASK; \
\r
708 PCD_SET_ENDPOINT((USBx), (bEpNum), (_wEPVal | USB_EP_CTR_RX | USB_EP_CTR_TX | USB_EP_DTOG_RX)); \
\r
709 } while(0) /* PCD_RX_DTOG */
\r
711 #define PCD_TX_DTOG(USBx, bEpNum) do { \
\r
712 register uint16_t _wEPVal; \
\r
714 _wEPVal = PCD_GET_ENDPOINT((USBx), (bEpNum)) & USB_EPREG_MASK; \
\r
716 PCD_SET_ENDPOINT((USBx), (bEpNum), (_wEPVal | USB_EP_CTR_RX | USB_EP_CTR_TX | USB_EP_DTOG_TX)); \
\r
717 } while(0) /* PCD_TX_DTOG */
\r
719 * @brief Clears DTOG_RX / DTOG_TX bit in the endpoint register.
\r
720 * @param USBx USB peripheral instance register address.
\r
721 * @param bEpNum Endpoint Number.
\r
724 #define PCD_CLEAR_RX_DTOG(USBx, bEpNum) do { \
\r
725 register uint16_t _wRegVal; \
\r
727 _wRegVal = PCD_GET_ENDPOINT((USBx), (bEpNum)); \
\r
729 if ((_wRegVal & USB_EP_DTOG_RX) != 0U)\
\r
731 PCD_RX_DTOG((USBx), (bEpNum)); \
\r
733 } while(0) /* PCD_CLEAR_RX_DTOG */
\r
735 #define PCD_CLEAR_TX_DTOG(USBx, bEpNum) do { \
\r
736 register uint16_t _wRegVal; \
\r
738 _wRegVal = PCD_GET_ENDPOINT((USBx), (bEpNum)); \
\r
740 if ((_wRegVal & USB_EP_DTOG_TX) != 0U)\
\r
742 PCD_TX_DTOG((USBx), (bEpNum)); \
\r
744 } while(0) /* PCD_CLEAR_TX_DTOG */
\r
747 * @brief Sets address in an endpoint register.
\r
748 * @param USBx USB peripheral instance register address.
\r
749 * @param bEpNum Endpoint Number.
\r
750 * @param bAddr Address.
\r
753 #define PCD_SET_EP_ADDRESS(USBx, bEpNum, bAddr) do { \
\r
754 register uint16_t _wRegVal; \
\r
756 _wRegVal = (PCD_GET_ENDPOINT((USBx), (bEpNum)) & USB_EPREG_MASK) | (bAddr); \
\r
758 PCD_SET_ENDPOINT((USBx), (bEpNum), (_wRegVal | USB_EP_CTR_RX | USB_EP_CTR_TX)); \
\r
759 } while(0) /* PCD_SET_EP_ADDRESS */
\r
762 * @brief Gets address in an endpoint register.
\r
763 * @param USBx USB peripheral instance register address.
\r
764 * @param bEpNum Endpoint Number.
\r
767 #define PCD_GET_EP_ADDRESS(USBx, bEpNum) ((uint8_t)(PCD_GET_ENDPOINT((USBx), (bEpNum)) & USB_EPADDR_FIELD))
\r
769 #define PCD_EP_TX_CNT(USBx, bEpNum) ((uint16_t *)((((uint32_t)(USBx)->BTABLE + ((uint32_t)(bEpNum) * 8U) + 2U) * PMA_ACCESS) + ((uint32_t)(USBx) + 0x400U)))
\r
770 #define PCD_EP_RX_CNT(USBx, bEpNum) ((uint16_t *)((((uint32_t)(USBx)->BTABLE + ((uint32_t)(bEpNum) * 8U) + 6U) * PMA_ACCESS) + ((uint32_t)(USBx) + 0x400U)))
\r
773 * @brief sets address of the tx/rx buffer.
\r
774 * @param USBx USB peripheral instance register address.
\r
775 * @param bEpNum Endpoint Number.
\r
776 * @param wAddr address to be set (must be word aligned).
\r
779 #define PCD_SET_EP_TX_ADDRESS(USBx, bEpNum, wAddr) do { \
\r
780 register uint16_t *_wRegVal; \
\r
781 register uint32_t _wRegBase = (uint32_t)USBx; \
\r
783 _wRegBase += (uint32_t)(USBx)->BTABLE; \
\r
784 _wRegVal = (uint16_t *)(_wRegBase + 0x400U + (((uint32_t)(bEpNum) * 8U) * PMA_ACCESS)); \
\r
785 *_wRegVal = ((wAddr) >> 1) << 1; \
\r
786 } while(0) /* PCD_SET_EP_TX_ADDRESS */
\r
788 #define PCD_SET_EP_RX_ADDRESS(USBx, bEpNum, wAddr) do { \
\r
789 register uint16_t *_wRegVal; \
\r
790 register uint32_t _wRegBase = (uint32_t)USBx; \
\r
792 _wRegBase += (uint32_t)(USBx)->BTABLE; \
\r
793 _wRegVal = (uint16_t *)(_wRegBase + 0x400U + ((((uint32_t)(bEpNum) * 8U) + 4U) * PMA_ACCESS)); \
\r
794 *_wRegVal = ((wAddr) >> 1) << 1; \
\r
795 } while(0) /* PCD_SET_EP_RX_ADDRESS */
\r
798 * @brief Gets address of the tx/rx buffer.
\r
799 * @param USBx USB peripheral instance register address.
\r
800 * @param bEpNum Endpoint Number.
\r
801 * @retval address of the buffer.
\r
803 #define PCD_GET_EP_TX_ADDRESS(USBx, bEpNum) ((uint16_t)*PCD_EP_TX_ADDRESS((USBx), (bEpNum)))
\r
804 #define PCD_GET_EP_RX_ADDRESS(USBx, bEpNum) ((uint16_t)*PCD_EP_RX_ADDRESS((USBx), (bEpNum)))
\r
807 * @brief Sets counter of rx buffer with no. of blocks.
\r
808 * @param pdwReg Register pointer
\r
809 * @param wCount Counter.
\r
810 * @param wNBlocks no. of Blocks.
\r
813 #define PCD_CALC_BLK32(pdwReg, wCount, wNBlocks) do { \
\r
814 (wNBlocks) = (wCount) >> 5; \
\r
815 *(pdwReg) = (uint16_t)(((wNBlocks) << 10) | USB_CNTRX_BLSIZE); \
\r
816 } while(0) /* PCD_CALC_BLK32 */
\r
818 #define PCD_CALC_BLK2(pdwReg, wCount, wNBlocks) do { \
\r
819 (wNBlocks) = (wCount) >> 1; \
\r
820 if (((wCount) & 0x1U) != 0U) \
\r
824 *(pdwReg) = (uint16_t)((wNBlocks) << 10); \
\r
825 } while(0) /* PCD_CALC_BLK2 */
\r
827 #define PCD_SET_EP_CNT_RX_REG(pdwReg, wCount) do { \
\r
828 uint32_t wNBlocks; \
\r
829 if ((wCount) == 0U) \
\r
831 *(pdwReg) &= (uint16_t)~USB_CNTRX_NBLK_MSK; \
\r
832 *(pdwReg) |= USB_CNTRX_BLSIZE; \
\r
834 else if((wCount) < 62U) \
\r
836 PCD_CALC_BLK2((pdwReg), (wCount), wNBlocks); \
\r
840 PCD_CALC_BLK32((pdwReg),(wCount), wNBlocks); \
\r
842 } while(0) /* PCD_SET_EP_CNT_RX_REG */
\r
844 #define PCD_SET_EP_RX_DBUF0_CNT(USBx, bEpNum, wCount) do { \
\r
845 register uint32_t _wRegBase = (uint32_t)(USBx); \
\r
846 uint16_t *pdwReg; \
\r
848 _wRegBase += (uint32_t)(USBx)->BTABLE; \
\r
849 pdwReg = (uint16_t *)(_wRegBase + 0x400U + ((((uint32_t)(bEpNum) * 8U) + 2U) * PMA_ACCESS)); \
\r
850 PCD_SET_EP_CNT_RX_REG(pdwReg, (wCount)); \
\r
854 * @brief sets counter for the tx/rx buffer.
\r
855 * @param USBx USB peripheral instance register address.
\r
856 * @param bEpNum Endpoint Number.
\r
857 * @param wCount Counter value.
\r
860 #define PCD_SET_EP_TX_CNT(USBx, bEpNum, wCount) do { \
\r
861 register uint32_t _wRegBase = (uint32_t)(USBx); \
\r
862 uint16_t *_wRegVal; \
\r
864 _wRegBase += (uint32_t)(USBx)->BTABLE; \
\r
865 _wRegVal = (uint16_t *)(_wRegBase + 0x400U + ((((uint32_t)(bEpNum) * 8U) + 2U) * PMA_ACCESS)); \
\r
866 *_wRegVal = (uint16_t)(wCount); \
\r
869 #define PCD_SET_EP_RX_CNT(USBx, bEpNum, wCount) do { \
\r
870 register uint32_t _wRegBase = (uint32_t)(USBx); \
\r
871 uint16_t *_wRegVal; \
\r
873 _wRegBase += (uint32_t)(USBx)->BTABLE; \
\r
874 _wRegVal = (uint16_t *)(_wRegBase + 0x400U + ((((uint32_t)(bEpNum) * 8U) + 6U) * PMA_ACCESS)); \
\r
875 PCD_SET_EP_CNT_RX_REG(_wRegVal, (wCount)); \
\r
879 * @brief gets counter of the tx buffer.
\r
880 * @param USBx USB peripheral instance register address.
\r
881 * @param bEpNum Endpoint Number.
\r
882 * @retval Counter value
\r
884 #define PCD_GET_EP_TX_CNT(USBx, bEpNum) ((uint32_t)(*PCD_EP_TX_CNT((USBx), (bEpNum))) & 0x3ffU)
\r
885 #define PCD_GET_EP_RX_CNT(USBx, bEpNum) ((uint32_t)(*PCD_EP_RX_CNT((USBx), (bEpNum))) & 0x3ffU)
\r
888 * @brief Sets buffer 0/1 address in a double buffer endpoint.
\r
889 * @param USBx USB peripheral instance register address.
\r
890 * @param bEpNum Endpoint Number.
\r
891 * @param wBuf0Addr buffer 0 address.
\r
892 * @retval Counter value
\r
894 #define PCD_SET_EP_DBUF0_ADDR(USBx, bEpNum, wBuf0Addr) do { \
\r
895 PCD_SET_EP_TX_ADDRESS((USBx), (bEpNum), (wBuf0Addr)); \
\r
896 } while(0) /* PCD_SET_EP_DBUF0_ADDR */
\r
897 #define PCD_SET_EP_DBUF1_ADDR(USBx, bEpNum, wBuf1Addr) do { \
\r
898 PCD_SET_EP_RX_ADDRESS((USBx), (bEpNum), (wBuf1Addr)); \
\r
899 } while(0) /* PCD_SET_EP_DBUF1_ADDR */
\r
902 * @brief Sets addresses in a double buffer endpoint.
\r
903 * @param USBx USB peripheral instance register address.
\r
904 * @param bEpNum Endpoint Number.
\r
905 * @param wBuf0Addr: buffer 0 address.
\r
906 * @param wBuf1Addr = buffer 1 address.
\r
909 #define PCD_SET_EP_DBUF_ADDR(USBx, bEpNum, wBuf0Addr, wBuf1Addr) do { \
\r
910 PCD_SET_EP_DBUF0_ADDR((USBx), (bEpNum), (wBuf0Addr)); \
\r
911 PCD_SET_EP_DBUF1_ADDR((USBx), (bEpNum), (wBuf1Addr)); \
\r
912 } while(0) /* PCD_SET_EP_DBUF_ADDR */
\r
915 * @brief Gets buffer 0/1 address of a double buffer endpoint.
\r
916 * @param USBx USB peripheral instance register address.
\r
917 * @param bEpNum Endpoint Number.
\r
920 #define PCD_GET_EP_DBUF0_ADDR(USBx, bEpNum) (PCD_GET_EP_TX_ADDRESS((USBx), (bEpNum)))
\r
921 #define PCD_GET_EP_DBUF1_ADDR(USBx, bEpNum) (PCD_GET_EP_RX_ADDRESS((USBx), (bEpNum)))
\r
924 * @brief Gets buffer 0/1 address of a double buffer endpoint.
\r
925 * @param USBx USB peripheral instance register address.
\r
926 * @param bEpNum Endpoint Number.
\r
927 * @param bDir endpoint dir EP_DBUF_OUT = OUT
\r
929 * @param wCount: Counter value
\r
932 #define PCD_SET_EP_DBUF0_CNT(USBx, bEpNum, bDir, wCount) do { \
\r
933 if ((bDir) == 0U) \
\r
934 /* OUT endpoint */ \
\r
936 PCD_SET_EP_RX_DBUF0_CNT((USBx), (bEpNum), (wCount)); \
\r
940 if ((bDir) == 1U) \
\r
942 /* IN endpoint */ \
\r
943 PCD_SET_EP_TX_CNT((USBx), (bEpNum), (wCount)); \
\r
946 } while(0) /* SetEPDblBuf0Count*/
\r
948 #define PCD_SET_EP_DBUF1_CNT(USBx, bEpNum, bDir, wCount) do { \
\r
949 register uint32_t _wBase = (uint32_t)(USBx); \
\r
950 uint16_t *_wEPRegVal; \
\r
952 if ((bDir) == 0U) \
\r
954 /* OUT endpoint */ \
\r
955 PCD_SET_EP_RX_CNT((USBx), (bEpNum), (wCount)); \
\r
959 if ((bDir) == 1U) \
\r
961 /* IN endpoint */ \
\r
962 _wBase += (uint32_t)(USBx)->BTABLE; \
\r
963 _wEPRegVal = (uint16_t *)(_wBase + 0x400U + ((((uint32_t)(bEpNum) * 8U) + 6U) * PMA_ACCESS)); \
\r
964 *_wEPRegVal = (uint16_t)(wCount); \
\r
967 } while(0) /* SetEPDblBuf1Count */
\r
969 #define PCD_SET_EP_DBUF_CNT(USBx, bEpNum, bDir, wCount) do { \
\r
970 PCD_SET_EP_DBUF0_CNT((USBx), (bEpNum), (bDir), (wCount)); \
\r
971 PCD_SET_EP_DBUF1_CNT((USBx), (bEpNum), (bDir), (wCount)); \
\r
972 } while(0) /* PCD_SET_EP_DBUF_CNT */
\r
975 * @brief Gets buffer 0/1 rx/tx counter for double buffering.
\r
976 * @param USBx USB peripheral instance register address.
\r
977 * @param bEpNum Endpoint Number.
\r
980 #define PCD_GET_EP_DBUF0_CNT(USBx, bEpNum) (PCD_GET_EP_TX_CNT((USBx), (bEpNum)))
\r
981 #define PCD_GET_EP_DBUF1_CNT(USBx, bEpNum) (PCD_GET_EP_RX_CNT((USBx), (bEpNum)))
\r
983 #endif /* defined (USB) */
\r
996 #endif /* defined (USB) || defined (USB_OTG_FS) */
\r
1002 #endif /* STM32L4xx_HAL_PCD_H */
\r
1004 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r