RTEMS 6.1-rc4
Loading...
Searching...
No Matches
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#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
52typedef enum
53{
54 USB_DEVICE_MODE = 0,
55 USB_HOST_MODE = 1,
56 USB_DRD_MODE = 2
57} USB_ModeTypeDef;
58
62typedef 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
75typedef 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
93typedef struct
94{
95 uint8_t dev_endpoints;
99 uint8_t Host_channels;
103 uint8_t dma_enable;
106 uint8_t speed;
110 uint8_t ep0_mps;
112 uint8_t phy_itface;
115 uint8_t Sof_enable;
117 uint8_t low_power_enable;
119 uint8_t lpm_enable;
121 uint8_t battery_charging_enable;
123 uint8_t vbus_sensing_enable;
125 uint8_t use_dedicated_ep1;
127 uint8_t use_external_vbus;
129} USB_CfgTypeDef;
130
131typedef struct
132{
133 uint8_t num;
136 uint8_t is_in;
139 uint8_t is_stall;
142 uint8_t is_iso_incomplete;
145 uint8_t type;
148 uint8_t data_pid_start;
151 uint32_t maxpacket;
154 uint8_t *xfer_buff;
156 uint32_t xfer_len;
158 uint32_t xfer_count;
160 uint8_t even_odd_frame;
163 uint16_t tx_fifo_num;
166 uint32_t dma_addr;
168 uint32_t xfer_size;
169} USB_EPTypeDef;
170
171typedef struct
172{
173 uint8_t dev_addr;
176 uint8_t ch_num;
179 uint8_t ep_num;
182 uint8_t ep_is_in;
185 uint8_t speed;
189 uint8_t do_ping;
190 uint8_t do_ssplit;
191 uint8_t do_csplit;
192 uint8_t ep_ss_schedule;
193 uint32_t iso_splt_xactPos;
195 uint8_t hub_port_nbr;
196 uint8_t hub_addr;
198 uint8_t ep_type;
201 uint16_t max_packet;
204 uint8_t data_pid;
207 uint8_t *xfer_buff;
209 uint32_t XferSize;
211 uint32_t xfer_len;
213 uint32_t xfer_count;
215 uint8_t toggle_in;
218 uint8_t toggle_out;
221 uint32_t dma_addr;
223 uint32_t ErrCnt;
224 uint32_t NyetErrCnt;
226 USB_URBStateTypeDef urb_state;
229 USB_HCStateTypeDef state;
231} USB_HCTypeDef;
232
233typedef USB_ModeTypeDef USB_OTG_ModeTypeDef;
234typedef USB_CfgTypeDef USB_OTG_CfgTypeDef;
235typedef USB_EPTypeDef USB_OTG_EPTypeDef;
236typedef USB_URBStateTypeDef USB_OTG_URBStateTypeDef;
237typedef USB_HCStateTypeDef USB_OTG_HCStateTypeDef;
238typedef USB_HCTypeDef USB_OTG_HCTypeDef;
239
240/* Exported constants --------------------------------------------------------*/
241
247#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
252#define USB_OTG_CORE_ID_300A 0x4F54300AU
253#define USB_OTG_CORE_ID_310A 0x4F54310AU
262#define USB_OTG_MODE_DEVICE 0U
263#define USB_OTG_MODE_HOST 1U
264#define USB_OTG_MODE_DRD 2U
273#define USB_OTG_SPEED_HIGH 0U
274#define USB_OTG_SPEED_HIGH_IN_FULL 1U
275#define USB_OTG_SPEED_FULL 3U
284#define USB_OTG_ULPI_PHY 1U
285#define USB_OTG_EMBEDDED_PHY 2U
294#ifndef USBD_HS_TRDT_VALUE
295#define USBD_HS_TRDT_VALUE 9U
296#endif /* USBD_HS_TRDT_VALUE */
297#ifndef USBD_FS_TRDT_VALUE
298#define USBD_FS_TRDT_VALUE 5U
299#define USBD_DEFAULT_TRDT_VALUE 9U
300#endif /* USBD_HS_TRDT_VALUE */
309#define USB_OTG_HS_MAX_PACKET_SIZE 512U
310#define USB_OTG_FS_MAX_PACKET_SIZE 64U
311#define USB_OTG_MAX_EP0_SIZE 64U
320#define DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ (0U << 1)
321#define DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ (1U << 1)
322#define DSTS_ENUMSPD_FS_PHY_48MHZ (3U << 1)
331#define DCFG_FRAME_INTERVAL_80 0U
332#define DCFG_FRAME_INTERVAL_85 1U
333#define DCFG_FRAME_INTERVAL_90 2U
334#define DCFG_FRAME_INTERVAL_95 3U
338#endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
343#define EP_MPS_64 0U
344#define EP_MPS_32 1U
345#define EP_MPS_16 2U
346#define EP_MPS_8 3U
355#define EP_TYPE_CTRL 0U
356#define EP_TYPE_ISOC 1U
357#define EP_TYPE_BULK 2U
358#define EP_TYPE_INTR 3U
359#define EP_TYPE_MSK 3U
368#define EP_SPEED_LOW 0U
369#define EP_SPEED_FULL 1U
370#define EP_SPEED_HIGH 2U
379#define HC_PID_DATA0 0U
380#define HC_PID_DATA2 1U
381#define HC_PID_DATA1 2U
382#define HC_PID_SETUP 3U
391#define USBD_HS_SPEED 0U
392#define USBD_HSINFS_SPEED 1U
393#define USBH_HS_SPEED 0U
394#define USBD_FS_SPEED 2U
395#define USBH_FSLS_SPEED 1U
400#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
405#define STS_GOUT_NAK 1U
406#define STS_DATA_UPDT 2U
407#define STS_XFER_COMP 3U
408#define STS_SETUP_COMP 4U
409#define STS_SETUP_UPDT 6U
418#define HCFG_30_60_MHZ 0U
419#define HCFG_48_MHZ 1U
420#define HCFG_6_MHZ 2U
429#define HFIR_6_MHZ 6000U
430#define HFIR_60_MHZ 60000U
431#define HFIR_48_MHZ 48000U
440#define HPRT0_PRTSPD_HIGH_SPEED 0U
441#define HPRT0_PRTSPD_FULL_SPEED 1U
442#define HPRT0_PRTSPD_LOW_SPEED 2U
447#define HCCHAR_CTRL 0U
448#define HCCHAR_ISOC 1U
449#define HCCHAR_BULK 2U
450#define HCCHAR_INTR 3U
451
452#define GRXSTS_PKTSTS_IN 2U
453#define GRXSTS_PKTSTS_IN_XFER_COMP 3U
454#define GRXSTS_PKTSTS_DATA_TOGGLE_ERR 5U
455#define GRXSTS_PKTSTS_CH_HALTED 7U
456
457#define CLEAR_INTERRUPT_MASK 0xFFFFFFFFU
458
459#define HC_MAX_PKT_CNT 256U
460#define ISO_SPLT_MPS 188U
461
462#define HCSPLT_BEGIN 1U
463#define HCSPLT_MIDDLE 2U
464#define HCSPLT_END 3U
465#define HCSPLT_FULL 4U
466
467#define TEST_J 1U
468#define TEST_K 2U
469#define TEST_SE0_NAK 3U
470#define TEST_PACKET 4U
471#define TEST_FORCE_EN 5U
472
473#define USBx_PCGCCTL *(__IO uint32_t *)((uint32_t)USBx_BASE + USB_OTG_PCGCCTL_BASE)
474#define USBx_HPRT0 *(__IO uint32_t *)((uint32_t)USBx_BASE + USB_OTG_HOST_PORT_BASE)
475
476#define USBx_DEVICE ((USB_OTG_DeviceTypeDef *)(USBx_BASE + USB_OTG_DEVICE_BASE))
477#define USBx_INEP(i) ((USB_OTG_INEndpointTypeDef *)(USBx_BASE\
478 + USB_OTG_IN_ENDPOINT_BASE + ((i) * USB_OTG_EP_REG_SIZE)))
479
480#define USBx_OUTEP(i) ((USB_OTG_OUTEndpointTypeDef *)(USBx_BASE\
481 + USB_OTG_OUT_ENDPOINT_BASE + ((i) * USB_OTG_EP_REG_SIZE)))
482
483#define USBx_DFIFO(i) *(__IO uint32_t *)(USBx_BASE + USB_OTG_FIFO_BASE + ((i) * USB_OTG_FIFO_SIZE))
484
485#define USBx_HOST ((USB_OTG_HostTypeDef *)(USBx_BASE + USB_OTG_HOST_BASE))
486#define USBx_HC(i) ((USB_OTG_HostChannelTypeDef *)(USBx_BASE\
487 + USB_OTG_HOST_CHANNEL_BASE\
488 + ((i) * USB_OTG_HOST_CHANNEL_SIZE)))
489
490
491#define EP_ADDR_MSK 0xFU
492#endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
497/* Exported macro ------------------------------------------------------------*/
502#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
503#define USB_MASK_INTERRUPT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->GINTMSK &= ~(__INTERRUPT__))
504#define USB_UNMASK_INTERRUPT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->GINTMSK |= (__INTERRUPT__))
505
506#define CLEAR_IN_EP_INTR(__EPNUM__, __INTERRUPT__) (USBx_INEP(__EPNUM__)->DIEPINT = (__INTERRUPT__))
507#define CLEAR_OUT_EP_INTR(__EPNUM__, __INTERRUPT__) (USBx_OUTEP(__EPNUM__)->DOEPINT = (__INTERRUPT__))
508#endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
513/* Exported functions --------------------------------------------------------*/
517#if defined (USB_OTG_FS) || defined (USB_OTG_HS)
518HAL_StatusTypeDef USB_CoreInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg);
519HAL_StatusTypeDef USB_DevInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg);
520HAL_StatusTypeDef USB_EnableGlobalInt(USB_OTG_GlobalTypeDef *USBx);
521HAL_StatusTypeDef USB_DisableGlobalInt(USB_OTG_GlobalTypeDef *USBx);
522HAL_StatusTypeDef USB_SetTurnaroundTime(USB_OTG_GlobalTypeDef *USBx, uint32_t hclk, uint8_t speed);
523HAL_StatusTypeDef USB_SetCurrentMode(USB_OTG_GlobalTypeDef *USBx, USB_OTG_ModeTypeDef mode);
524HAL_StatusTypeDef USB_SetDevSpeed(const USB_OTG_GlobalTypeDef *USBx, uint8_t speed);
525HAL_StatusTypeDef USB_FlushRxFifo(USB_OTG_GlobalTypeDef *USBx);
526HAL_StatusTypeDef USB_FlushTxFifo(USB_OTG_GlobalTypeDef *USBx, uint32_t num);
527HAL_StatusTypeDef USB_ActivateEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep);
528HAL_StatusTypeDef USB_DeactivateEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep);
529HAL_StatusTypeDef USB_ActivateDedicatedEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep);
530HAL_StatusTypeDef USB_DeactivateDedicatedEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep);
531HAL_StatusTypeDef USB_EPStartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep, uint8_t dma);
532HAL_StatusTypeDef USB_WritePacket(const USB_OTG_GlobalTypeDef *USBx, uint8_t *src,
533 uint8_t ch_ep_num, uint16_t len, uint8_t dma);
534
535void *USB_ReadPacket(const USB_OTG_GlobalTypeDef *USBx, uint8_t *dest, uint16_t len);
536HAL_StatusTypeDef USB_EPSetStall(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep);
537HAL_StatusTypeDef USB_EPClearStall(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep);
538HAL_StatusTypeDef USB_EPStopXfer(const USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep);
539HAL_StatusTypeDef USB_SetDevAddress(const USB_OTG_GlobalTypeDef *USBx, uint8_t address);
540HAL_StatusTypeDef USB_DevConnect(const USB_OTG_GlobalTypeDef *USBx);
541HAL_StatusTypeDef USB_DevDisconnect(const USB_OTG_GlobalTypeDef *USBx);
542HAL_StatusTypeDef USB_StopDevice(USB_OTG_GlobalTypeDef *USBx);
543HAL_StatusTypeDef USB_ActivateSetup(const USB_OTG_GlobalTypeDef *USBx);
544HAL_StatusTypeDef USB_EP0_OutStart(const USB_OTG_GlobalTypeDef *USBx, uint8_t dma, const uint8_t *psetup);
545uint8_t USB_GetDevSpeed(const USB_OTG_GlobalTypeDef *USBx);
546uint32_t USB_GetMode(const USB_OTG_GlobalTypeDef *USBx);
547uint32_t USB_ReadInterrupts(USB_OTG_GlobalTypeDef const *USBx);
548uint32_t USB_ReadChInterrupts(const USB_OTG_GlobalTypeDef *USBx, uint8_t chnum);
549uint32_t USB_ReadDevAllOutEpInterrupt(const USB_OTG_GlobalTypeDef *USBx);
550uint32_t USB_ReadDevOutEPInterrupt(const USB_OTG_GlobalTypeDef *USBx, uint8_t epnum);
551uint32_t USB_ReadDevAllInEpInterrupt(const USB_OTG_GlobalTypeDef *USBx);
552uint32_t USB_ReadDevInEPInterrupt(const USB_OTG_GlobalTypeDef *USBx, uint8_t epnum);
553void USB_ClearInterrupts(USB_OTG_GlobalTypeDef *USBx, uint32_t interrupt);
554
555HAL_StatusTypeDef USB_HostInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg);
556HAL_StatusTypeDef USB_InitFSLSPClkSel(const USB_OTG_GlobalTypeDef *USBx, uint8_t freq);
557HAL_StatusTypeDef USB_ResetPort(const USB_OTG_GlobalTypeDef *USBx);
558HAL_StatusTypeDef USB_DriveVbus(const USB_OTG_GlobalTypeDef *USBx, uint8_t state);
559uint32_t USB_GetHostSpeed(USB_OTG_GlobalTypeDef const *USBx);
560uint32_t USB_GetCurrentFrame(USB_OTG_GlobalTypeDef const *USBx);
561HAL_StatusTypeDef USB_HC_Init(USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num,
562 uint8_t epnum, uint8_t dev_address, uint8_t speed,
563 uint8_t ep_type, uint16_t mps);
564HAL_StatusTypeDef USB_HC_StartXfer(USB_OTG_GlobalTypeDef *USBx,
565 USB_OTG_HCTypeDef *hc, uint8_t dma);
566
567uint32_t USB_HC_ReadInterrupt(const USB_OTG_GlobalTypeDef *USBx);
568HAL_StatusTypeDef USB_HC_Halt(const USB_OTG_GlobalTypeDef *USBx, uint8_t hc_num);
569HAL_StatusTypeDef USB_DoPing(const USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num);
570HAL_StatusTypeDef USB_StopHost(USB_OTG_GlobalTypeDef *USBx);
571HAL_StatusTypeDef USB_ActivateRemoteWakeup(const USB_OTG_GlobalTypeDef *USBx);
572HAL_StatusTypeDef USB_DeActivateRemoteWakeup(const USB_OTG_GlobalTypeDef *USBx);
573#endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
574
590#endif /* defined (USB_OTG_FS) || defined (USB_OTG_HS) */
591
592#ifdef __cplusplus
593}
594#endif /* __cplusplus */
595
596
597#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