stm32f4xx_hal_pcd.h
Go to the documentation of this file.
1 
20 /* Define to prevent recursive inclusion -------------------------------------*/
21 #ifndef STM32F4xx_HAL_PCD_H
22 #define STM32F4xx_HAL_PCD_H
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32f4xx_ll_usb.h"
30 
31 #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
32 
41 /* Exported types ------------------------------------------------------------*/
49 typedef enum
50 {
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
56 } PCD_StateTypeDef;
57 
58 /* Device LPM suspend state */
59 typedef enum
60 {
61  LPM_L0 = 0x00, /* on */
62  LPM_L1 = 0x01, /* LPM L1 sleep */
63  LPM_L2 = 0x02, /* suspend */
64  LPM_L3 = 0x03, /* off */
65 } PCD_LPM_StateTypeDef;
66 
67 typedef enum
68 {
69  PCD_LPM_L0_ACTIVE = 0x00, /* on */
70  PCD_LPM_L1_ACTIVE = 0x01, /* LPM L1 sleep */
71 } PCD_LPM_MsgTypeDef;
72 
73 typedef enum
74 {
75  PCD_BCD_ERROR = 0xFF,
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,
81 
82 } PCD_BCD_MsgTypeDef;
83 
84 #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
85 typedef USB_OTG_GlobalTypeDef PCD_TypeDef;
86 typedef USB_OTG_CfgTypeDef PCD_InitTypeDef;
87 typedef USB_OTG_EPTypeDef PCD_EPTypeDef;
88 #endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
89 
93 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
94 typedef struct __PCD_HandleTypeDef
95 #else
96 typedef struct
97 #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
98 {
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];
104  HAL_LockTypeDef Lock;
105  __IO PCD_StateTypeDef State;
106  __IO uint32_t ErrorCode;
107  uint32_t Setup[12];
108  PCD_LPM_StateTypeDef LPM_State;
109  uint32_t BESL;
110 
111 
112  uint32_t lpm_active;
115  uint32_t battery_charging_active;
117  void *pData;
119 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
120  void (* SOFCallback)(struct __PCD_HandleTypeDef *hpcd);
121  void (* SetupStageCallback)(struct __PCD_HandleTypeDef *hpcd);
122  void (* ResetCallback)(struct __PCD_HandleTypeDef *hpcd);
123  void (* SuspendCallback)(struct __PCD_HandleTypeDef *hpcd);
124  void (* ResumeCallback)(struct __PCD_HandleTypeDef *hpcd);
125  void (* ConnectCallback)(struct __PCD_HandleTypeDef *hpcd);
126  void (* DisconnectCallback)(struct __PCD_HandleTypeDef *hpcd);
128  void (* DataOutStageCallback)(struct __PCD_HandleTypeDef *hpcd, uint8_t epnum);
129  void (* DataInStageCallback)(struct __PCD_HandleTypeDef *hpcd, uint8_t epnum);
130  void (* ISOOUTIncompleteCallback)(struct __PCD_HandleTypeDef *hpcd, uint8_t epnum);
131  void (* ISOINIncompleteCallback)(struct __PCD_HandleTypeDef *hpcd, uint8_t epnum);
132  void (* BCDCallback)(struct __PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg);
133  void (* LPMCallback)(struct __PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg);
135  void (* MspInitCallback)(struct __PCD_HandleTypeDef *hpcd);
136  void (* MspDeInitCallback)(struct __PCD_HandleTypeDef *hpcd);
137 #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
138 } PCD_HandleTypeDef;
139 
144 /* Include PCD HAL Extended module */
145 #include "stm32f4xx_hal_pcd_ex.h"
146 
147 /* Exported constants --------------------------------------------------------*/
155 #define PCD_SPEED_HIGH USBD_HS_SPEED
156 #define PCD_SPEED_HIGH_IN_FULL USBD_HSINFS_SPEED
157 #define PCD_SPEED_FULL USBD_FS_SPEED
158 
165 #define PCD_PHY_ULPI 1U
166 #define PCD_PHY_EMBEDDED 2U
167 #define PCD_PHY_UTMI 3U
168 
176 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
177 #define HAL_PCD_ERROR_INVALID_CALLBACK (0x00000010U)
178 #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
179 
188 /* Exported macros -----------------------------------------------------------*/
193 #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
194 #define __HAL_PCD_ENABLE(__HANDLE__) (void)USB_EnableGlobalInt ((__HANDLE__)->Instance)
195 #define __HAL_PCD_DISABLE(__HANDLE__) (void)USB_DisableGlobalInt ((__HANDLE__)->Instance)
196 
197 #define __HAL_PCD_GET_FLAG(__HANDLE__, __INTERRUPT__) ((USB_ReadInterrupts((__HANDLE__)->Instance) & (__INTERRUPT__)) == (__INTERRUPT__))
198 #define __HAL_PCD_CLEAR_FLAG(__HANDLE__, __INTERRUPT__) (((__HANDLE__)->Instance->GINTSTS) &= (__INTERRUPT__))
199 #define __HAL_PCD_IS_INVALID_INTERRUPT(__HANDLE__) (USB_ReadInterrupts((__HANDLE__)->Instance) == 0U)
200 
201 
202 #define __HAL_PCD_UNGATE_PHYCLOCK(__HANDLE__) *(__IO uint32_t *)((uint32_t)((__HANDLE__)->Instance) + USB_OTG_PCGCCTL_BASE) &= ~(USB_OTG_PCGCCTL_STOPCLK)
203 
204 #define __HAL_PCD_GATE_PHYCLOCK(__HANDLE__) *(__IO uint32_t *)((uint32_t)((__HANDLE__)->Instance) + USB_OTG_PCGCCTL_BASE) |= USB_OTG_PCGCCTL_STOPCLK
205 
206 #define __HAL_PCD_IS_PHY_SUSPENDED(__HANDLE__) ((*(__IO uint32_t *)((uint32_t)((__HANDLE__)->Instance) + USB_OTG_PCGCCTL_BASE)) & 0x10U)
207 
208 #define __HAL_USB_OTG_HS_WAKEUP_EXTI_ENABLE_IT() EXTI->IMR |= (USB_OTG_HS_WAKEUP_EXTI_LINE)
209 #define __HAL_USB_OTG_HS_WAKEUP_EXTI_DISABLE_IT() EXTI->IMR &= ~(USB_OTG_HS_WAKEUP_EXTI_LINE)
210 #define __HAL_USB_OTG_HS_WAKEUP_EXTI_GET_FLAG() EXTI->PR & (USB_OTG_HS_WAKEUP_EXTI_LINE)
211 #define __HAL_USB_OTG_HS_WAKEUP_EXTI_CLEAR_FLAG() EXTI->PR = (USB_OTG_HS_WAKEUP_EXTI_LINE)
212 
213 #define __HAL_USB_OTG_HS_WAKEUP_EXTI_ENABLE_RISING_EDGE() \
214  do { \
215  EXTI->FTSR &= ~(USB_OTG_HS_WAKEUP_EXTI_LINE); \
216  EXTI->RTSR |= USB_OTG_HS_WAKEUP_EXTI_LINE; \
217  } while(0U)
218 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_IT() EXTI->IMR |= USB_OTG_FS_WAKEUP_EXTI_LINE
219 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_DISABLE_IT() EXTI->IMR &= ~(USB_OTG_FS_WAKEUP_EXTI_LINE)
220 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_GET_FLAG() EXTI->PR & (USB_OTG_FS_WAKEUP_EXTI_LINE)
221 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_CLEAR_FLAG() EXTI->PR = USB_OTG_FS_WAKEUP_EXTI_LINE
222 
223 #define __HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_RISING_EDGE() \
224  do { \
225  EXTI->FTSR &= ~(USB_OTG_FS_WAKEUP_EXTI_LINE); \
226  EXTI->RTSR |= USB_OTG_FS_WAKEUP_EXTI_LINE; \
227  } while(0U)
228 #endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
229 
230 
235 /* Exported functions --------------------------------------------------------*/
240 /* Initialization/de-initialization functions ********************************/
244 HAL_StatusTypeDef HAL_PCD_Init(PCD_HandleTypeDef *hpcd);
245 HAL_StatusTypeDef HAL_PCD_DeInit(PCD_HandleTypeDef *hpcd);
246 void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd);
247 void HAL_PCD_MspDeInit(PCD_HandleTypeDef *hpcd);
248 
249 #if (USE_HAL_PCD_REGISTER_CALLBACKS == 1U)
250 
254 typedef enum
255 {
256  HAL_PCD_SOF_CB_ID = 0x01,
257  HAL_PCD_SETUPSTAGE_CB_ID = 0x02,
258  HAL_PCD_RESET_CB_ID = 0x03,
259  HAL_PCD_SUSPEND_CB_ID = 0x04,
260  HAL_PCD_RESUME_CB_ID = 0x05,
261  HAL_PCD_CONNECT_CB_ID = 0x06,
262  HAL_PCD_DISCONNECT_CB_ID = 0x07,
264  HAL_PCD_MSPINIT_CB_ID = 0x08,
265  HAL_PCD_MSPDEINIT_CB_ID = 0x09
267 } HAL_PCD_CallbackIDTypeDef;
277 typedef void (*pPCD_CallbackTypeDef)(PCD_HandleTypeDef *hpcd);
278 typedef void (*pPCD_DataOutStageCallbackTypeDef)(PCD_HandleTypeDef *hpcd, uint8_t epnum);
279 typedef void (*pPCD_DataInStageCallbackTypeDef)(PCD_HandleTypeDef *hpcd, uint8_t epnum);
280 typedef void (*pPCD_IsoOutIncpltCallbackTypeDef)(PCD_HandleTypeDef *hpcd, uint8_t epnum);
281 typedef void (*pPCD_IsoInIncpltCallbackTypeDef)(PCD_HandleTypeDef *hpcd, uint8_t epnum);
282 typedef void (*pPCD_LpmCallbackTypeDef)(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg);
283 typedef void (*pPCD_BcdCallbackTypeDef)(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg);
289 HAL_StatusTypeDef HAL_PCD_RegisterCallback(PCD_HandleTypeDef *hpcd,
290  HAL_PCD_CallbackIDTypeDef CallbackID,
291  pPCD_CallbackTypeDef pCallback);
292 
293 HAL_StatusTypeDef HAL_PCD_UnRegisterCallback(PCD_HandleTypeDef *hpcd,
294  HAL_PCD_CallbackIDTypeDef CallbackID);
295 
296 HAL_StatusTypeDef HAL_PCD_RegisterDataOutStageCallback(PCD_HandleTypeDef *hpcd,
297  pPCD_DataOutStageCallbackTypeDef pCallback);
298 
299 HAL_StatusTypeDef HAL_PCD_UnRegisterDataOutStageCallback(PCD_HandleTypeDef *hpcd);
300 
301 HAL_StatusTypeDef HAL_PCD_RegisterDataInStageCallback(PCD_HandleTypeDef *hpcd,
302  pPCD_DataInStageCallbackTypeDef pCallback);
303 
304 HAL_StatusTypeDef HAL_PCD_UnRegisterDataInStageCallback(PCD_HandleTypeDef *hpcd);
305 
306 HAL_StatusTypeDef HAL_PCD_RegisterIsoOutIncpltCallback(PCD_HandleTypeDef *hpcd,
307  pPCD_IsoOutIncpltCallbackTypeDef pCallback);
308 
309 HAL_StatusTypeDef HAL_PCD_UnRegisterIsoOutIncpltCallback(PCD_HandleTypeDef *hpcd);
310 
311 HAL_StatusTypeDef HAL_PCD_RegisterIsoInIncpltCallback(PCD_HandleTypeDef *hpcd,
312  pPCD_IsoInIncpltCallbackTypeDef pCallback);
313 
314 HAL_StatusTypeDef HAL_PCD_UnRegisterIsoInIncpltCallback(PCD_HandleTypeDef *hpcd);
315 
316 HAL_StatusTypeDef HAL_PCD_RegisterBcdCallback(PCD_HandleTypeDef *hpcd,
317  pPCD_BcdCallbackTypeDef pCallback);
318 
319 HAL_StatusTypeDef HAL_PCD_UnRegisterBcdCallback(PCD_HandleTypeDef *hpcd);
320 
321 HAL_StatusTypeDef HAL_PCD_RegisterLpmCallback(PCD_HandleTypeDef *hpcd,
322  pPCD_LpmCallbackTypeDef pCallback);
323 
324 HAL_StatusTypeDef HAL_PCD_UnRegisterLpmCallback(PCD_HandleTypeDef *hpcd);
325 #endif /* USE_HAL_PCD_REGISTER_CALLBACKS */
326 
330 /* I/O operation functions ***************************************************/
331 /* Non-Blocking mode: Interrupt */
335 HAL_StatusTypeDef HAL_PCD_Start(PCD_HandleTypeDef *hpcd);
336 HAL_StatusTypeDef HAL_PCD_Stop(PCD_HandleTypeDef *hpcd);
337 void HAL_PCD_IRQHandler(PCD_HandleTypeDef *hpcd);
338 void HAL_PCD_WKUP_IRQHandler(PCD_HandleTypeDef *hpcd);
339 
340 void HAL_PCD_SOFCallback(PCD_HandleTypeDef *hpcd);
341 void HAL_PCD_SetupStageCallback(PCD_HandleTypeDef *hpcd);
342 void HAL_PCD_ResetCallback(PCD_HandleTypeDef *hpcd);
343 void HAL_PCD_SuspendCallback(PCD_HandleTypeDef *hpcd);
344 void HAL_PCD_ResumeCallback(PCD_HandleTypeDef *hpcd);
345 void HAL_PCD_ConnectCallback(PCD_HandleTypeDef *hpcd);
346 void HAL_PCD_DisconnectCallback(PCD_HandleTypeDef *hpcd);
347 
348 void HAL_PCD_DataOutStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
349 void HAL_PCD_DataInStageCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
350 void HAL_PCD_ISOOUTIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
351 void HAL_PCD_ISOINIncompleteCallback(PCD_HandleTypeDef *hpcd, uint8_t epnum);
356 /* Peripheral Control functions **********************************************/
360 HAL_StatusTypeDef HAL_PCD_DevConnect(PCD_HandleTypeDef *hpcd);
361 HAL_StatusTypeDef HAL_PCD_DevDisconnect(PCD_HandleTypeDef *hpcd);
362 HAL_StatusTypeDef HAL_PCD_SetAddress(PCD_HandleTypeDef *hpcd, uint8_t address);
363 HAL_StatusTypeDef HAL_PCD_EP_Open(PCD_HandleTypeDef *hpcd, uint8_t ep_addr,
364  uint16_t ep_mps, uint8_t ep_type);
365 
366 HAL_StatusTypeDef HAL_PCD_EP_Close(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
367 HAL_StatusTypeDef HAL_PCD_EP_Receive(PCD_HandleTypeDef *hpcd, uint8_t ep_addr,
368  uint8_t *pBuf, uint32_t len);
369 
370 HAL_StatusTypeDef HAL_PCD_EP_Transmit(PCD_HandleTypeDef *hpcd, uint8_t ep_addr,
371  uint8_t *pBuf, uint32_t len);
372 
373 
374 HAL_StatusTypeDef HAL_PCD_EP_SetStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
375 HAL_StatusTypeDef HAL_PCD_EP_ClrStall(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
376 HAL_StatusTypeDef HAL_PCD_EP_Flush(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
377 HAL_StatusTypeDef HAL_PCD_ActivateRemoteWakeup(PCD_HandleTypeDef *hpcd);
378 HAL_StatusTypeDef HAL_PCD_DeActivateRemoteWakeup(PCD_HandleTypeDef *hpcd);
379 
380 uint32_t HAL_PCD_EP_GetRxCount(PCD_HandleTypeDef *hpcd, uint8_t ep_addr);
385 /* Peripheral State functions ************************************************/
389 PCD_StateTypeDef HAL_PCD_GetState(PCD_HandleTypeDef *hpcd);
398 /* Private constants ---------------------------------------------------------*/
405 #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
406 #define USB_OTG_FS_WAKEUP_EXTI_LINE (0x1U << 18)
407 #define USB_OTG_HS_WAKEUP_EXTI_LINE (0x1U << 20)
408 #endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
409 
410 
418 #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
419 #ifndef USB_OTG_DOEPINT_OTEPSPR
420 #define USB_OTG_DOEPINT_OTEPSPR (0x1UL << 5)
421 #endif
422 
423 #ifndef USB_OTG_DOEPMSK_OTEPSPRM
424 #define USB_OTG_DOEPMSK_OTEPSPRM (0x1UL << 5)
425 #endif
426 
427 #ifndef USB_OTG_DOEPINT_NAK
428 #define USB_OTG_DOEPINT_NAK (0x1UL << 13)
429 #endif
430 
431 #ifndef USB_OTG_DOEPMSK_NAKM
432 #define USB_OTG_DOEPMSK_NAKM (0x1UL << 13)
433 #endif
434 
435 #ifndef USB_OTG_DOEPINT_STPKTRX
436 #define USB_OTG_DOEPINT_STPKTRX (0x1UL << 15)
437 #endif
438 
439 #ifndef USB_OTG_DOEPMSK_NYETM
440 #define USB_OTG_DOEPMSK_NYETM (0x1UL << 14)
441 #endif
442 #endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
443 
444 /* Private macros ------------------------------------------------------------*/
460 #endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
461 
462 #ifdef __cplusplus
463 }
464 #endif
465 
466 #endif /* STM32F4xx_HAL_PCD_H */
467 
468 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
__IO
#define __IO
Definition: imxrt1050/imxrt1050-evkb/CMSIS/core_cm7.h:237
Init
napi_value Init(napi_env env, napi_value exports)
Definition: porcupine/demo/c/pvrecorder/node/pv_recorder_napi.c:197
HAL_StatusTypeDef
HAL_StatusTypeDef
HAL Status structures definition
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:40
stm32f4xx_hal_pcd_ex.h
Header file of PCD HAL Extension module.
HAL_LockTypeDef
HAL_LockTypeDef
HAL Lock structures definition
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:51
USB_OTG_GlobalTypeDef
USB_OTG_Core_Registers.
Definition: stm32f407xx.h:794


picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:14:52