RTEMS 6.1-rc1
stm32h7xx_ll_usb.h
Go to the documentation of this file.
1
19/* Define to prevent recursive inclusion -------------------------------------*/
20#ifndef STM32H7xx_LL_USB_H
21#define STM32H7xx_LL_USB_H
22
23#ifdef __cplusplus
24extern "C" {
25#endif /* __cplusplus */
26
27/* Includes ------------------------------------------------------------------*/
28#include "stm32h7xx_hal_def.h"
29
30#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
39/* Exported types ------------------------------------------------------------*/
40
45typedef enum
46{
47 USB_DEVICE_MODE = 0,
48 USB_HOST_MODE = 1,
49 USB_DRD_MODE = 2
50} USB_ModeTypeDef;
51
55typedef enum
56{
57 URB_IDLE = 0,
58 URB_DONE,
59 URB_NOTREADY,
60 URB_NYET,
61 URB_ERROR,
62 URB_STALL
63} USB_URBStateTypeDef;
64
68typedef enum
69{
70 HC_IDLE = 0,
71 HC_XFRC,
72 HC_HALTED,
73 HC_ACK,
74 HC_NAK,
75 HC_NYET,
76 HC_STALL,
77 HC_XACTERR,
78 HC_BBLERR,
79 HC_DATATGLERR
80} USB_HCStateTypeDef;
81
82
86typedef struct
87{
88 uint32_t dev_endpoints;
92 uint32_t Host_channels;
96 uint32_t dma_enable;
98 uint32_t speed;
102 uint32_t ep0_mps;
104 uint32_t phy_itface;
107 uint32_t Sof_enable;
109 uint32_t low_power_enable;
111 uint32_t lpm_enable;
113 uint32_t battery_charging_enable;
115 uint32_t vbus_sensing_enable;
117 uint32_t use_dedicated_ep1;
119 uint32_t use_external_vbus;
121} USB_CfgTypeDef;
122
123typedef struct
124{
125 uint8_t num;
128 uint8_t is_in;
131 uint8_t is_stall;
134 uint8_t is_iso_incomplete;
137 uint8_t type;
140 uint8_t data_pid_start;
143 uint32_t maxpacket;
146 uint8_t *xfer_buff;
148 uint32_t xfer_len;
150 uint32_t xfer_count;
152 uint8_t even_odd_frame;
155 uint16_t tx_fifo_num;
158 uint32_t dma_addr;
160 uint32_t xfer_size;
161} USB_EPTypeDef;
162
163typedef struct
164{
165 uint8_t dev_addr;
168 uint8_t ch_num;
171 uint8_t ep_num;
174 uint8_t ep_is_in;
177 uint8_t speed;
181 uint8_t do_ping;
183 uint8_t process_ping;
185 uint8_t ep_type;
188 uint16_t max_packet;
191 uint8_t data_pid;
194 uint8_t *xfer_buff;
196 uint32_t XferSize;
198 uint32_t xfer_len;
200 uint32_t xfer_count;
202 uint8_t toggle_in;
205 uint8_t toggle_out;
208 uint32_t dma_addr;
210 uint32_t ErrCnt;
212 USB_URBStateTypeDef urb_state;
215 USB_HCStateTypeDef state;
217} USB_HCTypeDef;
218
219typedef USB_ModeTypeDef USB_OTG_ModeTypeDef;
220typedef USB_CfgTypeDef USB_OTG_CfgTypeDef;
221typedef USB_EPTypeDef USB_OTG_EPTypeDef;
222typedef USB_URBStateTypeDef USB_OTG_URBStateTypeDef;
223typedef USB_HCStateTypeDef USB_OTG_HCStateTypeDef;
224typedef USB_HCTypeDef USB_OTG_HCTypeDef;
225
226/* Exported constants --------------------------------------------------------*/
227
233#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
238#define USB_OTG_CORE_ID_300A 0x4F54300AU
239#define USB_OTG_CORE_ID_310A 0x4F54310AU
248#define USB_OTG_MODE_DEVICE 0U
249#define USB_OTG_MODE_HOST 1U
250#define USB_OTG_MODE_DRD 2U
259#define USB_OTG_SPEED_HIGH 0U
260#define USB_OTG_SPEED_HIGH_IN_FULL 1U
261#define USB_OTG_SPEED_FULL 3U
270#define USB_OTG_ULPI_PHY 1U
271#define USB_OTG_EMBEDDED_PHY 2U
280#ifndef USBD_HS_TRDT_VALUE
281#define USBD_HS_TRDT_VALUE 9U
282#endif /* USBD_HS_TRDT_VALUE */
283#ifndef USBD_FS_TRDT_VALUE
284#define USBD_FS_TRDT_VALUE 5U
285#define USBD_DEFAULT_TRDT_VALUE 9U
286#endif /* USBD_HS_TRDT_VALUE */
295#define USB_OTG_HS_MAX_PACKET_SIZE 512U
296#define USB_OTG_FS_MAX_PACKET_SIZE 64U
297#define USB_OTG_MAX_EP0_SIZE 64U
306#define DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ (0U << 1)
307#define DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ (1U << 1)
308#define DSTS_ENUMSPD_FS_PHY_48MHZ (3U << 1)
317#define DCFG_FRAME_INTERVAL_80 0U
318#define DCFG_FRAME_INTERVAL_85 1U
319#define DCFG_FRAME_INTERVAL_90 2U
320#define DCFG_FRAME_INTERVAL_95 3U
324#endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
329#define EP_MPS_64 0U
330#define EP_MPS_32 1U
331#define EP_MPS_16 2U
332#define EP_MPS_8 3U
341#define EP_TYPE_CTRL 0U
342#define EP_TYPE_ISOC 1U
343#define EP_TYPE_BULK 2U
344#define EP_TYPE_INTR 3U
345#define EP_TYPE_MSK 3U
354#define EP_SPEED_LOW 0U
355#define EP_SPEED_FULL 1U
356#define EP_SPEED_HIGH 2U
365#define HC_PID_DATA0 0U
366#define HC_PID_DATA2 1U
367#define HC_PID_DATA1 2U
368#define HC_PID_SETUP 3U
377#define USBD_HS_SPEED 0U
378#define USBD_HSINFS_SPEED 1U
379#define USBH_HS_SPEED 0U
380#define USBD_FS_SPEED 2U
381#define USBH_FSLS_SPEED 1U
386#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
391#define STS_GOUT_NAK 1U
392#define STS_DATA_UPDT 2U
393#define STS_XFER_COMP 3U
394#define STS_SETUP_COMP 4U
395#define STS_SETUP_UPDT 6U
404#define HCFG_30_60_MHZ 0U
405#define HCFG_48_MHZ 1U
406#define HCFG_6_MHZ 2U
415#define HFIR_6_MHZ 6000U
416#define HFIR_60_MHZ 60000U
417#define HFIR_48_MHZ 48000U
426#define HPRT0_PRTSPD_HIGH_SPEED 0U
427#define HPRT0_PRTSPD_FULL_SPEED 1U
428#define HPRT0_PRTSPD_LOW_SPEED 2U
433#define HCCHAR_CTRL 0U
434#define HCCHAR_ISOC 1U
435#define HCCHAR_BULK 2U
436#define HCCHAR_INTR 3U
437
438#define GRXSTS_PKTSTS_IN 2U
439#define GRXSTS_PKTSTS_IN_XFER_COMP 3U
440#define GRXSTS_PKTSTS_DATA_TOGGLE_ERR 5U
441#define GRXSTS_PKTSTS_CH_HALTED 7U
442
443#define CLEAR_INTERRUPT_MASK 0xFFFFFFFFU
444
445#define HC_MAX_PKT_CNT 256U
446
447#define TEST_J 1U
448#define TEST_K 2U
449#define TEST_SE0_NAK 3U
450#define TEST_PACKET 4U
451#define TEST_FORCE_EN 5U
452
453#define USBx_PCGCCTL *(__IO uint32_t *)((uint32_t)USBx_BASE + USB_OTG_PCGCCTL_BASE)
454#define USBx_HPRT0 *(__IO uint32_t *)((uint32_t)USBx_BASE + USB_OTG_HOST_PORT_BASE)
455
456#define USBx_DEVICE ((USB_OTG_DeviceTypeDef *)(USBx_BASE + USB_OTG_DEVICE_BASE))
457#define USBx_INEP(i) ((USB_OTG_INEndpointTypeDef *)(USBx_BASE\
458 + USB_OTG_IN_ENDPOINT_BASE + ((i) * USB_OTG_EP_REG_SIZE)))
459
460#define USBx_OUTEP(i) ((USB_OTG_OUTEndpointTypeDef *)(USBx_BASE\
461 + USB_OTG_OUT_ENDPOINT_BASE + ((i) * USB_OTG_EP_REG_SIZE)))
462
463#define USBx_DFIFO(i) *(__IO uint32_t *)(USBx_BASE + USB_OTG_FIFO_BASE + ((i) * USB_OTG_FIFO_SIZE))
464
465#define USBx_HOST ((USB_OTG_HostTypeDef *)(USBx_BASE + USB_OTG_HOST_BASE))
466#define USBx_HC(i) ((USB_OTG_HostChannelTypeDef *)(USBx_BASE\
467 + USB_OTG_HOST_CHANNEL_BASE\
468 + ((i) * USB_OTG_HOST_CHANNEL_SIZE)))
469
470
471#define EP_ADDR_MSK 0xFU
472#endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
477/* Exported macro ------------------------------------------------------------*/
482#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
483#define USB_MASK_INTERRUPT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->GINTMSK &= ~(__INTERRUPT__))
484#define USB_UNMASK_INTERRUPT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->GINTMSK |= (__INTERRUPT__))
485
486#define CLEAR_IN_EP_INTR(__EPNUM__, __INTERRUPT__) (USBx_INEP(__EPNUM__)->DIEPINT = (__INTERRUPT__))
487#define CLEAR_OUT_EP_INTR(__EPNUM__, __INTERRUPT__) (USBx_OUTEP(__EPNUM__)->DOEPINT = (__INTERRUPT__))
488#endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
493/* Exported functions --------------------------------------------------------*/
497#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
498HAL_StatusTypeDef USB_CoreInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg);
499HAL_StatusTypeDef USB_DevInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg);
500HAL_StatusTypeDef USB_EnableGlobalInt(USB_OTG_GlobalTypeDef *USBx);
501HAL_StatusTypeDef USB_DisableGlobalInt(USB_OTG_GlobalTypeDef *USBx);
502HAL_StatusTypeDef USB_SetTurnaroundTime(USB_OTG_GlobalTypeDef *USBx, uint32_t hclk, uint8_t speed);
503HAL_StatusTypeDef USB_SetCurrentMode(USB_OTG_GlobalTypeDef *USBx, USB_OTG_ModeTypeDef mode);
504HAL_StatusTypeDef USB_SetDevSpeed(USB_OTG_GlobalTypeDef *USBx, uint8_t speed);
505HAL_StatusTypeDef USB_FlushRxFifo(USB_OTG_GlobalTypeDef *USBx);
506HAL_StatusTypeDef USB_FlushTxFifo(USB_OTG_GlobalTypeDef *USBx, uint32_t num);
507HAL_StatusTypeDef USB_ActivateEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep);
508HAL_StatusTypeDef USB_DeactivateEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep);
509HAL_StatusTypeDef USB_ActivateDedicatedEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep);
510HAL_StatusTypeDef USB_DeactivateDedicatedEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep);
511HAL_StatusTypeDef USB_EPStartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep, uint8_t dma);
512HAL_StatusTypeDef USB_WritePacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *src,
513 uint8_t ch_ep_num, uint16_t len, uint8_t dma);
514
515void *USB_ReadPacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *dest, uint16_t len);
516HAL_StatusTypeDef USB_EPSetStall(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep);
517HAL_StatusTypeDef USB_EPClearStall(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep);
518HAL_StatusTypeDef USB_EPStopXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep);
519HAL_StatusTypeDef USB_SetDevAddress(USB_OTG_GlobalTypeDef *USBx, uint8_t address);
520HAL_StatusTypeDef USB_DevConnect(USB_OTG_GlobalTypeDef *USBx);
521HAL_StatusTypeDef USB_DevDisconnect(USB_OTG_GlobalTypeDef *USBx);
522HAL_StatusTypeDef USB_StopDevice(USB_OTG_GlobalTypeDef *USBx);
523HAL_StatusTypeDef USB_ActivateSetup(USB_OTG_GlobalTypeDef *USBx);
524HAL_StatusTypeDef USB_EP0_OutStart(USB_OTG_GlobalTypeDef *USBx, uint8_t dma, uint8_t *psetup);
525uint8_t USB_GetDevSpeed(USB_OTG_GlobalTypeDef *USBx);
526uint32_t USB_GetMode(USB_OTG_GlobalTypeDef *USBx);
527uint32_t USB_ReadInterrupts(USB_OTG_GlobalTypeDef *USBx);
528uint32_t USB_ReadChInterrupts(USB_OTG_GlobalTypeDef *USBx, uint8_t chnum);
529uint32_t USB_ReadDevAllOutEpInterrupt(USB_OTG_GlobalTypeDef *USBx);
530uint32_t USB_ReadDevOutEPInterrupt(USB_OTG_GlobalTypeDef *USBx, uint8_t epnum);
531uint32_t USB_ReadDevAllInEpInterrupt(USB_OTG_GlobalTypeDef *USBx);
532uint32_t USB_ReadDevInEPInterrupt(USB_OTG_GlobalTypeDef *USBx, uint8_t epnum);
533void USB_ClearInterrupts(USB_OTG_GlobalTypeDef *USBx, uint32_t interrupt);
534
535HAL_StatusTypeDef USB_HostInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg);
536HAL_StatusTypeDef USB_InitFSLSPClkSel(USB_OTG_GlobalTypeDef *USBx, uint8_t freq);
537HAL_StatusTypeDef USB_ResetPort(USB_OTG_GlobalTypeDef *USBx);
538HAL_StatusTypeDef USB_DriveVbus(USB_OTG_GlobalTypeDef *USBx, uint8_t state);
539uint32_t USB_GetHostSpeed(USB_OTG_GlobalTypeDef *USBx);
540uint32_t USB_GetCurrentFrame(USB_OTG_GlobalTypeDef *USBx);
541HAL_StatusTypeDef USB_HC_Init(USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num,
542 uint8_t epnum, uint8_t dev_address, uint8_t speed,
543 uint8_t ep_type, uint16_t mps);
544HAL_StatusTypeDef USB_HC_StartXfer(USB_OTG_GlobalTypeDef *USBx,
545 USB_OTG_HCTypeDef *hc, uint8_t dma);
546
547uint32_t USB_HC_ReadInterrupt(USB_OTG_GlobalTypeDef *USBx);
548HAL_StatusTypeDef USB_HC_Halt(USB_OTG_GlobalTypeDef *USBx, uint8_t hc_num);
549HAL_StatusTypeDef USB_DoPing(USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num);
550HAL_StatusTypeDef USB_StopHost(USB_OTG_GlobalTypeDef *USBx);
551HAL_StatusTypeDef USB_ActivateRemoteWakeup(USB_OTG_GlobalTypeDef *USBx);
552HAL_StatusTypeDef USB_DeActivateRemoteWakeup(USB_OTG_GlobalTypeDef *USBx);
553#endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
554
570#endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
571
572#ifdef __cplusplus
573}
574#endif /* __cplusplus */
575
576
577#endif /* STM32H7xx_LL_USB_H */
This file contains HAL common defines, enumeration, macros and structures definitions.
HAL_StatusTypeDef
HAL Status structures definition.
Definition: stm32h7xx_hal_def.h:47
USB_OTG_Core_Registers.
Definition: stm32h723xx.h:1761