20 #ifndef STM32F4xx_LL_USB_H
21 #define STM32F4xx_LL_USB_H
30 #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
40 #ifndef HAL_USB_TIMEOUT
41 #define HAL_USB_TIMEOUT 0xF000000U
44 #ifndef HAL_USB_CURRENT_MODE_MAX_DELAY_MS
45 #define HAL_USB_CURRENT_MODE_MAX_DELAY_MS 200U
246 #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
250 #define USB_OTG_CORE_ID_300A 0x4F54300AU
251 #define USB_OTG_CORE_ID_310A 0x4F54310AU
259 #define USB_OTG_MODE_DEVICE 0U
260 #define USB_OTG_MODE_HOST 1U
261 #define USB_OTG_MODE_DRD 2U
269 #define USB_OTG_SPEED_HIGH 0U
270 #define USB_OTG_SPEED_HIGH_IN_FULL 1U
271 #define USB_OTG_SPEED_FULL 3U
279 #define USB_OTG_ULPI_PHY 1U
280 #define USB_OTG_EMBEDDED_PHY 2U
288 #ifndef USBD_HS_TRDT_VALUE
289 #define USBD_HS_TRDT_VALUE 9U
291 #ifndef USBD_FS_TRDT_VALUE
292 #define USBD_FS_TRDT_VALUE 5U
293 #define USBD_DEFAULT_TRDT_VALUE 9U
302 #define USB_OTG_HS_MAX_PACKET_SIZE 512U
303 #define USB_OTG_FS_MAX_PACKET_SIZE 64U
304 #define USB_OTG_MAX_EP0_SIZE 64U
312 #define DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ (0U << 1)
313 #define DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ (1U << 1)
314 #define DSTS_ENUMSPD_FS_PHY_48MHZ (3U << 1)
322 #define DCFG_FRAME_INTERVAL_80 0U
323 #define DCFG_FRAME_INTERVAL_85 1U
324 #define DCFG_FRAME_INTERVAL_90 2U
325 #define DCFG_FRAME_INTERVAL_95 3U
344 #define EP_TYPE_CTRL 0U
345 #define EP_TYPE_ISOC 1U
346 #define EP_TYPE_BULK 2U
347 #define EP_TYPE_INTR 3U
348 #define EP_TYPE_MSK 3U
356 #define EP_SPEED_LOW 0U
357 #define EP_SPEED_FULL 1U
358 #define EP_SPEED_HIGH 2U
366 #define HC_PID_DATA0 0U
367 #define HC_PID_DATA2 1U
368 #define HC_PID_DATA1 2U
369 #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)
390 #define STS_GOUT_NAK 1U
391 #define STS_DATA_UPDT 2U
392 #define STS_XFER_COMP 3U
393 #define STS_SETUP_COMP 4U
394 #define STS_SETUP_UPDT 6U
402 #define HCFG_30_60_MHZ 0U
403 #define HCFG_48_MHZ 1U
404 #define HCFG_6_MHZ 2U
412 #define HFIR_6_MHZ 6000U
413 #define HFIR_60_MHZ 60000U
414 #define HFIR_48_MHZ 48000U
422 #define HPRT0_PRTSPD_HIGH_SPEED 0U
423 #define HPRT0_PRTSPD_FULL_SPEED 1U
424 #define HPRT0_PRTSPD_LOW_SPEED 2U
429 #define HCCHAR_CTRL 0U
430 #define HCCHAR_ISOC 1U
431 #define HCCHAR_BULK 2U
432 #define HCCHAR_INTR 3U
434 #define GRXSTS_PKTSTS_IN 2U
435 #define GRXSTS_PKTSTS_IN_XFER_COMP 3U
436 #define GRXSTS_PKTSTS_DATA_TOGGLE_ERR 5U
437 #define GRXSTS_PKTSTS_CH_HALTED 7U
439 #define CLEAR_INTERRUPT_MASK 0xFFFFFFFFU
441 #define HC_MAX_PKT_CNT 256U
442 #define ISO_SPLT_MPS 188U
444 #define HCSPLT_BEGIN 1U
445 #define HCSPLT_MIDDLE 2U
446 #define HCSPLT_END 3U
447 #define HCSPLT_FULL 4U
451 #define TEST_SE0_NAK 3U
452 #define TEST_PACKET 4U
453 #define TEST_FORCE_EN 5U
455 #define USBx_PCGCCTL *(__IO uint32_t *)((uint32_t)USBx_BASE + USB_OTG_PCGCCTL_BASE)
456 #define USBx_HPRT0 *(__IO uint32_t *)((uint32_t)USBx_BASE + USB_OTG_HOST_PORT_BASE)
458 #define USBx_DEVICE ((USB_OTG_DeviceTypeDef *)(USBx_BASE + USB_OTG_DEVICE_BASE))
459 #define USBx_INEP(i) ((USB_OTG_INEndpointTypeDef *)(USBx_BASE\
460 + USB_OTG_IN_ENDPOINT_BASE + ((i) * USB_OTG_EP_REG_SIZE)))
462 #define USBx_OUTEP(i) ((USB_OTG_OUTEndpointTypeDef *)(USBx_BASE\
463 + USB_OTG_OUT_ENDPOINT_BASE + ((i) * USB_OTG_EP_REG_SIZE)))
465 #define USBx_DFIFO(i) *(__IO uint32_t *)(USBx_BASE + USB_OTG_FIFO_BASE + ((i) * USB_OTG_FIFO_SIZE))
467 #define USBx_HOST ((USB_OTG_HostTypeDef *)(USBx_BASE + USB_OTG_HOST_BASE))
468 #define USBx_HC(i) ((USB_OTG_HostChannelTypeDef *)(USBx_BASE\
469 + USB_OTG_HOST_CHANNEL_BASE\
470 + ((i) * USB_OTG_HOST_CHANNEL_SIZE)))
473 #define EP_ADDR_MSK 0xFU
483 #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
484 #define USB_MASK_INTERRUPT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->GINTMSK &= ~(__INTERRUPT__))
485 #define USB_UNMASK_INTERRUPT(__INSTANCE__, __INTERRUPT__) ((__INSTANCE__)->GINTMSK |= (__INTERRUPT__))
487 #define CLEAR_IN_EP_INTR(__EPNUM__, __INTERRUPT__) (USBx_INEP(__EPNUM__)->DIEPINT = (__INTERRUPT__))
488 #define CLEAR_OUT_EP_INTR(__EPNUM__, __INTERRUPT__) (USBx_OUTEP(__EPNUM__)->DOEPINT = (__INTERRUPT__))
498 #if defined (USB_OTG_FS) || defined (USB_OTG_HS)
505 HAL_StatusTypeDef
USB_SetDevSpeed(
const USB_OTG_GlobalTypeDef *USBx, uint8_t speed);
507 HAL_StatusTypeDef
USB_FlushTxFifo(USB_OTG_GlobalTypeDef *USBx, uint32_t num);
513 HAL_StatusTypeDef
USB_WritePacket(
const USB_OTG_GlobalTypeDef *USBx, uint8_t *src,
514 uint8_t ch_ep_num, uint16_t len, uint8_t dma);
516 void *
USB_ReadPacket(
const USB_OTG_GlobalTypeDef *USBx, uint8_t *dest, uint16_t len);
520 HAL_StatusTypeDef
USB_SetDevAddress(
const USB_OTG_GlobalTypeDef *USBx, uint8_t address);
521 HAL_StatusTypeDef
USB_DevConnect(
const USB_OTG_GlobalTypeDef *USBx);
525 HAL_StatusTypeDef
USB_EP0_OutStart(
const USB_OTG_GlobalTypeDef *USBx, uint8_t dma,
const uint8_t *psetup);
527 uint32_t
USB_GetMode(
const USB_OTG_GlobalTypeDef *USBx);
538 HAL_StatusTypeDef
USB_ResetPort(
const USB_OTG_GlobalTypeDef *USBx);
539 HAL_StatusTypeDef
USB_DriveVbus(
const USB_OTG_GlobalTypeDef *USBx, uint8_t state);
542 HAL_StatusTypeDef
USB_HC_Init(USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num,
543 uint8_t epnum, uint8_t dev_address, uint8_t speed,
544 uint8_t ep_type, uint16_t mps);
549 HAL_StatusTypeDef
USB_HC_Halt(
const USB_OTG_GlobalTypeDef *USBx, uint8_t hc_num);
550 HAL_StatusTypeDef
USB_DoPing(
const USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num);
551 HAL_StatusTypeDef
USB_StopHost(USB_OTG_GlobalTypeDef *USBx);
uint32_t USB_GetMode(const USB_OTG_GlobalTypeDef *USBx)
Returns USB core mode.
HAL_StatusTypeDef USB_WritePacket(const USB_OTG_GlobalTypeDef *USBx, uint8_t *src, uint8_t ch_ep_num, uint16_t len, uint8_t dma)
USB_WritePacket : Writes a packet into the Tx FIFO associated with the EP/channel.
uint32_t USB_GetHostSpeed(USB_OTG_GlobalTypeDef const *USBx)
Return Host Core speed.
HAL_StatusTypeDef USB_ResetPort(const USB_OTG_GlobalTypeDef *USBx)
USB_OTG_ResetPort : Reset Host Port.
uint32_t USB_ReadDevOutEPInterrupt(const USB_OTG_GlobalTypeDef *USBx, uint8_t epnum)
Returns Device OUT EP Interrupt register.
uint32_t USB_HC_ReadInterrupt(const USB_OTG_GlobalTypeDef *USBx)
Read all host channel interrupts status.
void * USB_ReadPacket(const USB_OTG_GlobalTypeDef *USBx, uint8_t *dest, uint16_t len)
USB_ReadPacket : read a packet from the RX FIFO.
HAL_StatusTypeDef USB_HC_Init(USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num, uint8_t epnum, uint8_t dev_address, uint8_t speed, uint8_t ep_type, uint16_t mps)
Initialize a host channel.
HAL_StatusTypeDef USB_ActivateEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep)
Activate and configure an endpoint.
HAL_StatusTypeDef USB_DoPing(const USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num)
Initiate Do Ping protocol.
uint32_t USB_ReadChInterrupts(const USB_OTG_GlobalTypeDef *USBx, uint8_t chnum)
USB_ReadChInterrupts: return USB channel interrupt status.
uint8_t USB_GetDevSpeed(const USB_OTG_GlobalTypeDef *USBx)
USB_GetDevSpeed Return the Dev Speed.
uint32_t USB_ReadDevAllInEpInterrupt(const USB_OTG_GlobalTypeDef *USBx)
USB_ReadDevAllInEpInterrupt: return the USB device IN endpoints interrupt status.
HAL_StatusTypeDef USB_CoreInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg)
Initializes the USB Core.
HAL_StatusTypeDef USB_HC_Halt(const USB_OTG_GlobalTypeDef *USBx, uint8_t hc_num)
Halt a host channel.
HAL_StatusTypeDef USB_HostInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg)
USB_HostInit : Initializes the USB OTG controller registers for Host mode.
HAL_StatusTypeDef USB_HC_StartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_HCTypeDef *hc, uint8_t dma)
Start a transfer over a host channel.
HAL_StatusTypeDef USB_DeactivateDedicatedEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep)
De-activate and de-initialize a dedicated endpoint.
HAL_StatusTypeDef USB_ActivateSetup(const USB_OTG_GlobalTypeDef *USBx)
Activate EP0 for Setup transactions.
HAL_StatusTypeDef USB_SetCurrentMode(USB_OTG_GlobalTypeDef *USBx, USB_OTG_ModeTypeDef mode)
USB_SetCurrentMode Set functional mode.
HAL_StatusTypeDef USB_DeactivateEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep)
De-activate and de-initialize an endpoint.
HAL_StatusTypeDef USB_EPClearStall(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep)
USB_EPClearStall : Clear a stall condition over an EP.
HAL_StatusTypeDef USB_SetTurnaroundTime(USB_OTG_GlobalTypeDef *USBx, uint32_t hclk, uint8_t speed)
Set the USB turnaround time.
HAL_StatusTypeDef USB_EPStartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep, uint8_t dma)
USB_EPStartXfer : setup and starts a transfer over an EP.
uint32_t USB_ReadDevAllOutEpInterrupt(const USB_OTG_GlobalTypeDef *USBx)
USB_ReadDevAllOutEpInterrupt: return the USB device OUT endpoints interrupt status.
HAL_StatusTypeDef USB_DriveVbus(const USB_OTG_GlobalTypeDef *USBx, uint8_t state)
USB_DriveVbus : activate or de-activate vbus.
HAL_StatusTypeDef USB_ActivateDedicatedEndpoint(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep)
Activate and configure a dedicated endpoint.
HAL_StatusTypeDef USB_EPSetStall(const USB_OTG_GlobalTypeDef *USBx, const USB_OTG_EPTypeDef *ep)
USB_EPSetStall : set a stall condition over an EP.
HAL_StatusTypeDef USB_DisableGlobalInt(USB_OTG_GlobalTypeDef *USBx)
USB_DisableGlobalInt Disable the controller's Global Int in the AHB Config reg.
HAL_StatusTypeDef USB_StopDevice(USB_OTG_GlobalTypeDef *USBx)
USB_StopDevice : Stop the usb device mode.
uint32_t USB_ReadDevInEPInterrupt(const USB_OTG_GlobalTypeDef *USBx, uint8_t epnum)
Returns Device IN EP Interrupt register.
HAL_StatusTypeDef USB_SetDevSpeed(const USB_OTG_GlobalTypeDef *USBx, uint8_t speed)
USB_SetDevSpeed Initializes the DevSpd field of DCFG register depending the PHY type and the enumerat...
HAL_StatusTypeDef USB_FlushRxFifo(USB_OTG_GlobalTypeDef *USBx)
USB_FlushRxFifo Flush Rx FIFO.
HAL_StatusTypeDef USB_EnableGlobalInt(USB_OTG_GlobalTypeDef *USBx)
USB_EnableGlobalInt Enables the controller's Global Int in the AHB Config reg.
HAL_StatusTypeDef USB_InitFSLSPClkSel(const USB_OTG_GlobalTypeDef *USBx, uint8_t freq)
USB_InitFSLSPClkSel : Initializes the FSLSPClkSel field of the HCFG register on the PHY type and set ...
HAL_StatusTypeDef USB_DevDisconnect(const USB_OTG_GlobalTypeDef *USBx)
USB_DevDisconnect : Disconnect the USB device by disabling Rpu.
HAL_StatusTypeDef USB_StopHost(USB_OTG_GlobalTypeDef *USBx)
Stop Host Core.
HAL_StatusTypeDef USB_SetDevAddress(const USB_OTG_GlobalTypeDef *USBx, uint8_t address)
USB_SetDevAddress : Stop the usb device mode.
HAL_StatusTypeDef USB_FlushTxFifo(USB_OTG_GlobalTypeDef *USBx, uint32_t num)
USB_FlushTxFifo Flush a Tx FIFO.
HAL_StatusTypeDef USB_DevConnect(const USB_OTG_GlobalTypeDef *USBx)
USB_DevConnect : Connect the USB device by enabling Rpu.
void USB_ClearInterrupts(USB_OTG_GlobalTypeDef *USBx, uint32_t interrupt)
USB_ClearInterrupts: clear a USB interrupt.
uint32_t USB_GetCurrentFrame(USB_OTG_GlobalTypeDef const *USBx)
Return Host Current Frame number.
HAL_StatusTypeDef USB_ActivateRemoteWakeup(const USB_OTG_GlobalTypeDef *USBx)
USB_ActivateRemoteWakeup active remote wakeup signalling.
uint32_t USB_ReadInterrupts(USB_OTG_GlobalTypeDef const *USBx)
USB_ReadInterrupts: return the global USB interrupt status.
HAL_StatusTypeDef USB_DeActivateRemoteWakeup(const USB_OTG_GlobalTypeDef *USBx)
USB_DeActivateRemoteWakeup de-active remote wakeup signalling.
HAL_StatusTypeDef USB_EPStopXfer(const USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
USB_EPStoptXfer Stop transfer on an EP.
HAL_StatusTypeDef USB_EP0_OutStart(const USB_OTG_GlobalTypeDef *USBx, uint8_t dma, const uint8_t *psetup)
Prepare the EP0 to start the first control setup.
HAL_StatusTypeDef USB_DevInit(USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg)
USB_DevInit Initializes the USB_OTG controller registers for device mode.
uint32_t iso_splt_xactPos
USB_URBStateTypeDef urb_state
uint8_t vbus_sensing_enable
uint8_t is_iso_incomplete
uint8_t use_dedicated_ep1
uint8_t use_external_vbus
uint8_t battery_charging_enable
USB_HCStateTypeDef
Host channel States definition.
USB_URBStateTypeDef
URB States definition.
USB_ModeTypeDef
USB Mode definition.
USB Instance Initialization Structure definition.
This file contains HAL common defines, enumeration, macros and structures definitions.