1 /**
2   ******************************************************************************
3   * @file    stm32l4xx_ll_usb.h
4   * @author  MCD Application Team
5   * @brief   Header file of USB Low Layer HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2017 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32L4xx_LL_USB_H
21 #define STM32L4xx_LL_USB_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif /* __cplusplus */
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32l4xx_hal_def.h"
29 
30 #if defined (USB) || defined (USB_OTG_FS)
31 /** @addtogroup STM32L4xx_HAL_Driver
32   * @{
33   */
34 
35 /** @addtogroup USB_LL
36   * @{
37   */
38 
39 /* Exported types ------------------------------------------------------------*/
40 #ifndef HAL_USB_TIMEOUT
41 #define HAL_USB_TIMEOUT                                       0xF000000U
42 #endif /* define HAL_USB_TIMEOUT */
43 
44 #ifndef HAL_USB_CURRENT_MODE_MAX_DELAY_MS
45 #define HAL_USB_CURRENT_MODE_MAX_DELAY_MS                           200U
46 #endif /* define HAL_USB_CURRENT_MODE_MAX_DELAY_MS */
47 
48 /**
49   * @brief  USB Mode definition
50   */
51 
52 typedef enum
53 {
54   USB_DEVICE_MODE = 0,
55   USB_HOST_MODE   = 1,
56   USB_DRD_MODE    = 2
57 } USB_ModeTypeDef;
58 
59 /**
60   * @brief  URB States definition
61   */
62 typedef enum
63 {
64   URB_IDLE = 0,
65   URB_DONE,
66   URB_NOTREADY,
67   URB_NYET,
68   URB_ERROR,
69   URB_STALL
70 } USB_URBStateTypeDef;
71 
72 /**
73   * @brief  Host channel States  definition
74   */
75 typedef enum
76 {
77   HC_IDLE = 0,
78   HC_XFRC,
79   HC_HALTED,
80   HC_ACK,
81   HC_NAK,
82   HC_NYET,
83   HC_STALL,
84   HC_XACTERR,
85   HC_BBLERR,
86   HC_DATATGLERR
87 } USB_HCStateTypeDef;
88 
89 
90 /**
91   * @brief  USB Instance Initialization Structure definition
92   */
93 typedef struct
94 {
95   uint8_t dev_endpoints;            /*!< Device Endpoints number.
96                                          This parameter depends on the used USB core.
97                                          This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
98 
99 #if defined (USB_OTG_FS)
100   uint8_t Host_channels;            /*!< Host Channels number.
101                                          This parameter Depends on the used USB core.
102                                          This parameter must be a number between Min_Data = 1 and Max_Data = 15 */
103 #endif /* defined (USB_OTG_FS) */
104 
105   uint8_t dma_enable;              /*!< USB DMA state.
106                                          If DMA is not supported this parameter shall be set by default to zero */
107 
108   uint8_t speed;                   /*!< USB Core speed.
109                                         This parameter can be any value of @ref PCD_Speed/HCD_Speed
110                                                                                 (HCD_SPEED_xxx, HCD_SPEED_xxx) */
111 
112   uint8_t ep0_mps;                 /*!< Set the Endpoint 0 Max Packet size.                                    */
113 
114   uint8_t phy_itface;              /*!< Select the used PHY interface.
115                                         This parameter can be any value of @ref PCD_PHY_Module/HCD_PHY_Module  */
116 
117   uint8_t Sof_enable;              /*!< Enable or disable the output of the SOF signal.                        */
118 
119   uint8_t low_power_enable;        /*!< Enable or disable the low Power Mode.                                  */
120 
121   uint8_t lpm_enable;              /*!< Enable or disable Link Power Management.                               */
122 
123   uint8_t battery_charging_enable; /*!< Enable or disable Battery charging.                                    */
124 
125 #if defined (USB_OTG_FS)
126   uint8_t vbus_sensing_enable;     /*!< Enable or disable the VBUS Sensing feature.                            */
127 
128   uint8_t use_dedicated_ep1;       /*!< Enable or disable the use of the dedicated EP1 interrupt.              */
129 
130   uint8_t use_external_vbus;       /*!< Enable or disable the use of the external VBUS.                        */
131 #endif /* defined (USB_OTG_FS) */
132 } USB_CfgTypeDef;
133 
134 typedef struct
135 {
136   uint8_t   num;                  /*!< Endpoint number
137                                        This parameter must be a number between Min_Data = 1 and Max_Data = 15   */
138 
139   uint8_t   is_in;                /*!< Endpoint direction
140                                        This parameter must be a number between Min_Data = 0 and Max_Data = 1    */
141 
142   uint8_t   is_stall;             /*!< Endpoint stall condition
143                                        This parameter must be a number between Min_Data = 0 and Max_Data = 1    */
144 
145 #if defined (USB_OTG_FS)
146   uint8_t   is_iso_incomplete;    /*!< Endpoint isoc condition
147                                        This parameter must be a number between Min_Data = 0 and Max_Data = 1    */
148 #endif /* defined (USB_OTG_FS) */
149 
150   uint8_t   type;                 /*!< Endpoint type
151                                        This parameter can be any value of @ref USB_LL_EP_Type                   */
152 
153   uint8_t   data_pid_start;       /*!< Initial data PID
154                                        This parameter must be a number between Min_Data = 0 and Max_Data = 1    */
155 
156 #if defined (USB)
157   uint16_t  pmaadress;            /*!< PMA Address
158                                        This parameter can be any value between Min_addr = 0 and Max_addr = 1K   */
159 
160   uint16_t  pmaaddr0;             /*!< PMA Address0
161                                        This parameter can be any value between Min_addr = 0 and Max_addr = 1K   */
162 
163   uint16_t  pmaaddr1;             /*!< PMA Address1
164                                        This parameter can be any value between Min_addr = 0 and Max_addr = 1K   */
165 
166   uint8_t   doublebuffer;         /*!< Double buffer enable
167                                        This parameter can be 0 or 1                                             */
168 #endif /* defined (USB) */
169 
170   uint32_t  maxpacket;            /*!< Endpoint Max packet size
171                                        This parameter must be a number between Min_Data = 0 and Max_Data = 64KB */
172 
173   uint8_t   *xfer_buff;           /*!< Pointer to transfer buffer                                               */
174 
175   uint32_t  xfer_len;             /*!< Current transfer length                                                  */
176 
177   uint32_t  xfer_count;           /*!< Partial transfer length in case of multi packet transfer                 */
178 
179 #if defined (USB_OTG_FS)
180   uint8_t   even_odd_frame;       /*!< IFrame parity
181                                        This parameter must be a number between Min_Data = 0 and Max_Data = 1    */
182 
183   uint16_t  tx_fifo_num;          /*!< Transmission FIFO number
184                                        This parameter must be a number between Min_Data = 1 and Max_Data = 15   */
185 
186   uint32_t  dma_addr;             /*!< 32 bits aligned transfer buffer address                                  */
187 
188   uint32_t  xfer_size;            /*!< requested transfer size                                                  */
189 #endif /* defined (USB_OTG_FS) */
190 
191 #if defined (USB)
192   uint32_t  xfer_len_db;          /*!< double buffer transfer length used with bulk double buffer in            */
193 
194   uint8_t   xfer_fill_db;         /*!< double buffer Need to Fill new buffer  used with bulk_in                 */
195 #endif /* defined (USB) */
196 } USB_EPTypeDef;
197 
198 typedef struct
199 {
200   uint8_t   dev_addr;           /*!< USB device address.
201                                      This parameter must be a number between Min_Data = 1 and Max_Data = 255    */
202 
203   uint8_t   ch_num;             /*!< Host channel number.
204                                      This parameter must be a number between Min_Data = 1 and Max_Data = 15     */
205 
206   uint8_t   ep_num;             /*!< Endpoint number.
207                                      This parameter must be a number between Min_Data = 1 and Max_Data = 15     */
208 
209   uint8_t   ep_is_in;           /*!< Endpoint direction
210                                      This parameter must be a number between Min_Data = 0 and Max_Data = 1      */
211 
212   uint8_t   speed;              /*!< USB Host Channel speed.
213                                      This parameter can be any value of @ref HCD_Device_Speed:
214                                                                              (HCD_DEVICE_SPEED_xxx)             */
215 
216   uint8_t   do_ping;            /*!< Enable or disable the use of the PING protocol for HS mode.                */
217 
218   uint8_t   hub_port_nbr;       /*!< USB HUB port number                                                        */
219   uint8_t   hub_addr;           /*!< USB HUB address                                                            */
220 
221   uint8_t   ep_type;            /*!< Endpoint Type.
222                                      This parameter can be any value of @ref USB_LL_EP_Type                     */
223 
224   uint16_t  max_packet;         /*!< Endpoint Max packet size.
225                                      This parameter must be a number between Min_Data = 0 and Max_Data = 64KB   */
226 
227   uint8_t   data_pid;           /*!< Initial data PID.
228                                      This parameter must be a number between Min_Data = 0 and Max_Data = 1      */
229 
230   uint8_t   *xfer_buff;         /*!< Pointer to transfer buffer.                                                */
231 
232   uint32_t  XferSize;           /*!< OTG Channel transfer size.                                                 */
233 
234   uint32_t  xfer_len;           /*!< Current transfer length.                                                   */
235 
236   uint32_t  xfer_count;         /*!< Partial transfer length in case of multi packet transfer.                  */
237 
238   uint8_t   toggle_in;          /*!< IN transfer current toggle flag.
239                                      This parameter must be a number between Min_Data = 0 and Max_Data = 1      */
240 
241   uint8_t   toggle_out;         /*!< OUT transfer current toggle flag
242                                      This parameter must be a number between Min_Data = 0 and Max_Data = 1      */
243 
244   uint32_t  dma_addr;           /*!< 32 bits aligned transfer buffer address.                                   */
245 
246   uint32_t  ErrCnt;             /*!< Host channel error count.                                                  */
247 
248   USB_URBStateTypeDef urb_state;  /*!< URB state.
249                                        This parameter can be any value of @ref USB_URBStateTypeDef              */
250 
251   USB_HCStateTypeDef state;       /*!< Host Channel state.
252                                        This parameter can be any value of @ref USB_HCStateTypeDef               */
253 } USB_HCTypeDef;
254 
255 #if defined (USB_OTG_FS)
256 typedef USB_ModeTypeDef     USB_OTG_ModeTypeDef;
257 typedef USB_CfgTypeDef      USB_OTG_CfgTypeDef;
258 typedef USB_EPTypeDef       USB_OTG_EPTypeDef;
259 typedef USB_URBStateTypeDef USB_OTG_URBStateTypeDef;
260 typedef USB_HCStateTypeDef  USB_OTG_HCStateTypeDef;
261 typedef USB_HCTypeDef       USB_OTG_HCTypeDef;
262 #endif /* defined (USB_OTG_FS) */
263 
264 /* Exported constants --------------------------------------------------------*/
265 
266 /** @defgroup PCD_Exported_Constants PCD Exported Constants
267   * @{
268   */
269 
270 #if defined (USB_OTG_FS)
271 /** @defgroup USB_OTG_CORE VERSION ID
272   * @{
273   */
274 #define USB_OTG_CORE_ID_300A          0x4F54300AU
275 #define USB_OTG_CORE_ID_310A          0x4F54310AU
276 /**
277   * @}
278   */
279 
280 /** @defgroup USB_Core_Mode_ USB Core Mode
281   * @{
282   */
283 #define USB_OTG_MODE_DEVICE                    0U
284 #define USB_OTG_MODE_HOST                      1U
285 #define USB_OTG_MODE_DRD                       2U
286 /**
287   * @}
288   */
289 
290 /** @defgroup USB_LL_Core_Speed USB Low Layer Core Speed
291   * @{
292   */
293 #define USB_OTG_SPEED_FULL                     3U
294 /**
295   * @}
296   */
297 
298 /** @defgroup USB_LL_Core_PHY USB Low Layer Core PHY
299   * @{
300   */
301 #define USB_OTG_EMBEDDED_PHY                   2U
302 /**
303   * @}
304   */
305 
306 /** @defgroup USB_LL_Turnaround_Timeout Turnaround Timeout Value
307   * @{
308   */
309 #ifndef USBD_FS_TRDT_VALUE
310 #define USBD_FS_TRDT_VALUE                     5U
311 #define USBD_DEFAULT_TRDT_VALUE                9U
312 #endif /* USBD_HS_TRDT_VALUE */
313 /**
314   * @}
315   */
316 
317 /** @defgroup USB_LL_Core_MPS USB Low Layer Core MPS
318   * @{
319   */
320 #define USB_OTG_FS_MAX_PACKET_SIZE            64U
321 #define USB_OTG_MAX_EP0_SIZE                  64U
322 /**
323   * @}
324   */
325 
326 /** @defgroup USB_LL_Core_PHY_Frequency USB Low Layer Core PHY Frequency
327   * @{
328   */
329 #define DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ     (0U << 1)
330 #define DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ     (1U << 1)
331 #define DSTS_ENUMSPD_FS_PHY_48MHZ              (3U << 1)
332 /**
333   * @}
334   */
335 
336 /** @defgroup USB_LL_CORE_Frame_Interval USB Low Layer Core Frame Interval
337   * @{
338   */
339 #define DCFG_FRAME_INTERVAL_80                 0U
340 #define DCFG_FRAME_INTERVAL_85                 1U
341 #define DCFG_FRAME_INTERVAL_90                 2U
342 #define DCFG_FRAME_INTERVAL_95                 3U
343 /**
344   * @}
345   */
346 #endif /* defined (USB_OTG_FS) */
347 /** @defgroup USB_LL_EP0_MPS USB Low Layer EP0 MPS
348   * @{
349   */
350 #define EP_MPS_64                              0U
351 #define EP_MPS_32                              1U
352 #define EP_MPS_16                              2U
353 #define EP_MPS_8                               3U
354 /**
355   * @}
356   */
357 
358 /** @defgroup USB_LL_EP_Type USB Low Layer EP Type
359   * @{
360   */
361 #define EP_TYPE_CTRL                           0U
362 #define EP_TYPE_ISOC                           1U
363 #define EP_TYPE_BULK                           2U
364 #define EP_TYPE_INTR                           3U
365 #define EP_TYPE_MSK                            3U
366 /**
367   * @}
368   */
369 
370 /** @defgroup USB_LL_EP_Speed USB Low Layer EP Speed
371   * @{
372   */
373 #define EP_SPEED_LOW                           0U
374 #define EP_SPEED_FULL                          1U
375 #define EP_SPEED_HIGH                          2U
376 /**
377   * @}
378   */
379 
380 /** @defgroup USB_LL_CH_PID_Type USB Low Layer Channel PID Type
381   * @{
382   */
383 #define HC_PID_DATA0                           0U
384 #define HC_PID_DATA2                           1U
385 #define HC_PID_DATA1                           2U
386 #define HC_PID_SETUP                           3U
387 /**
388   * @}
389   */
390 
391 /** @defgroup USB_LL Device Speed
392   * @{
393   */
394 #define USBD_FS_SPEED                          2U
395 #define USBH_FSLS_SPEED                        1U
396 /**
397   * @}
398   */
399 
400 #if defined (USB_OTG_FS)
401 /** @defgroup USB_LL_STS_Defines USB Low Layer STS Defines
402   * @{
403   */
404 #define STS_GOUT_NAK                           1U
405 #define STS_DATA_UPDT                          2U
406 #define STS_XFER_COMP                          3U
407 #define STS_SETUP_COMP                         4U
408 #define STS_SETUP_UPDT                         6U
409 /**
410   * @}
411   */
412 
413 /** @defgroup USB_LL_HCFG_SPEED_Defines USB Low Layer HCFG Speed Defines
414   * @{
415   */
416 #define HCFG_30_60_MHZ                         0U
417 #define HCFG_48_MHZ                            1U
418 #define HCFG_6_MHZ                             2U
419 /**
420   * @}
421   */
422 
423 /** @defgroup USB_LL_HFIR_Defines USB Low Layer frame interval Defines
424   * @{
425   */
426 #define HFIR_6_MHZ                          6000U
427 #define HFIR_60_MHZ                        60000U
428 #define HFIR_48_MHZ                        48000U
429 /**
430   * @}
431   */
432 
433 /** @defgroup USB_LL_HPRT0_PRTSPD_SPEED_Defines USB Low Layer HPRT0 PRTSPD Speed Defines
434   * @{
435   */
436 #define HPRT0_PRTSPD_HIGH_SPEED                0U
437 #define HPRT0_PRTSPD_FULL_SPEED                1U
438 #define HPRT0_PRTSPD_LOW_SPEED                 2U
439 /**
440   * @}
441   */
442 
443 #define HCCHAR_CTRL                            0U
444 #define HCCHAR_ISOC                            1U
445 #define HCCHAR_BULK                            2U
446 #define HCCHAR_INTR                            3U
447 
448 #define GRXSTS_PKTSTS_IN                       2U
449 #define GRXSTS_PKTSTS_IN_XFER_COMP             3U
450 #define GRXSTS_PKTSTS_DATA_TOGGLE_ERR          5U
451 #define GRXSTS_PKTSTS_CH_HALTED                7U
452 
453 #define CLEAR_INTERRUPT_MASK          0xFFFFFFFFU
454 
455 #define HC_MAX_PKT_CNT                       256U
456 
457 #define USBx_PCGCCTL    *(__IO uint32_t *)((uint32_t)USBx_BASE + USB_OTG_PCGCCTL_BASE)
458 #define USBx_HPRT0      *(__IO uint32_t *)((uint32_t)USBx_BASE + USB_OTG_HOST_PORT_BASE)
459 
460 #define USBx_DEVICE     ((USB_OTG_DeviceTypeDef *)(USBx_BASE + USB_OTG_DEVICE_BASE))
461 #define USBx_INEP(i)    ((USB_OTG_INEndpointTypeDef *)(USBx_BASE\
462                                                        + USB_OTG_IN_ENDPOINT_BASE + ((i) * USB_OTG_EP_REG_SIZE)))
463 
464 #define USBx_OUTEP(i)   ((USB_OTG_OUTEndpointTypeDef *)(USBx_BASE\
465                                                         + USB_OTG_OUT_ENDPOINT_BASE + ((i) * USB_OTG_EP_REG_SIZE)))
466 
467 #define USBx_DFIFO(i)   *(__IO uint32_t *)(USBx_BASE + USB_OTG_FIFO_BASE + ((i) * USB_OTG_FIFO_SIZE))
468 
469 #define USBx_HOST       ((USB_OTG_HostTypeDef *)(USBx_BASE + USB_OTG_HOST_BASE))
470 #define USBx_HC(i)      ((USB_OTG_HostChannelTypeDef *)(USBx_BASE\
471                                                         + USB_OTG_HOST_CHANNEL_BASE\
472                                                         + ((i) * USB_OTG_HOST_CHANNEL_SIZE)))
473 
474 
475 #define EP_ADDR_MSK                            0xFU
476 #endif /* defined (USB_OTG_FS) */
477 
478 #if defined (USB)
479 #define BTABLE_ADDRESS                         0x000U
480 #define PMA_ACCESS                             1U
481 
482 #ifndef USB_EP_RX_STRX
483 #define USB_EP_RX_STRX                         (0x3U << 12)
484 #endif /* USB_EP_RX_STRX */
485 
486 #define EP_ADDR_MSK                            0x7U
487 
488 #ifndef USE_USB_DOUBLE_BUFFER
489 #define USE_USB_DOUBLE_BUFFER                  1U
490 #endif /* USE_USB_DOUBLE_BUFFER */
491 #endif /* defined (USB) */
492 
493 /**
494   * @}
495   */
496 
497 /* Exported macro ------------------------------------------------------------*/
498 /** @defgroup USB_LL_Exported_Macros USB Low Layer Exported Macros
499   * @{
500   */
501 #if defined (USB_OTG_FS)
502 #define USB_MASK_INTERRUPT(__INSTANCE__, __INTERRUPT__)     ((__INSTANCE__)->GINTMSK &= ~(__INTERRUPT__))
503 #define USB_UNMASK_INTERRUPT(__INSTANCE__, __INTERRUPT__)   ((__INSTANCE__)->GINTMSK |= (__INTERRUPT__))
504 
505 #define CLEAR_IN_EP_INTR(__EPNUM__, __INTERRUPT__)          (USBx_INEP(__EPNUM__)->DIEPINT = (__INTERRUPT__))
506 #define CLEAR_OUT_EP_INTR(__EPNUM__, __INTERRUPT__)         (USBx_OUTEP(__EPNUM__)->DOEPINT = (__INTERRUPT__))
507 #endif /* defined (USB_OTG_FS) */
508 /**
509   * @}
510   */
511 
512 /* Exported functions --------------------------------------------------------*/
513 /** @addtogroup USB_LL_Exported_Functions USB Low Layer Exported Functions
514   * @{
515   */
516 #if defined (USB_OTG_FS)
517 HAL_StatusTypeDef USB_CoreInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg);
518 HAL_StatusTypeDef USB_DevInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg);
519 HAL_StatusTypeDef USB_EnableGlobalInt(USB_OTG_GlobalTypeDef *USBx);
520 HAL_StatusTypeDef USB_DisableGlobalInt(USB_OTG_GlobalTypeDef *USBx);
521 HAL_StatusTypeDef USB_SetTurnaroundTime(USB_OTG_GlobalTypeDef *USBx, uint32_t hclk, uint8_t speed);
522 HAL_StatusTypeDef USB_SetCurrentMode(USB_OTG_GlobalTypeDef *USBx, USB_ModeTypeDef mode);
523 HAL_StatusTypeDef USB_SetDevSpeed(const USB_OTG_GlobalTypeDef *USBx, uint8_t speed);
524 HAL_StatusTypeDef USB_FlushRxFifo(USB_OTG_GlobalTypeDef *USBx);
525 HAL_StatusTypeDef USB_FlushTxFifo(USB_OTG_GlobalTypeDef *USBx, uint32_t num);
526 HAL_StatusTypeDef USB_ActivateEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep);
527 HAL_StatusTypeDef USB_DeactivateEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep);
528 HAL_StatusTypeDef USB_ActivateDedicatedEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep);
529 HAL_StatusTypeDef USB_DeactivateDedicatedEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep);
530 HAL_StatusTypeDef USB_EPStartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep);
531 HAL_StatusTypeDef USB_WritePacket(const USB_OTG_GlobalTypeDef *USBx, uint8_t *src,
532                                   uint8_t ch_ep_num, uint16_t len);
533 
534 void             *USB_ReadPacket(const USB_OTG_GlobalTypeDef *USBx, uint8_t *dest, uint16_t len);
535 HAL_StatusTypeDef USB_EPSetStall(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep);
536 HAL_StatusTypeDef USB_EPClearStall(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep);
537 HAL_StatusTypeDef USB_EPStopXfer(const USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep);
538 HAL_StatusTypeDef USB_SetDevAddress(const USB_OTG_GlobalTypeDef *USBx, uint8_t address);
539 HAL_StatusTypeDef USB_DevConnect(const USB_OTG_GlobalTypeDef *USBx);
540 HAL_StatusTypeDef USB_DevDisconnect(const USB_OTG_GlobalTypeDef *USBx);
541 HAL_StatusTypeDef USB_StopDevice(USB_OTG_GlobalTypeDef *USBx);
542 HAL_StatusTypeDef USB_ActivateSetup(const USB_OTG_GlobalTypeDef *USBx);
543 HAL_StatusTypeDef USB_EP0_OutStart(const USB_OTG_GlobalTypeDef *USBx, const uint8_t *psetup);
544 uint8_t           USB_GetDevSpeed(const USB_OTG_GlobalTypeDef *USBx);
545 uint32_t          USB_GetMode(const USB_OTG_GlobalTypeDef *USBx);
546 uint32_t          USB_ReadInterrupts(USB_OTG_GlobalTypeDef const *USBx);
547 uint32_t          USB_ReadChInterrupts(const USB_OTG_GlobalTypeDef *USBx, uint8_t chnum);
548 uint32_t          USB_ReadDevAllOutEpInterrupt(const USB_OTG_GlobalTypeDef *USBx);
549 uint32_t          USB_ReadDevOutEPInterrupt(const USB_OTG_GlobalTypeDef *USBx, uint8_t epnum);
550 uint32_t          USB_ReadDevAllInEpInterrupt(const USB_OTG_GlobalTypeDef *USBx);
551 uint32_t          USB_ReadDevInEPInterrupt(const USB_OTG_GlobalTypeDef *USBx, uint8_t epnum);
552 void              USB_ClearInterrupts(USB_OTG_GlobalTypeDef *USBx, uint32_t interrupt);
553 
554 HAL_StatusTypeDef USB_HostInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg);
555 HAL_StatusTypeDef USB_InitFSLSPClkSel(const USB_OTG_GlobalTypeDef *USBx, uint8_t freq);
556 HAL_StatusTypeDef USB_ResetPort(const USB_OTG_GlobalTypeDef *USBx);
557 HAL_StatusTypeDef USB_DriveVbus(const USB_OTG_GlobalTypeDef *USBx, uint8_t state);
558 uint32_t          USB_GetHostSpeed(USB_OTG_GlobalTypeDef const *USBx);
559 uint32_t          USB_GetCurrentFrame(USB_OTG_GlobalTypeDef const *USBx);
560 HAL_StatusTypeDef USB_HC_Init(USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num,
561                               uint8_t epnum, uint8_t dev_address, uint8_t speed,
562                               uint8_t ep_type, uint16_t mps);
563 HAL_StatusTypeDef USB_HC_StartXfer(USB_OTG_GlobalTypeDef *USBx,
564                                    USB_OTG_HCTypeDef *hc);
565 
566 uint32_t          USB_HC_ReadInterrupt(const USB_OTG_GlobalTypeDef *USBx);
567 HAL_StatusTypeDef USB_HC_Halt(const USB_OTG_GlobalTypeDef *USBx, uint8_t hc_num);
568 HAL_StatusTypeDef USB_DoPing(const USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num);
569 HAL_StatusTypeDef USB_StopHost(USB_OTG_GlobalTypeDef *USBx);
570 HAL_StatusTypeDef USB_ActivateRemoteWakeup(const USB_OTG_GlobalTypeDef *USBx);
571 HAL_StatusTypeDef USB_DeActivateRemoteWakeup(const USB_OTG_GlobalTypeDef *USBx);
572 #endif /* defined (USB_OTG_FS) */
573 
574 #if defined (USB)
575 HAL_StatusTypeDef USB_CoreInit(USB_TypeDef *USBx, USB_CfgTypeDef cfg);
576 HAL_StatusTypeDef USB_DevInit(USB_TypeDef *USBx, USB_CfgTypeDef cfg);
577 HAL_StatusTypeDef USB_EnableGlobalInt(USB_TypeDef *USBx);
578 HAL_StatusTypeDef USB_DisableGlobalInt(USB_TypeDef *USBx);
579 HAL_StatusTypeDef USB_SetCurrentMode(USB_TypeDef *USBx, USB_ModeTypeDef mode);
580 HAL_StatusTypeDef USB_SetDevSpeed(USB_TypeDef *USBx, uint8_t speed);
581 
582 HAL_StatusTypeDef USB_FlushRxFifo(USB_TypeDef const *USBx);
583 HAL_StatusTypeDef USB_FlushTxFifo(USB_TypeDef const *USBx, uint32_t num);
584 
585 #if defined (HAL_PCD_MODULE_ENABLED)
586 HAL_StatusTypeDef USB_ActivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep);
587 HAL_StatusTypeDef USB_DeactivateEndpoint(USB_TypeDef *USBx, USB_EPTypeDef *ep);
588 HAL_StatusTypeDef USB_EPStartXfer(USB_TypeDef *USBx, USB_EPTypeDef *ep);
589 HAL_StatusTypeDef USB_EPSetStall(USB_TypeDef *USBx, USB_EPTypeDef *ep);
590 HAL_StatusTypeDef USB_EPClearStall(USB_TypeDef *USBx, USB_EPTypeDef *ep);
591 HAL_StatusTypeDef USB_EPStopXfer(USB_TypeDef *USBx, USB_EPTypeDef *ep);
592 #endif /* defined (HAL_PCD_MODULE_ENABLED) */
593 
594 HAL_StatusTypeDef USB_SetDevAddress(USB_TypeDef *USBx, uint8_t address);
595 HAL_StatusTypeDef USB_DevConnect(USB_TypeDef *USBx);
596 HAL_StatusTypeDef USB_DevDisconnect(USB_TypeDef *USBx);
597 HAL_StatusTypeDef USB_StopDevice(USB_TypeDef *USBx);
598 HAL_StatusTypeDef USB_EP0_OutStart(USB_TypeDef *USBx, uint8_t *psetup);
599 HAL_StatusTypeDef USB_WritePacket(USB_TypeDef *USBx, uint8_t *src,
600                                   uint8_t ch_ep_num, uint16_t len);
601 
602 void             *USB_ReadPacket(USB_TypeDef *USBx, uint8_t *dest, uint16_t len);
603 
604 uint32_t          USB_ReadInterrupts(USB_TypeDef const *USBx);
605 uint32_t          USB_ReadDevAllOutEpInterrupt(USB_TypeDef *USBx);
606 uint32_t          USB_ReadDevOutEPInterrupt(USB_TypeDef *USBx, uint8_t epnum);
607 uint32_t          USB_ReadDevAllInEpInterrupt(USB_TypeDef *USBx);
608 uint32_t          USB_ReadDevInEPInterrupt(USB_TypeDef *USBx, uint8_t epnum);
609 void              USB_ClearInterrupts(USB_TypeDef *USBx, uint32_t interrupt);
610 HAL_StatusTypeDef USB_ActivateRemoteWakeup(USB_TypeDef *USBx);
611 HAL_StatusTypeDef USB_DeActivateRemoteWakeup(USB_TypeDef *USBx);
612 
613 void              USB_WritePMA(USB_TypeDef const *USBx, uint8_t *pbUsrBuf,
614                                uint16_t wPMABufAddr, uint16_t wNBytes);
615 
616 void              USB_ReadPMA(USB_TypeDef const *USBx, uint8_t *pbUsrBuf,
617                               uint16_t wPMABufAddr, uint16_t wNBytes);
618 #endif /* defined (USB) */
619 /**
620   * @}
621   */
622 
623 /**
624   * @}
625   */
626 
627 /**
628   * @}
629   */
630 
631 /**
632   * @}
633   */
634 #endif /* defined (USB) || defined (USB_OTG_FS) */
635 
636 #ifdef __cplusplus
637 }
638 #endif /* __cplusplus */
639 
640 
641 #endif /* STM32L4xx_LL_USB_H */
642