21 #ifndef STM32F7xx_HAL_PCD_H
22 #define STM32F7xx_HAL_PCD_H
29 #include "stm32f7xx_ll_usb.h"
31 #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
51 HAL_PCD_STATE_RESET = 0x00,
52 HAL_PCD_STATE_READY = 0x01,
53 HAL_PCD_STATE_ERROR = 0x02,
54 HAL_PCD_STATE_BUSY = 0x03,
55 HAL_PCD_STATE_TIMEOUT = 0x04
65 } PCD_LPM_StateTypeDef;
69 PCD_LPM_L0_ACTIVE = 0x00,
70 PCD_LPM_L1_ACTIVE = 0x01,
76 PCD_BCD_CONTACT_DETECTION = 0xFE,
77 PCD_BCD_STD_DOWNSTREAM_PORT = 0xFD,
78 PCD_BCD_CHARGING_DOWNSTREAM_PORT = 0xFC,
79 PCD_BCD_DEDICATED_CHARGING_PORT = 0xFB,
80 PCD_BCD_DISCOVERY_COMPLETED = 0x00,
84 #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
86 typedef USB_OTG_CfgTypeDef PCD_InitTypeDef;
87 typedef USB_OTG_EPTypeDef PCD_EPTypeDef;
93 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
94 typedef struct __PCD_HandleTypeDef
99 PCD_TypeDef *Instance;
100 PCD_InitTypeDef
Init;
101 __IO uint8_t USB_Address;
102 PCD_EPTypeDef IN_ep[16];
103 PCD_EPTypeDef OUT_ep[16];
105 __IO PCD_StateTypeDef State;
106 __IO uint32_t ErrorCode;
108 PCD_LPM_StateTypeDef LPM_State;
116 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
117 void (* SOFCallback)(
struct __PCD_HandleTypeDef *hpcd);
118 void (* SetupStageCallback)(
struct __PCD_HandleTypeDef *hpcd);
119 void (* ResetCallback)(
struct __PCD_HandleTypeDef *hpcd);
120 void (* SuspendCallback)(
struct __PCD_HandleTypeDef *hpcd);
121 void (* ResumeCallback)(
struct __PCD_HandleTypeDef *hpcd);
122 void (* ConnectCallback)(
struct __PCD_HandleTypeDef *hpcd);
123 void (* DisconnectCallback)(
struct __PCD_HandleTypeDef *hpcd);
125 void (* DataOutStageCallback)(
struct __PCD_HandleTypeDef *hpcd, uint8_t epnum);
126 void (* DataInStageCallback)(
struct __PCD_HandleTypeDef *hpcd, uint8_t epnum);
127 void (* ISOOUTIncompleteCallback)(
struct __PCD_HandleTypeDef *hpcd, uint8_t epnum);
128 void (* ISOINIncompleteCallback)(
struct __PCD_HandleTypeDef *hpcd, uint8_t epnum);
129 void (* LPMCallback)(
struct __PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg);
131 void (* MspInitCallback)(
struct __PCD_HandleTypeDef *hpcd);
132 void (* MspDeInitCallback)(
struct __PCD_HandleTypeDef *hpcd);
151 #define PCD_SPEED_HIGH USBD_HS_SPEED
152 #define PCD_SPEED_HIGH_IN_FULL USBD_HSINFS_SPEED
153 #define PCD_SPEED_FULL USBD_FS_SPEED
161 #define PCD_PHY_ULPI 1U
162 #define PCD_PHY_EMBEDDED 2U
163 #define PCD_PHY_UTMI 3U
172 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
173 #define HAL_PCD_ERROR_INVALID_CALLBACK (0x00000010U)
189 #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
190 #define __HAL_PCD_ENABLE(__HANDLE__) (void)USB_EnableGlobalInt ((__HANDLE__)->Instance)
191 #define __HAL_PCD_DISABLE(__HANDLE__) (void)USB_DisableGlobalInt ((__HANDLE__)->Instance)
193 #define __HAL_PCD_GET_FLAG(__HANDLE__, __INTERRUPT__) ((USB_ReadInterrupts((__HANDLE__)->Instance) & (__INTERRUPT__)) == (__INTERRUPT__))
194 #define __HAL_PCD_CLEAR_FLAG(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->GINTSTS) &= (__INTERRUPT__))
195 #define __HAL_PCD_IS_INVALID_INTERRUPT(__HANDLE__) (USB_ReadInterrupts((__HANDLE__)->Instance) == 0U)
198 #define __HAL_PCD_UNGATE_PHYCLOCK(__HANDLE__) *(__IO uint32_t *)((uint32_t)((__HANDLE__)->Instance) + USB_OTG_PCGCCTL_BASE) &= \
199 ~(USB_OTG_PCGCCTL_STOPCLK)
201 #define __HAL_PCD_GATE_PHYCLOCK(__HANDLE__) *(__IO uint32_t *)((uint32_t)((__HANDLE__)->Instance) + USB_OTG_PCGCCTL_BASE) |= USB_OTG_PCGCCTL_STOPCLK
203 #define __HAL_PCD_IS_PHY_SUSPENDED(__HANDLE__) ((*(__IO uint32_t *)((uint32_t)((__HANDLE__)->Instance) + USB_OTG_PCGCCTL_BASE)) & 0x10U)
205 #define __HAL_USB_OTG_HS_WAKEUP_EXTI_ENABLE_IT() EXTI->IMR |= (USB_OTG_HS_WAKEUP_EXTI_LINE)
206 #define __HAL_USB_OTG_HS_WAKEUP_EXTI_DISABLE_IT() EXTI->IMR &= ~(USB_OTG_HS_WAKEUP_EXTI_LINE)
207 #define __HAL_USB_OTG_HS_WAKEUP_EXTI_GET_FLAG() EXTI->PR & (USB_OTG_HS_WAKEUP_EXTI_LINE)
208 #define __HAL_USB_OTG_HS_WAKEUP_EXTI_CLEAR_FLAG() EXTI->PR = (USB_OTG_HS_WAKEUP_EXTI_LINE)
210 #define __HAL_USB_OTG_HS_WAKEUP_EXTI_ENABLE_RISING_EDGE() \
212 EXTI->FTSR &= ~(USB_OTG_HS_WAKEUP_EXTI_LINE); \
213 EXTI->RTSR |= USB_OTG_HS_WAKEUP_EXTI_LINE; \
215 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_IT() EXTI->IMR |= USB_OTG_FS_WAKEUP_EXTI_LINE
216 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_DISABLE_IT() EXTI->IMR &= ~(USB_OTG_FS_WAKEUP_EXTI_LINE)
217 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_GET_FLAG() EXTI->PR & (USB_OTG_FS_WAKEUP_EXTI_LINE)
218 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_CLEAR_FLAG() EXTI->PR = USB_OTG_FS_WAKEUP_EXTI_LINE
220 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_RISING_EDGE() \
222 EXTI->FTSR &= ~(USB_OTG_FS_WAKEUP_EXTI_LINE); \
223 EXTI->RTSR |= USB_OTG_FS_WAKEUP_EXTI_LINE; \
243 void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd);
244 void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd);
246 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
253 HAL_PCD_SOF_CB_ID = 0x01,
254 HAL_PCD_SETUPSTAGE_CB_ID = 0x02,
255 HAL_PCD_RESET_CB_ID = 0x03,
256 HAL_PCD_SUSPEND_CB_ID = 0x04,
257 HAL_PCD_RESUME_CB_ID = 0x05,
258 HAL_PCD_CONNECT_CB_ID = 0x06,
259 HAL_PCD_DISCONNECT_CB_ID = 0x07,
261 HAL_PCD_MSPINIT_CB_ID = 0x08,
262 HAL_PCD_MSPDEINIT_CB_ID = 0x09
264 } HAL_PCD_CallbackIDTypeDef;
274 typedef void (*pPCD_CallbackTypeDef)(PCD_HandleTypeDef *hpcd);
275 typedef void (*pPCD_DataOutStageCallbackTypeDef)(PCD_HandleTypeDef *hpcd, uint8_t epnum);
276 typedef void (*pPCD_DataInStageCallbackTypeDef)(PCD_HandleTypeDef *hpcd, uint8_t epnum);
277 typedef void (*pPCD_IsoOutIncpltCallbackTypeDef)(PCD_HandleTypeDef *hpcd, uint8_t epnum);
278 typedef void (*pPCD_IsoInIncpltCallbackTypeDef)(PCD_HandleTypeDef *hpcd, uint8_t epnum);
279 typedef void (*pPCD_LpmCallbackTypeDef)(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg);
285 HAL_StatusTypeDef HAL_PCD_RegisterCallback(PCD_HandleTypeDef *hpcd, HAL_PCD_CallbackIDTypeDef CallbackID, pPCD_CallbackTypeDef pCallback);
286 HAL_StatusTypeDef HAL_PCD_UnRegisterCallback(PCD_HandleTypeDef *hpcd, HAL_PCD_CallbackIDTypeDef CallbackID);
288 HAL_StatusTypeDef HAL_PCD_RegisterDataOutStageCallback(PCD_HandleTypeDef *hpcd, pPCD_DataOutStageCallbackTypeDef pCallback);
289 HAL_StatusTypeDef HAL_PCD_UnRegisterDataOutStageCallback(PCD_HandleTypeDef *hpcd);
291 HAL_StatusTypeDef HAL_PCD_RegisterDataInStageCallback(PCD_HandleTypeDef *hpcd, pPCD_DataInStageCallbackTypeDef pCallback);
292 HAL_StatusTypeDef HAL_PCD_UnRegisterDataInStageCallback(PCD_HandleTypeDef *hpcd);
294 HAL_StatusTypeDef HAL_PCD_RegisterIsoOutIncpltCallback(PCD_HandleTypeDef *hpcd, pPCD_IsoOutIncpltCallbackTypeDef pCallback);
295 HAL_StatusTypeDef HAL_PCD_UnRegisterIsoOutIncpltCallback(PCD_HandleTypeDef *hpcd);
297 HAL_StatusTypeDef HAL_PCD_RegisterIsoInIncpltCallback(PCD_HandleTypeDef *hpcd, pPCD_IsoInIncpltCallbackTypeDef pCallback);
298 HAL_StatusTypeDef HAL_PCD_UnRegisterIsoInIncpltCallback(PCD_HandleTypeDef *hpcd);
300 HAL_StatusTypeDef HAL_PCD_RegisterLpmCallback(PCD_HandleTypeDef *hpcd, pPCD_LpmCallbackTypeDef pCallback);
314 void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd);
316 void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd);
317 void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd);
318 void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd);
319 void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd);
320 void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd);
321 void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd);
322 void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd);
324 void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
325 void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
326 void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
327 void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
339 HAL_StatusTypeDef HAL_PCD_EP_Open(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type);
341 HAL_StatusTypeDef HAL_PCD_EP_Receive(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len);
342 HAL_StatusTypeDef HAL_PCD_EP_Transmit(PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len);
343 uint32_t HAL_PCD_EP_GetRxCount(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
357 PCD_StateTypeDef HAL_PCD_GetState(PCD_HandleTypeDef *hpcd);
373 #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
374 #define USB_OTG_FS_WAKEUP_EXTI_LINE (0x1U << 18)
375 #define USB_OTG_HS_WAKEUP_EXTI_LINE (0x1U << 20)
386 #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
387 #ifndef USB_OTG_DOEPINT_OTEPSPR
388 #define USB_OTG_DOEPINT_OTEPSPR (0x1UL << 5)
391 #ifndef USB_OTG_DOEPMSK_OTEPSPRM
392 #define USB_OTG_DOEPMSK_OTEPSPRM (0x1UL << 5)
395 #ifndef USB_OTG_DOEPINT_NAK
396 #define USB_OTG_DOEPINT_NAK (0x1UL << 13)
399 #ifndef USB_OTG_DOEPMSK_NAKM
400 #define USB_OTG_DOEPMSK_NAKM (0x1UL << 13)
403 #ifndef USB_OTG_DOEPINT_STPKTRX
404 #define USB_OTG_DOEPINT_STPKTRX (0x1UL << 15)
407 #ifndef USB_OTG_DOEPMSK_NYETM
408 #define USB_OTG_DOEPMSK_NYETM (0x1UL << 14)