STM32L4xx_HAL_Driver  1.14.0
USB Low Layer Exported Functions

Modules

 Initialization/de-initialization functions
 Initialization and Configuration functions.
 

Functions

HAL_StatusTypeDef USB_CoreInit (USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg)
 Initializes the USB Core. More...
 
HAL_StatusTypeDef USB_DevInit (USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg)
 USB_DevInit : Initializes the USB_OTG controller registers for device mode. More...
 
HAL_StatusTypeDef USB_EnableGlobalInt (USB_OTG_GlobalTypeDef *USBx)
 USB_EnableGlobalInt Enables the controller's Global Int in the AHB Config reg. More...
 
HAL_StatusTypeDef USB_DisableGlobalInt (USB_OTG_GlobalTypeDef *USBx)
 USB_DisableGlobalInt Disable the controller's Global Int in the AHB Config reg. More...
 
HAL_StatusTypeDef USB_SetTurnaroundTime (USB_OTG_GlobalTypeDef *USBx, uint32_t hclk, uint8_t speed)
 Set the USB turnaround time. More...
 
HAL_StatusTypeDef USB_SetCurrentMode (USB_OTG_GlobalTypeDef *USBx, USB_ModeTypeDef mode)
 USB_SetCurrentMode : Set functional mode. More...
 
HAL_StatusTypeDef USB_SetDevSpeed (USB_OTG_GlobalTypeDef *USBx, uint8_t speed)
 USB_SetDevSpeed Initializes the DevSpd field of DCFG register depending the PHY type and the enumeration speed of the device. More...
 
HAL_StatusTypeDef USB_FlushRxFifo (USB_OTG_GlobalTypeDef *USBx)
 USB_FlushRxFifo : Flush Rx FIFO. More...
 
HAL_StatusTypeDef USB_FlushTxFifo (USB_OTG_GlobalTypeDef *USBx, uint32_t num)
 USB_OTG_FlushTxFifo : Flush a Tx FIFO. More...
 
HAL_StatusTypeDef USB_ActivateEndpoint (USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
 Activate and configure an endpoint. More...
 
HAL_StatusTypeDef USB_DeactivateEndpoint (USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
 De-activate and de-initialize an endpoint. More...
 
HAL_StatusTypeDef USB_ActivateDedicatedEndpoint (USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
 Activate and configure a dedicated endpoint. More...
 
HAL_StatusTypeDef USB_DeactivateDedicatedEndpoint (USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
 De-activate and de-initialize a dedicated endpoint. More...
 
HAL_StatusTypeDef USB_EPStartXfer (USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
 USB_EPStartXfer : setup and starts a transfer over an EP. More...
 
HAL_StatusTypeDef USB_EP0StartXfer (USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
 USB_EP0StartXfer : setup and starts a transfer over the EP 0. More...
 
HAL_StatusTypeDef USB_WritePacket (USB_OTG_GlobalTypeDef *USBx, uint8_t *src, uint8_t ch_ep_num, uint16_t len)
 USB_WritePacket : Writes a packet into the Tx FIFO associated with the EP/channel. More...
 
void * USB_ReadPacket (USB_OTG_GlobalTypeDef *USBx, uint8_t *dest, uint16_t len)
 USB_ReadPacket : read a packet from the RX FIFO. More...
 
HAL_StatusTypeDef USB_EPSetStall (USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
 USB_EPSetStall : set a stall condition over an EP. More...
 
HAL_StatusTypeDef USB_EPClearStall (USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
 USB_EPClearStall : Clear a stall condition over an EP. More...
 
HAL_StatusTypeDef USB_SetDevAddress (USB_OTG_GlobalTypeDef *USBx, uint8_t address)
 USB_SetDevAddress : Stop the usb device mode. More...
 
HAL_StatusTypeDef USB_DevConnect (USB_OTG_GlobalTypeDef *USBx)
 USB_DevConnect : Connect the USB device by enabling the pull-up/pull-down. More...
 
HAL_StatusTypeDef USB_DevDisconnect (USB_OTG_GlobalTypeDef *USBx)
 USB_DevDisconnect : Disconnect the USB device by disabling the pull-up/pull-down. More...
 
HAL_StatusTypeDef USB_StopDevice (USB_OTG_GlobalTypeDef *USBx)
 USB_StopDevice : Stop the usb device mode. More...
 
HAL_StatusTypeDef USB_ActivateSetup (USB_OTG_GlobalTypeDef *USBx)
 Activate EP0 for Setup transactions. More...
 
HAL_StatusTypeDef USB_EP0_OutStart (USB_OTG_GlobalTypeDef *USBx, uint8_t *psetup)
 Prepare the EP0 to start the first control setup. More...
 
uint8_t USB_GetDevSpeed (USB_OTG_GlobalTypeDef *USBx)
 USB_GetDevSpeed Return the Dev Speed. More...
 
uint32_t USB_GetMode (USB_OTG_GlobalTypeDef *USBx)
 Returns USB core mode. More...
 
uint32_t USB_ReadInterrupts (USB_OTG_GlobalTypeDef *USBx)
 USB_ReadInterrupts: return the global USB interrupt status. More...
 
uint32_t USB_ReadDevAllOutEpInterrupt (USB_OTG_GlobalTypeDef *USBx)
 USB_ReadDevAllOutEpInterrupt: return the USB device OUT endpoints interrupt status. More...
 
uint32_t USB_ReadDevOutEPInterrupt (USB_OTG_GlobalTypeDef *USBx, uint8_t epnum)
 Returns Device OUT EP Interrupt register. More...
 
uint32_t USB_ReadDevAllInEpInterrupt (USB_OTG_GlobalTypeDef *USBx)
 USB_ReadDevAllInEpInterrupt: return the USB device IN endpoints interrupt status. More...
 
uint32_t USB_ReadDevInEPInterrupt (USB_OTG_GlobalTypeDef *USBx, uint8_t epnum)
 Returns Device IN EP Interrupt register. More...
 
void USB_ClearInterrupts (USB_OTG_GlobalTypeDef *USBx, uint32_t interrupt)
 USB_ClearInterrupts: clear a USB interrupt. More...
 
HAL_StatusTypeDef USB_HostInit (USB_OTG_GlobalTypeDef *USBx, USB_OTG_CfgTypeDef cfg)
 USB_HostInit : Initializes the USB OTG controller registers for Host mode. More...
 
HAL_StatusTypeDef USB_InitFSLSPClkSel (USB_OTG_GlobalTypeDef *USBx, uint8_t freq)
 USB_InitFSLSPClkSel : Initializes the FSLSPClkSel field of the HCFG register on the PHY type and set the right frame interval. More...
 
HAL_StatusTypeDef USB_ResetPort (USB_OTG_GlobalTypeDef *USBx)
 USB_OTG_ResetPort : Reset Host Port. More...
 
HAL_StatusTypeDef USB_DriveVbus (USB_OTG_GlobalTypeDef *USBx, uint8_t state)
 USB_DriveVbus : activate or de-activate vbus. More...
 
uint32_t USB_GetHostSpeed (USB_OTG_GlobalTypeDef *USBx)
 Return Host Core speed. More...
 
uint32_t USB_GetCurrentFrame (USB_OTG_GlobalTypeDef *USBx)
 Return Host Current Frame number. More...
 
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. More...
 
HAL_StatusTypeDef USB_HC_StartXfer (USB_OTG_GlobalTypeDef *USBx, USB_OTG_HCTypeDef *hc)
 Start a transfer over a host channel. More...
 
uint32_t USB_HC_ReadInterrupt (USB_OTG_GlobalTypeDef *USBx)
 Read all host channel interrupts status. More...
 
HAL_StatusTypeDef USB_HC_Halt (USB_OTG_GlobalTypeDef *USBx, uint8_t hc_num)
 Halt a host channel. More...
 
HAL_StatusTypeDef USB_DoPing (USB_OTG_GlobalTypeDef *USBx, uint8_t ch_num)
 Initiate Do Ping protocol. More...
 
HAL_StatusTypeDef USB_StopHost (USB_OTG_GlobalTypeDef *USBx)
 Stop Host Core. More...
 
HAL_StatusTypeDef USB_ActivateRemoteWakeup (USB_OTG_GlobalTypeDef *USBx)
 USB_ActivateRemoteWakeup active remote wakeup signalling. More...
 
HAL_StatusTypeDef USB_DeActivateRemoteWakeup (USB_OTG_GlobalTypeDef *USBx)
 USB_DeActivateRemoteWakeup de-active remote wakeup signalling. More...
 
HAL_StatusTypeDef USB_CoreInit (USB_TypeDef *USBx, USB_CfgTypeDef cfg)
 Initializes the USB Core. More...
 
HAL_StatusTypeDef USB_DevInit (USB_TypeDef *USBx, USB_CfgTypeDef cfg)
 USB_DevInit : Initializes the USB controller registers for device mode. More...
 
HAL_StatusTypeDef USB_EnableGlobalInt (USB_TypeDef *USBx)
 USB_EnableGlobalInt Enables the controller's Global Int in the AHB Config reg. More...
 
HAL_StatusTypeDef USB_DisableGlobalInt (USB_TypeDef *USBx)
 USB_DisableGlobalInt Disable the controller's Global Int in the AHB Config reg. More...
 
HAL_StatusTypeDef USB_SetCurrentMode (USB_TypeDef *USBx, USB_ModeTypeDef mode)
 USB_SetCurrentMode : Set functional mode. More...
 
HAL_StatusTypeDef USB_SetDevSpeed (USB_TypeDef *USBx, uint8_t speed)
 USB_SetDevSpeed :Initializes the device speed depending on the PHY type and the enumeration speed of the device. More...
 
HAL_StatusTypeDef USB_FlushRxFifo (USB_TypeDef *USBx)
 USB_FlushRxFifo : Flush Rx FIFO. More...
 
HAL_StatusTypeDef USB_FlushTxFifo (USB_TypeDef *USBx, uint32_t num)
 USB_FlushTxFifo : Flush a Tx FIFO. More...
 
HAL_StatusTypeDef USB_ActivateEndpoint (USB_TypeDef *USBx, USB_EPTypeDef *ep)
 Activate and configure an endpoint. More...
 
HAL_StatusTypeDef USB_DeactivateEndpoint (USB_TypeDef *USBx, USB_EPTypeDef *ep)
 De-activate and de-initialize an endpoint. More...
 
HAL_StatusTypeDef USB_EPStartXfer (USB_TypeDef *USBx, USB_EPTypeDef *ep)
 USB_EPStartXfer : setup and starts a transfer over an EP. More...
 
HAL_StatusTypeDef USB_WritePacket (USB_TypeDef *USBx, uint8_t *src, uint8_t ch_ep_num, uint16_t len)
 USB_WritePacket : Writes a packet into the Tx FIFO associated with the EP/channel. More...
 
void * USB_ReadPacket (USB_TypeDef *USBx, uint8_t *dest, uint16_t len)
 USB_ReadPacket : read a packet from the Tx FIFO associated with the EP/channel. More...
 
HAL_StatusTypeDef USB_EPSetStall (USB_TypeDef *USBx, USB_EPTypeDef *ep)
 USB_EPSetStall : set a stall condition over an EP. More...
 
HAL_StatusTypeDef USB_EPClearStall (USB_TypeDef *USBx, USB_EPTypeDef *ep)
 USB_EPClearStall : Clear a stall condition over an EP. More...
 
HAL_StatusTypeDef USB_SetDevAddress (USB_TypeDef *USBx, uint8_t address)
 USB_SetDevAddress : Stop the usb device mode. More...
 
HAL_StatusTypeDef USB_DevConnect (USB_TypeDef *USBx)
 USB_DevConnect : Connect the USB device by enabling the pull-up/pull-down. More...
 
HAL_StatusTypeDef USB_DevDisconnect (USB_TypeDef *USBx)
 USB_DevDisconnect : Disconnect the USB device by disabling the pull-up/pull-down. More...
 
HAL_StatusTypeDef USB_StopDevice (USB_TypeDef *USBx)
 USB_StopDevice : Stop the usb device mode. More...
 
HAL_StatusTypeDef USB_EP0_OutStart (USB_TypeDef *USBx, uint8_t *psetup)
 Prepare the EP0 to start the first control setup. More...
 
uint32_t USB_ReadInterrupts (USB_TypeDef *USBx)
 USB_ReadInterrupts: return the global USB interrupt status. More...
 
uint32_t USB_ReadDevAllOutEpInterrupt (USB_TypeDef *USBx)
 USB_ReadDevAllOutEpInterrupt: return the USB device OUT endpoints interrupt status. More...
 
uint32_t USB_ReadDevOutEPInterrupt (USB_TypeDef *USBx, uint8_t epnum)
 Returns Device OUT EP Interrupt register. More...
 
uint32_t USB_ReadDevAllInEpInterrupt (USB_TypeDef *USBx)
 USB_ReadDevAllInEpInterrupt: return the USB device IN endpoints interrupt status. More...
 
uint32_t USB_ReadDevInEPInterrupt (USB_TypeDef *USBx, uint8_t epnum)
 Returns Device IN EP Interrupt register. More...
 
void USB_ClearInterrupts (USB_TypeDef *USBx, uint32_t interrupt)
 USB_ClearInterrupts: clear a USB interrupt. More...
 
HAL_StatusTypeDef USB_ActivateRemoteWakeup (USB_TypeDef *USBx)
 USB_ActivateRemoteWakeup : active remote wakeup signalling. More...
 
HAL_StatusTypeDef USB_DeActivateRemoteWakeup (USB_TypeDef *USBx)
 USB_DeActivateRemoteWakeup : de-active remote wakeup signalling. More...
 
void USB_WritePMA (USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
 Copy a buffer from user memory area to packet memory area (PMA) More...
 
void USB_ReadPMA (USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
 Copy a buffer from user memory area to packet memory area (PMA) More...
 

Detailed Description

Function Documentation

◆ USB_ActivateDedicatedEndpoint()

HAL_StatusTypeDef USB_ActivateDedicatedEndpoint ( USB_OTG_GlobalTypeDef *  USBx,
USB_OTG_EPTypeDef ep 
)

Activate and configure a dedicated endpoint.

Parameters
USBxSelected device
eppointer to endpoint structure
Return values
HALstatus

Definition at line 530 of file stm32l4xx_ll_usb.c.

531 {
532  uint32_t USBx_BASE = (uint32_t)USBx;
533  uint32_t epnum = (uint32_t)ep->num;
534 
535  /* Read DEPCTLn register */
536  if (ep->is_in == 1U)
537  {
538  if (((USBx_INEP(epnum)->DIEPCTL) & USB_OTG_DIEPCTL_USBAEP) == 0U)
539  {
540  USBx_INEP(epnum)->DIEPCTL |= (ep->maxpacket & USB_OTG_DIEPCTL_MPSIZ) |
541  ((uint32_t)ep->type << 18) | (epnum << 22) |
542  USB_OTG_DIEPCTL_SD0PID_SEVNFRM |
543  USB_OTG_DIEPCTL_USBAEP;
544  }
545 
546  USBx_DEVICE->DEACHMSK |= USB_OTG_DAINTMSK_IEPM & (uint32_t)(1UL << (ep->num & EP_ADDR_MSK));
547  }
548  else
549  {
550  if (((USBx_OUTEP(epnum)->DOEPCTL) & USB_OTG_DOEPCTL_USBAEP) == 0U)
551  {
552  USBx_OUTEP(epnum)->DOEPCTL |= (ep->maxpacket & USB_OTG_DOEPCTL_MPSIZ) |
553  ((uint32_t)ep->type << 18) | (epnum << 22) |
554  USB_OTG_DOEPCTL_USBAEP;
555  }
556 
557  USBx_DEVICE->DEACHMSK |= USB_OTG_DAINTMSK_OEPM & ((uint32_t)(1UL << (ep->num & EP_ADDR_MSK)) << 16);
558  }
559 
560  return HAL_OK;
561 }
if(lpuartdiv >=LPUART_BRR_MIN_VALUE)
return HAL_OK

◆ USB_ActivateEndpoint() [1/2]

HAL_StatusTypeDef USB_ActivateEndpoint ( USB_OTG_GlobalTypeDef *  USBx,
USB_OTG_EPTypeDef ep 
)

Activate and configure an endpoint.

Parameters
USBxSelected device
eppointer to endpoint structure
Return values
HALstatus

Definition at line 492 of file stm32l4xx_ll_usb.c.

493 {
494  uint32_t USBx_BASE = (uint32_t)USBx;
495  uint32_t epnum = (uint32_t)ep->num;
496 
497  if (ep->is_in == 1U)
498  {
499  USBx_DEVICE->DAINTMSK |= USB_OTG_DAINTMSK_IEPM & (uint32_t)(1UL << (ep->num & EP_ADDR_MSK));
500 
501  if ((USBx_INEP(epnum)->DIEPCTL & USB_OTG_DIEPCTL_USBAEP) == 0U)
502  {
503  USBx_INEP(epnum)->DIEPCTL |= (ep->maxpacket & USB_OTG_DIEPCTL_MPSIZ) |
504  ((uint32_t)ep->type << 18) | (epnum << 22) |
505  USB_OTG_DIEPCTL_SD0PID_SEVNFRM |
506  USB_OTG_DIEPCTL_USBAEP;
507  }
508  }
509  else
510  {
511  USBx_DEVICE->DAINTMSK |= USB_OTG_DAINTMSK_OEPM & ((uint32_t)(1UL << (ep->num & EP_ADDR_MSK)) << 16);
512 
513  if (((USBx_OUTEP(epnum)->DOEPCTL) & USB_OTG_DOEPCTL_USBAEP) == 0U)
514  {
515  USBx_OUTEP(epnum)->DOEPCTL |= (ep->maxpacket & USB_OTG_DOEPCTL_MPSIZ) |
516  ((uint32_t)ep->type << 18) |
517  USB_OTG_DIEPCTL_SD0PID_SEVNFRM |
518  USB_OTG_DOEPCTL_USBAEP;
519  }
520  }
521  return HAL_OK;
522 }
if(lpuartdiv >=LPUART_BRR_MIN_VALUE)
return HAL_OK

◆ USB_ActivateEndpoint() [2/2]

HAL_StatusTypeDef USB_ActivateEndpoint ( USB_TypeDef *  USBx,
USB_EPTypeDef ep 
)

Activate and configure an endpoint.

Parameters
USBx: Selected device
eppointer to endpoint structure
Return values
HALstatus

Definition at line 1975 of file stm32l4xx_ll_usb.c.

1976 {
1977  HAL_StatusTypeDef ret = HAL_OK;
1978  uint16_t wEpRegVal;
1979 
1980  wEpRegVal = PCD_GET_ENDPOINT(USBx, ep->num) & USB_EP_T_MASK;
1981 
1982  /* initialize Endpoint */
1983  switch (ep->type)
1984  {
1985  case EP_TYPE_CTRL:
1986  wEpRegVal |= USB_EP_CONTROL;
1987  break;
1988 
1989  case EP_TYPE_BULK:
1990  wEpRegVal |= USB_EP_BULK;
1991  break;
1992 
1993  case EP_TYPE_INTR:
1994  wEpRegVal |= USB_EP_INTERRUPT;
1995  break;
1996 
1997  case EP_TYPE_ISOC:
1998  wEpRegVal |= USB_EP_ISOCHRONOUS;
1999  break;
2000 
2001  default:
2002  ret = HAL_ERROR;
2003  break;
2004  }
2005 
2006  PCD_SET_ENDPOINT(USBx, ep->num, wEpRegVal | USB_EP_CTR_RX | USB_EP_CTR_TX);
2007 
2008  PCD_SET_EP_ADDRESS(USBx, ep->num, ep->num);
2009 
2010  if (ep->doublebuffer == 0U)
2011  {
2012  if (ep->is_in != 0U)
2013  {
2014  /*Set the endpoint Transmit buffer address */
2015  PCD_SET_EP_TX_ADDRESS(USBx, ep->num, ep->pmaadress);
2016  PCD_CLEAR_TX_DTOG(USBx, ep->num);
2017 
2018  if (ep->type != EP_TYPE_ISOC)
2019  {
2020  /* Configure NAK status for the Endpoint */
2021  PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_NAK);
2022  }
2023  else
2024  {
2025  /* Configure TX Endpoint to disabled state */
2026  PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
2027  }
2028  }
2029  else
2030  {
2031  /*Set the endpoint Receive buffer address */
2032  PCD_SET_EP_RX_ADDRESS(USBx, ep->num, ep->pmaadress);
2033  /*Set the endpoint Receive buffer counter*/
2034  PCD_SET_EP_RX_CNT(USBx, ep->num, ep->maxpacket);
2035  PCD_CLEAR_RX_DTOG(USBx, ep->num);
2036  /* Configure VALID status for the Endpoint*/
2037  PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_VALID);
2038  }
2039  }
2040  /*Double Buffer*/
2041  else
2042  {
2043  /* Set the endpoint as double buffered */
2044  PCD_SET_EP_DBUF(USBx, ep->num);
2045  /* Set buffer address for double buffered mode */
2046  PCD_SET_EP_DBUF_ADDR(USBx, ep->num, ep->pmaaddr0, ep->pmaaddr1);
2047 
2048  if (ep->is_in == 0U)
2049  {
2050  /* Clear the data toggle bits for the endpoint IN/OUT */
2051  PCD_CLEAR_RX_DTOG(USBx, ep->num);
2052  PCD_CLEAR_TX_DTOG(USBx, ep->num);
2053 
2054  /* Reset value of the data toggle bits for the endpoint out */
2055  PCD_TX_DTOG(USBx, ep->num);
2056 
2057  PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_VALID);
2058  PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
2059  }
2060  else
2061  {
2062  /* Clear the data toggle bits for the endpoint IN/OUT */
2063  PCD_CLEAR_RX_DTOG(USBx, ep->num);
2064  PCD_CLEAR_TX_DTOG(USBx, ep->num);
2065  PCD_RX_DTOG(USBx, ep->num);
2066 
2067  if (ep->type != EP_TYPE_ISOC)
2068  {
2069  /* Configure NAK status for the Endpoint */
2070  PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_NAK);
2071  }
2072  else
2073  {
2074  /* Configure TX Endpoint to disabled state */
2075  PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
2076  }
2077 
2078  PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_DIS);
2079  }
2080  }
2081 
2082  return ret;
2083 }
return HAL_OK

◆ USB_ActivateRemoteWakeup() [1/2]

HAL_StatusTypeDef USB_ActivateRemoteWakeup ( USB_OTG_GlobalTypeDef *  USBx)

USB_ActivateRemoteWakeup active remote wakeup signalling.

Parameters
USBxSelected device
Return values
HALstatus

Definition at line 1760 of file stm32l4xx_ll_usb.c.

1761 {
1762  uint32_t USBx_BASE = (uint32_t)USBx;
1763 
1764  if ((USBx_DEVICE->DSTS & USB_OTG_DSTS_SUSPSTS) == USB_OTG_DSTS_SUSPSTS)
1765  {
1766  /* active Remote wakeup signalling */
1767  USBx_DEVICE->DCTL |= USB_OTG_DCTL_RWUSIG;
1768  }
1769 
1770  return HAL_OK;
1771 }
return HAL_OK

◆ USB_ActivateRemoteWakeup() [2/2]

HAL_StatusTypeDef USB_ActivateRemoteWakeup ( USB_TypeDef *  USBx)

USB_ActivateRemoteWakeup : active remote wakeup signalling.

Parameters
USBxSelected device
Return values
HALstatus

Definition at line 2505 of file stm32l4xx_ll_usb.c.

2506 {
2507  USBx->CNTR |= USB_CNTR_RESUME;
2508 
2509  return HAL_OK;
2510 }
return HAL_OK

◆ USB_ActivateSetup()

HAL_StatusTypeDef USB_ActivateSetup ( USB_OTG_GlobalTypeDef *  USBx)

Activate EP0 for Setup transactions.

Parameters
USBxSelected device
Return values
HALstatus

Definition at line 1109 of file stm32l4xx_ll_usb.c.

1110 {
1111  uint32_t USBx_BASE = (uint32_t)USBx;
1112 
1113  /* Set the MPS of the IN EP based on the enumeration speed */
1114  USBx_INEP(0U)->DIEPCTL &= ~USB_OTG_DIEPCTL_MPSIZ;
1115 
1116  if ((USBx_DEVICE->DSTS & USB_OTG_DSTS_ENUMSPD) == DSTS_ENUMSPD_LS_PHY_6MHZ)
1117  {
1118  USBx_INEP(0U)->DIEPCTL |= 3U;
1119  }
1120  USBx_DEVICE->DCTL |= USB_OTG_DCTL_CGINAK;
1121 
1122  return HAL_OK;
1123 }
return HAL_OK

◆ USB_ClearInterrupts() [1/2]

void USB_ClearInterrupts ( USB_OTG_GlobalTypeDef *  USBx,
uint32_t  interrupt 
)

USB_ClearInterrupts: clear a USB interrupt.

Parameters
USBxSelected device
interruptinterrupt flag
Return values
None

Definition at line 1086 of file stm32l4xx_ll_usb.c.

1087 {
1088  USBx->GINTSTS |= interrupt;
1089 }

◆ USB_ClearInterrupts() [2/2]

void USB_ClearInterrupts ( USB_TypeDef *  USBx,
uint32_t  interrupt 
)

USB_ClearInterrupts: clear a USB interrupt.

Parameters
USBxSelected device
interruptinterrupt flag
Return values
None

Definition at line 2471 of file stm32l4xx_ll_usb.c.

2472 {
2473  /* Prevent unused argument(s) compilation warning */
2474  UNUSED(USBx);
2475  UNUSED(interrupt);
2476  /* NOTE : - This function is not required by USB Device FS peripheral, it is used
2477  only by USB OTG FS peripheral.
2478  - This function is added to ensure compatibility across platforms.
2479  */
2480 }

◆ USB_CoreInit() [1/2]

HAL_StatusTypeDef USB_CoreInit ( USB_OTG_GlobalTypeDef *  USBx,
USB_OTG_CfgTypeDef  cfg 
)

Initializes the USB Core.

Parameters
USBxUSB Instance
cfgpointer to a USB_OTG_CfgTypeDef structure that contains the configuration information for the specified USBx peripheral.
Return values
HALstatus

Definition at line 82 of file stm32l4xx_ll_usb.c.

83 {
84  HAL_StatusTypeDef ret;
85 
86  if (cfg.phy_itface == USB_OTG_ULPI_PHY)
87  {
88  USBx->GCCFG &= ~(USB_OTG_GCCFG_PWRDWN);
89 
90  /* Init The ULPI Interface */
91  USBx->GUSBCFG &= ~(USB_OTG_GUSBCFG_TSDPS | USB_OTG_GUSBCFG_ULPIFSLS | USB_OTG_GUSBCFG_PHYSEL);
92 
93  /* Select vbus source */
94  USBx->GUSBCFG &= ~(USB_OTG_GUSBCFG_ULPIEVBUSD | USB_OTG_GUSBCFG_ULPIEVBUSI);
95  if (cfg.use_external_vbus == 1U)
96  {
97  USBx->GUSBCFG |= USB_OTG_GUSBCFG_ULPIEVBUSD;
98  }
99  /* Reset after a PHY select */
100  ret = USB_CoreReset(USBx);
101  }
102  else /* FS interface (embedded Phy) */
103  {
104  /* Select FS Embedded PHY */
105  USBx->GUSBCFG |= USB_OTG_GUSBCFG_PHYSEL;
106 
107  /* Reset after a PHY select and set Host mode */
108  ret = USB_CoreReset(USBx);
109 
110  if (cfg.battery_charging_enable == 0U)
111  {
112  /* Activate the USB Transceiver */
113  USBx->GCCFG |= USB_OTG_GCCFG_PWRDWN;
114  }
115  else
116  {
117  /* Deactivate the USB Transceiver */
118  USBx->GCCFG &= ~(USB_OTG_GCCFG_PWRDWN);
119  }
120  }
121 
122  return ret;
123 }
static HAL_StatusTypeDef USB_CoreReset(USB_OTG_GlobalTypeDef *USBx)
Reset the USB Core (needed after USB clock settings change)
uint32_t battery_charging_enable

◆ USB_CoreInit() [2/2]

HAL_StatusTypeDef USB_CoreInit ( USB_TypeDef *  USBx,
USB_CfgTypeDef  cfg 
)

Initializes the USB Core.

Parameters
USBxUSB Instance
cfg: pointer to a USB_CfgTypeDef structure that contains the configuration information for the specified USBx peripheral.
Return values
HALstatus

Definition at line 1797 of file stm32l4xx_ll_usb.c.

1798 {
1799  /* Prevent unused argument(s) compilation warning */
1800  UNUSED(USBx);
1801  UNUSED(cfg);
1802 
1803  /* NOTE : - This function is not required by USB Device FS peripheral, it is used
1804  only by USB OTG FS peripheral.
1805  - This function is added to ensure compatibility across platforms.
1806  */
1807 
1808  return HAL_OK;
1809 }
return HAL_OK

◆ USB_DeactivateDedicatedEndpoint()

HAL_StatusTypeDef USB_DeactivateDedicatedEndpoint ( USB_OTG_GlobalTypeDef *  USBx,
USB_OTG_EPTypeDef ep 
)

De-activate and de-initialize a dedicated endpoint.

Parameters
USBxSelected device
eppointer to endpoint structure
Return values
HALstatus

Definition at line 604 of file stm32l4xx_ll_usb.c.

605 {
606  uint32_t USBx_BASE = (uint32_t)USBx;
607  uint32_t epnum = (uint32_t)ep->num;
608 
609  /* Read DEPCTLn register */
610  if (ep->is_in == 1U)
611  {
612  USBx_INEP(epnum)->DIEPCTL &= ~ USB_OTG_DIEPCTL_USBAEP;
613  USBx_DEVICE->DAINTMSK &= ~(USB_OTG_DAINTMSK_IEPM & (uint32_t)(1UL << (ep->num & EP_ADDR_MSK)));
614  }
615  else
616  {
617  USBx_OUTEP(epnum)->DOEPCTL &= ~USB_OTG_DOEPCTL_USBAEP;
618  USBx_DEVICE->DAINTMSK &= ~(USB_OTG_DAINTMSK_OEPM & ((uint32_t)(1UL << (ep->num & EP_ADDR_MSK)) << 16));
619  }
620 
621  return HAL_OK;
622 }
if(lpuartdiv >=LPUART_BRR_MIN_VALUE)
return HAL_OK

◆ USB_DeactivateEndpoint() [1/2]

HAL_StatusTypeDef USB_DeactivateEndpoint ( USB_OTG_GlobalTypeDef *  USBx,
USB_OTG_EPTypeDef ep 
)

De-activate and de-initialize an endpoint.

Parameters
USBxSelected device
eppointer to endpoint structure
Return values
HALstatus

Definition at line 569 of file stm32l4xx_ll_usb.c.

570 {
571  uint32_t USBx_BASE = (uint32_t)USBx;
572  uint32_t epnum = (uint32_t)ep->num;
573 
574  /* Read DEPCTLn register */
575  if (ep->is_in == 1U)
576  {
577  USBx_DEVICE->DEACHMSK &= ~(USB_OTG_DAINTMSK_IEPM & (uint32_t)(1UL << (ep->num & EP_ADDR_MSK)));
578  USBx_DEVICE->DAINTMSK &= ~(USB_OTG_DAINTMSK_IEPM & (uint32_t)(1UL << (ep->num & EP_ADDR_MSK)));
579  USBx_INEP(epnum)->DIEPCTL &= ~(USB_OTG_DIEPCTL_USBAEP |
580  USB_OTG_DIEPCTL_MPSIZ |
581  USB_OTG_DIEPCTL_TXFNUM |
582  USB_OTG_DIEPCTL_SD0PID_SEVNFRM |
583  USB_OTG_DIEPCTL_EPTYP);
584  }
585  else
586  {
587  USBx_DEVICE->DEACHMSK &= ~(USB_OTG_DAINTMSK_OEPM & ((uint32_t)(1UL << (ep->num & EP_ADDR_MSK)) << 16));
588  USBx_DEVICE->DAINTMSK &= ~(USB_OTG_DAINTMSK_OEPM & ((uint32_t)(1UL << (ep->num & EP_ADDR_MSK)) << 16));
589  USBx_OUTEP(epnum)->DOEPCTL &= ~(USB_OTG_DOEPCTL_USBAEP |
590  USB_OTG_DOEPCTL_MPSIZ |
591  USB_OTG_DOEPCTL_SD0PID_SEVNFRM |
592  USB_OTG_DOEPCTL_EPTYP);
593  }
594 
595  return HAL_OK;
596 }
if(lpuartdiv >=LPUART_BRR_MIN_VALUE)
return HAL_OK

◆ USB_DeactivateEndpoint() [2/2]

HAL_StatusTypeDef USB_DeactivateEndpoint ( USB_TypeDef *  USBx,
USB_EPTypeDef ep 
)

De-activate and de-initialize an endpoint.

Parameters
USBx: Selected device
eppointer to endpoint structure
Return values
HALstatus

Definition at line 2091 of file stm32l4xx_ll_usb.c.

2092 {
2093  if (ep->doublebuffer == 0U)
2094  {
2095  if (ep->is_in != 0U)
2096  {
2097  PCD_CLEAR_TX_DTOG(USBx, ep->num);
2098  /* Configure DISABLE status for the Endpoint*/
2099  PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
2100  }
2101  else
2102  {
2103  PCD_CLEAR_RX_DTOG(USBx, ep->num);
2104  /* Configure DISABLE status for the Endpoint*/
2105  PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_DIS);
2106  }
2107  }
2108  /*Double Buffer*/
2109  else
2110  {
2111  if (ep->is_in == 0U)
2112  {
2113  /* Clear the data toggle bits for the endpoint IN/OUT*/
2114  PCD_CLEAR_RX_DTOG(USBx, ep->num);
2115  PCD_CLEAR_TX_DTOG(USBx, ep->num);
2116 
2117  /* Reset value of the data toggle bits for the endpoint out*/
2118  PCD_TX_DTOG(USBx, ep->num);
2119 
2120  PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_DIS);
2121  PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
2122  }
2123  else
2124  {
2125  /* Clear the data toggle bits for the endpoint IN/OUT*/
2126  PCD_CLEAR_RX_DTOG(USBx, ep->num);
2127  PCD_CLEAR_TX_DTOG(USBx, ep->num);
2128  PCD_RX_DTOG(USBx, ep->num);
2129  /* Configure DISABLE status for the Endpoint*/
2130  PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_DIS);
2131  PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_DIS);
2132  }
2133  }
2134 
2135  return HAL_OK;
2136 }
return HAL_OK

◆ USB_DeActivateRemoteWakeup() [1/2]

HAL_StatusTypeDef USB_DeActivateRemoteWakeup ( USB_OTG_GlobalTypeDef *  USBx)

USB_DeActivateRemoteWakeup de-active remote wakeup signalling.

Parameters
USBxSelected device
Return values
HALstatus

Definition at line 1778 of file stm32l4xx_ll_usb.c.

1779 {
1780  uint32_t USBx_BASE = (uint32_t)USBx;
1781 
1782  /* active Remote wakeup signalling */
1783  USBx_DEVICE->DCTL &= ~(USB_OTG_DCTL_RWUSIG);
1784 
1785  return HAL_OK;
1786 }
return HAL_OK

◆ USB_DeActivateRemoteWakeup() [2/2]

HAL_StatusTypeDef USB_DeActivateRemoteWakeup ( USB_TypeDef *  USBx)

USB_DeActivateRemoteWakeup : de-active remote wakeup signalling.

Parameters
USBxSelected device
Return values
HALstatus

Definition at line 2517 of file stm32l4xx_ll_usb.c.

2518 {
2519  USBx->CNTR &= ~(USB_CNTR_RESUME);
2520  return HAL_OK;
2521 }
return HAL_OK

◆ USB_DevConnect() [1/2]

HAL_StatusTypeDef USB_DevConnect ( USB_OTG_GlobalTypeDef *  USBx)

USB_DevConnect : Connect the USB device by enabling the pull-up/pull-down.

Parameters
USBxSelected device
Return values
HALstatus

Definition at line 970 of file stm32l4xx_ll_usb.c.

971 {
972  uint32_t USBx_BASE = (uint32_t)USBx;
973 
974  USBx_DEVICE->DCTL &= ~USB_OTG_DCTL_SDIS;
975  HAL_Delay(3U);
976 
977  return HAL_OK;
978 }
void HAL_Delay(uint32_t Delay)
This function provides minimum delay (in milliseconds) based on variable incremented.
return HAL_OK

◆ USB_DevConnect() [2/2]

HAL_StatusTypeDef USB_DevConnect ( USB_TypeDef *  USBx)

USB_DevConnect : Connect the USB device by enabling the pull-up/pull-down.

Parameters
USBx: Selected device
Return values
HALstatus

Definition at line 2361 of file stm32l4xx_ll_usb.c.

2362 {
2363  /* Enabling DP Pull-UP bit to Connect internal PU resistor on USB DP line */
2364  USBx->BCDR |= USB_BCDR_DPPU;
2365 
2366  return HAL_OK;
2367 }
return HAL_OK

◆ USB_DevDisconnect() [1/2]

HAL_StatusTypeDef USB_DevDisconnect ( USB_OTG_GlobalTypeDef *  USBx)

USB_DevDisconnect : Disconnect the USB device by disabling the pull-up/pull-down.

Parameters
USBxSelected device
Return values
HALstatus

Definition at line 985 of file stm32l4xx_ll_usb.c.

986 {
987  uint32_t USBx_BASE = (uint32_t)USBx;
988 
989  USBx_DEVICE->DCTL |= USB_OTG_DCTL_SDIS;
990  HAL_Delay(3U);
991 
992  return HAL_OK;
993 }
void HAL_Delay(uint32_t Delay)
This function provides minimum delay (in milliseconds) based on variable incremented.
return HAL_OK

◆ USB_DevDisconnect() [2/2]

HAL_StatusTypeDef USB_DevDisconnect ( USB_TypeDef *  USBx)

USB_DevDisconnect : Disconnect the USB device by disabling the pull-up/pull-down.

Parameters
USBx: Selected device
Return values
HALstatus

Definition at line 2374 of file stm32l4xx_ll_usb.c.

2375 {
2376  /* Disable DP Pull-Up bit to disconnect the Internal PU resistor on USB DP line */
2377  USBx->BCDR &= (uint16_t)(~(USB_BCDR_DPPU));
2378 
2379  return HAL_OK;
2380 }
return HAL_OK

◆ USB_DevInit() [1/2]

HAL_StatusTypeDef USB_DevInit ( USB_OTG_GlobalTypeDef *  USBx,
USB_OTG_CfgTypeDef  cfg 
)

USB_DevInit : Initializes the USB_OTG controller registers for device mode.

Parameters
USBxSelected device
cfgpointer to a USB_OTG_CfgTypeDef structure that contains the configuration information for the specified USBx peripheral.
Return values
HALstatus

Definition at line 268 of file stm32l4xx_ll_usb.c.

269 {
270  HAL_StatusTypeDef ret = HAL_OK;
271  uint32_t USBx_BASE = (uint32_t)USBx;
272  uint32_t i;
273 
274  for (i = 0U; i < 15U; i++)
275  {
276  USBx->DIEPTXF[i] = 0U;
277  }
278 
279  /* VBUS Sensing setup */
280  if (cfg.vbus_sensing_enable == 0U)
281  {
282  /* Deactivate VBUS Sensing B */
283  USBx->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
284 
285  /* B-peripheral session valid override enable */
286  USBx->GOTGCTL |= USB_OTG_GOTGCTL_BVALOEN;
287  USBx->GOTGCTL |= USB_OTG_GOTGCTL_BVALOVAL;
288  }
289  else
290  {
291  /* Enable HW VBUS sensing */
292  USBx->GCCFG |= USB_OTG_GCCFG_VBDEN;
293  }
294 
295  /* Restart the Phy Clock */
296  USBx_PCGCCTL = 0U;
297 
298  /* Device mode configuration */
299  USBx_DEVICE->DCFG |= DCFG_FRAME_INTERVAL_80;
300 
301  /* Set Core speed to Full speed mode */
302  (void)USB_SetDevSpeed(USBx, USB_OTG_SPEED_FULL);
303 
304  /* Flush the FIFOs */
305  if (USB_FlushTxFifo(USBx, 0x10U) != HAL_OK) /* all Tx FIFOs */
306  {
307  ret = HAL_ERROR;
308  }
309 
310  if (USB_FlushRxFifo(USBx) != HAL_OK)
311  {
312  ret = HAL_ERROR;
313  }
314 
315  /* Clear all pending Device Interrupts */
316  USBx_DEVICE->DIEPMSK = 0U;
317  USBx_DEVICE->DOEPMSK = 0U;
318  USBx_DEVICE->DAINTMSK = 0U;
319 
320  for (i = 0U; i < cfg.dev_endpoints; i++)
321  {
322  if ((USBx_INEP(i)->DIEPCTL & USB_OTG_DIEPCTL_EPENA) == USB_OTG_DIEPCTL_EPENA)
323  {
324  if (i == 0U)
325  {
326  USBx_INEP(i)->DIEPCTL = USB_OTG_DIEPCTL_SNAK;
327  }
328  else
329  {
330  USBx_INEP(i)->DIEPCTL = USB_OTG_DIEPCTL_EPDIS | USB_OTG_DIEPCTL_SNAK;
331  }
332  }
333  else
334  {
335  USBx_INEP(i)->DIEPCTL = 0U;
336  }
337 
338  USBx_INEP(i)->DIEPTSIZ = 0U;
339  USBx_INEP(i)->DIEPINT = 0xFB7FU;
340  }
341 
342  for (i = 0U; i < cfg.dev_endpoints; i++)
343  {
344  if ((USBx_OUTEP(i)->DOEPCTL & USB_OTG_DOEPCTL_EPENA) == USB_OTG_DOEPCTL_EPENA)
345  {
346  if (i == 0U)
347  {
348  USBx_OUTEP(i)->DOEPCTL = USB_OTG_DOEPCTL_SNAK;
349  }
350  else
351  {
352  USBx_OUTEP(i)->DOEPCTL = USB_OTG_DOEPCTL_EPDIS | USB_OTG_DOEPCTL_SNAK;
353  }
354  }
355  else
356  {
357  USBx_OUTEP(i)->DOEPCTL = 0U;
358  }
359 
360  USBx_OUTEP(i)->DOEPTSIZ = 0U;
361  USBx_OUTEP(i)->DOEPINT = 0xFB7FU;
362  }
363 
364  USBx_DEVICE->DIEPMSK &= ~(USB_OTG_DIEPMSK_TXFURM);
365 
366  /* Disable all interrupts. */
367  USBx->GINTMSK = 0U;
368 
369  /* Clear any pending interrupts */
370  USBx->GINTSTS = 0xBFFFFFFFU;
371 
372  /* Enable the common interrupts */
373  USBx->GINTMSK |= USB_OTG_GINTMSK_RXFLVLM;
374 
375  /* Enable interrupts matching to the Device mode ONLY */
376  USBx->GINTMSK |= USB_OTG_GINTMSK_USBSUSPM | USB_OTG_GINTMSK_USBRST |
377  USB_OTG_GINTMSK_ENUMDNEM | USB_OTG_GINTMSK_IEPINT |
378  USB_OTG_GINTMSK_OEPINT | USB_OTG_GINTMSK_IISOIXFRM |
379  USB_OTG_GINTMSK_PXFRM_IISOOXFRM | USB_OTG_GINTMSK_WUIM;
380 
381  if (cfg.Sof_enable != 0U)
382  {
383  USBx->GINTMSK |= USB_OTG_GINTMSK_SOFM;
384  }
385 
386  if (cfg.vbus_sensing_enable == 1U)
387  {
388  USBx->GINTMSK |= (USB_OTG_GINTMSK_SRQIM | USB_OTG_GINTMSK_OTGINT);
389  }
390 
391  return ret;
392 }
HAL_StatusTypeDef USB_SetDevSpeed(USB_OTG_GlobalTypeDef *USBx, uint8_t speed)
USB_SetDevSpeed Initializes the DevSpd field of DCFG register depending the PHY type and the enumerat...
return HAL_OK
HAL_StatusTypeDef USB_FlushTxFifo(USB_OTG_GlobalTypeDef *USBx, uint32_t num)
USB_OTG_FlushTxFifo : Flush a Tx FIFO.
HAL_StatusTypeDef USB_FlushRxFifo(USB_OTG_GlobalTypeDef *USBx)
USB_FlushRxFifo : Flush Rx FIFO.

◆ USB_DevInit() [2/2]

HAL_StatusTypeDef USB_DevInit ( USB_TypeDef *  USBx,
USB_CfgTypeDef  cfg 
)

USB_DevInit : Initializes the USB controller registers for device mode.

Parameters
USBx: Selected device
cfg: pointer to a USB_CfgTypeDef structure that contains the configuration information for the specified USBx peripheral.
Return values
HALstatus

Definition at line 1884 of file stm32l4xx_ll_usb.c.

1885 {
1886  /* Prevent unused argument(s) compilation warning */
1887  UNUSED(cfg);
1888 
1889  /* Init Device */
1890  /*CNTR_FRES = 1*/
1891  USBx->CNTR = USB_CNTR_FRES;
1892 
1893  /*CNTR_FRES = 0*/
1894  USBx->CNTR = 0;
1895 
1896  /*Clear pending interrupts*/
1897  USBx->ISTR = 0;
1898 
1899  /*Set Btable Address*/
1900  USBx->BTABLE = BTABLE_ADDRESS;
1901 
1902  /* Enable USB Device Interrupt mask */
1903  (void)USB_EnableGlobalInt(USBx);
1904 
1905  return HAL_OK;
1906 }
HAL_StatusTypeDef USB_EnableGlobalInt(USB_OTG_GlobalTypeDef *USBx)
USB_EnableGlobalInt Enables the controller&#39;s Global Int in the AHB Config reg.
return HAL_OK

◆ USB_DisableGlobalInt() [1/2]

HAL_StatusTypeDef USB_DisableGlobalInt ( USB_OTG_GlobalTypeDef *  USBx)

USB_DisableGlobalInt Disable the controller's Global Int in the AHB Config reg.

Parameters
USBxSelected device
Return values
HALstatus

Definition at line 223 of file stm32l4xx_ll_usb.c.

224 {
225  USBx->GAHBCFG &= ~USB_OTG_GAHBCFG_GINT;
226  return HAL_OK;
227 }
return HAL_OK

◆ USB_DisableGlobalInt() [2/2]

HAL_StatusTypeDef USB_DisableGlobalInt ( USB_TypeDef *  USBx)

USB_DisableGlobalInt Disable the controller's Global Int in the AHB Config reg.

Parameters
USBx: Selected device
Return values
HALstatus

Definition at line 1839 of file stm32l4xx_ll_usb.c.

1840 {
1841  uint16_t winterruptmask;
1842 
1843  /* Set winterruptmask variable */
1844  winterruptmask = USB_CNTR_CTRM | USB_CNTR_WKUPM |
1845  USB_CNTR_SUSPM | USB_CNTR_ERRM |
1846  USB_CNTR_SOFM | USB_CNTR_ESOFM |
1847  USB_CNTR_RESETM | USB_CNTR_L1REQM;
1848 
1849  /* Clear interrupt mask */
1850  USBx->CNTR &= ~winterruptmask;
1851 
1852  return HAL_OK;
1853 }
return HAL_OK

◆ USB_DoPing()

HAL_StatusTypeDef USB_DoPing ( USB_OTG_GlobalTypeDef *  USBx,
uint8_t  ch_num 
)

Initiate Do Ping protocol.

Parameters
USBxSelected device
hc_numHost Channel number This parameter can be a value from 1 to 15
Return values
HALstate

Definition at line 1680 of file stm32l4xx_ll_usb.c.

1681 {
1682  uint32_t USBx_BASE = (uint32_t)USBx;
1683  uint32_t chnum = (uint32_t)ch_num;
1684  uint32_t num_packets = 1U;
1685  uint32_t tmpreg;
1686 
1687  USBx_HC(chnum)->HCTSIZ = ((num_packets << 19) & USB_OTG_HCTSIZ_PKTCNT) |
1688  USB_OTG_HCTSIZ_DOPING;
1689 
1690  /* Set host channel enable */
1691  tmpreg = USBx_HC(chnum)->HCCHAR;
1692  tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
1693  tmpreg |= USB_OTG_HCCHAR_CHENA;
1694  USBx_HC(chnum)->HCCHAR = tmpreg;
1695 
1696  return HAL_OK;
1697 }
return HAL_OK

◆ USB_DriveVbus()

HAL_StatusTypeDef USB_DriveVbus ( USB_OTG_GlobalTypeDef *  USBx,
uint8_t  state 
)

USB_DriveVbus : activate or de-activate vbus.

Parameters
stateVBUS state This parameter can be one of these values: 0 : VBUS Active 1 : VBUS Inactive
Return values
HALstatus

Definition at line 1317 of file stm32l4xx_ll_usb.c.

1318 {
1319  uint32_t USBx_BASE = (uint32_t)USBx;
1320  __IO uint32_t hprt0 = 0U;
1321 
1322  hprt0 = USBx_HPRT0;
1323 
1324  hprt0 &= ~(USB_OTG_HPRT_PENA | USB_OTG_HPRT_PCDET |
1325  USB_OTG_HPRT_PENCHNG | USB_OTG_HPRT_POCCHNG);
1326 
1327  if (((hprt0 & USB_OTG_HPRT_PPWR) == 0U) && (state == 1U))
1328  {
1329  USBx_HPRT0 = (USB_OTG_HPRT_PPWR | hprt0);
1330  }
1331  if (((hprt0 & USB_OTG_HPRT_PPWR) == USB_OTG_HPRT_PPWR) && (state == 0U))
1332  {
1333  USBx_HPRT0 = ((~USB_OTG_HPRT_PPWR) & hprt0);
1334  }
1335  return HAL_OK;
1336 }
return HAL_OK

◆ USB_EnableGlobalInt() [1/2]

HAL_StatusTypeDef USB_EnableGlobalInt ( USB_OTG_GlobalTypeDef *  USBx)

USB_EnableGlobalInt Enables the controller's Global Int in the AHB Config reg.

Parameters
USBxSelected device
Return values
HALstatus

Definition at line 211 of file stm32l4xx_ll_usb.c.

212 {
213  USBx->GAHBCFG |= USB_OTG_GAHBCFG_GINT;
214  return HAL_OK;
215 }
return HAL_OK

◆ USB_EnableGlobalInt() [2/2]

HAL_StatusTypeDef USB_EnableGlobalInt ( USB_TypeDef *  USBx)

USB_EnableGlobalInt Enables the controller's Global Int in the AHB Config reg.

Parameters
USBx: Selected device
Return values
HALstatus

Definition at line 1817 of file stm32l4xx_ll_usb.c.

1818 {
1819  uint16_t winterruptmask;
1820 
1821  /* Set winterruptmask variable */
1822  winterruptmask = USB_CNTR_CTRM | USB_CNTR_WKUPM |
1823  USB_CNTR_SUSPM | USB_CNTR_ERRM |
1824  USB_CNTR_SOFM | USB_CNTR_ESOFM |
1825  USB_CNTR_RESETM | USB_CNTR_L1REQM;
1826 
1827  /* Set interrupt mask */
1828  USBx->CNTR |= winterruptmask;
1829 
1830  return HAL_OK;
1831 }
return HAL_OK

◆ USB_EP0_OutStart() [1/2]

HAL_StatusTypeDef USB_EP0_OutStart ( USB_OTG_GlobalTypeDef *  USBx,
uint8_t *  psetup 
)

Prepare the EP0 to start the first control setup.

Parameters
USBxSelected device
psetuppointer to setup packet
Return values
HALstatus

Definition at line 1131 of file stm32l4xx_ll_usb.c.

1132 {
1133  UNUSED(psetup);
1134  uint32_t USBx_BASE = (uint32_t)USBx;
1135  uint32_t gSNPSiD = *(__IO uint32_t *)(&USBx->CID + 0x1U);
1136 
1137  if (gSNPSiD > USB_OTG_CORE_ID_300A)
1138  {
1139  if ((USBx_OUTEP(0U)->DOEPCTL & USB_OTG_DOEPCTL_EPENA) == USB_OTG_DOEPCTL_EPENA)
1140  {
1141  return HAL_OK;
1142  }
1143  }
1144 
1145  USBx_OUTEP(0U)->DOEPTSIZ = 0U;
1146  USBx_OUTEP(0U)->DOEPTSIZ |= (USB_OTG_DOEPTSIZ_PKTCNT & (1U << 19));
1147  USBx_OUTEP(0U)->DOEPTSIZ |= (3U * 8U);
1148  USBx_OUTEP(0U)->DOEPTSIZ |= USB_OTG_DOEPTSIZ_STUPCNT;
1149 
1150  return HAL_OK;
1151 }
return HAL_OK

◆ USB_EP0_OutStart() [2/2]

HAL_StatusTypeDef USB_EP0_OutStart ( USB_TypeDef *  USBx,
uint8_t *  psetup 
)

Prepare the EP0 to start the first control setup.

Parameters
USBxSelected device
psetuppointer to setup packet
Return values
HALstatus

Definition at line 2488 of file stm32l4xx_ll_usb.c.

2489 {
2490  /* Prevent unused argument(s) compilation warning */
2491  UNUSED(USBx);
2492  UNUSED(psetup);
2493  /* NOTE : - This function is not required by USB Device FS peripheral, it is used
2494  only by USB OTG FS peripheral.
2495  - This function is added to ensure compatibility across platforms.
2496  */
2497  return HAL_OK;
2498 }
return HAL_OK

◆ USB_EP0StartXfer()

HAL_StatusTypeDef USB_EP0StartXfer ( USB_OTG_GlobalTypeDef *  USBx,
USB_OTG_EPTypeDef ep 
)

USB_EP0StartXfer : setup and starts a transfer over the EP 0.

Parameters
USBxSelected device
eppointer to endpoint structure
Return values
HALstatus

Definition at line 734 of file stm32l4xx_ll_usb.c.

735 {
736  uint32_t USBx_BASE = (uint32_t)USBx;
737  uint32_t epnum = (uint32_t)ep->num;
738 
739  /* IN endpoint */
740  if (ep->is_in == 1U)
741  {
742  /* Zero Length Packet? */
743  if (ep->xfer_len == 0U)
744  {
745  USBx_INEP(epnum)->DIEPTSIZ &= ~(USB_OTG_DIEPTSIZ_PKTCNT);
746  USBx_INEP(epnum)->DIEPTSIZ |= (USB_OTG_DIEPTSIZ_PKTCNT & (1U << 19));
747  USBx_INEP(epnum)->DIEPTSIZ &= ~(USB_OTG_DIEPTSIZ_XFRSIZ);
748  }
749  else
750  {
751  /* Program the transfer size and packet count
752  * as follows: xfersize = N * maxpacket +
753  * short_packet pktcnt = N + (short_packet
754  * exist ? 1 : 0)
755  */
756  USBx_INEP(epnum)->DIEPTSIZ &= ~(USB_OTG_DIEPTSIZ_XFRSIZ);
757  USBx_INEP(epnum)->DIEPTSIZ &= ~(USB_OTG_DIEPTSIZ_PKTCNT);
758 
759  if (ep->xfer_len > ep->maxpacket)
760  {
761  ep->xfer_len = ep->maxpacket;
762  }
763  USBx_INEP(epnum)->DIEPTSIZ |= (USB_OTG_DIEPTSIZ_PKTCNT & (1U << 19));
764  USBx_INEP(epnum)->DIEPTSIZ |= (USB_OTG_DIEPTSIZ_XFRSIZ & ep->xfer_len);
765  }
766 
767  /* EP enable, IN data in FIFO */
768  USBx_INEP(epnum)->DIEPCTL |= (USB_OTG_DIEPCTL_CNAK | USB_OTG_DIEPCTL_EPENA);
769 
770  /* Enable the Tx FIFO Empty Interrupt for this EP */
771  if (ep->xfer_len > 0U)
772  {
773  USBx_DEVICE->DIEPEMPMSK |= 1UL << (ep->num & EP_ADDR_MSK);
774  }
775  }
776  else /* OUT endpoint */
777  {
778  /* Program the transfer size and packet count as follows:
779  * pktcnt = N
780  * xfersize = N * maxpacket
781  */
782  USBx_OUTEP(epnum)->DOEPTSIZ &= ~(USB_OTG_DOEPTSIZ_XFRSIZ);
783  USBx_OUTEP(epnum)->DOEPTSIZ &= ~(USB_OTG_DOEPTSIZ_PKTCNT);
784 
785  if (ep->xfer_len > 0U)
786  {
787  ep->xfer_len = ep->maxpacket;
788  }
789 
790  USBx_OUTEP(epnum)->DOEPTSIZ |= (USB_OTG_DOEPTSIZ_PKTCNT & (1U << 19));
791  USBx_OUTEP(epnum)->DOEPTSIZ |= (USB_OTG_DOEPTSIZ_XFRSIZ & (ep->maxpacket));
792 
793  /* EP enable */
794  USBx_OUTEP(epnum)->DOEPCTL |= (USB_OTG_DOEPCTL_CNAK | USB_OTG_DOEPCTL_EPENA);
795  }
796 
797  return HAL_OK;
798 }
if(lpuartdiv >=LPUART_BRR_MIN_VALUE)
return HAL_OK

◆ USB_EPClearStall() [1/2]

HAL_StatusTypeDef USB_EPClearStall ( USB_OTG_GlobalTypeDef *  USBx,
USB_OTG_EPTypeDef ep 
)

USB_EPClearStall : Clear a stall condition over an EP.

Parameters
USBxSelected device
eppointer to endpoint structure
Return values
HALstatus

Definition at line 885 of file stm32l4xx_ll_usb.c.

886 {
887  uint32_t USBx_BASE = (uint32_t)USBx;
888  uint32_t epnum = (uint32_t)ep->num;
889 
890  if (ep->is_in == 1U)
891  {
892  USBx_INEP(epnum)->DIEPCTL &= ~USB_OTG_DIEPCTL_STALL;
893  if ((ep->type == EP_TYPE_INTR) || (ep->type == EP_TYPE_BULK))
894  {
895  USBx_INEP(epnum)->DIEPCTL |= USB_OTG_DIEPCTL_SD0PID_SEVNFRM; /* DATA0 */
896  }
897  }
898  else
899  {
900  USBx_OUTEP(epnum)->DOEPCTL &= ~USB_OTG_DOEPCTL_STALL;
901  if ((ep->type == EP_TYPE_INTR) || (ep->type == EP_TYPE_BULK))
902  {
903  USBx_OUTEP(epnum)->DOEPCTL |= USB_OTG_DOEPCTL_SD0PID_SEVNFRM; /* DATA0 */
904  }
905  }
906  return HAL_OK;
907 }
if(lpuartdiv >=LPUART_BRR_MIN_VALUE)
return HAL_OK

◆ USB_EPClearStall() [2/2]

HAL_StatusTypeDef USB_EPClearStall ( USB_TypeDef *  USBx,
USB_EPTypeDef ep 
)

USB_EPClearStall : Clear a stall condition over an EP.

Parameters
USBx: Selected device
eppointer to endpoint structure
Return values
HALstatus

Definition at line 2293 of file stm32l4xx_ll_usb.c.

2294 {
2295  if (ep->doublebuffer == 0U)
2296  {
2297  if (ep->is_in != 0U)
2298  {
2299  PCD_CLEAR_TX_DTOG(USBx, ep->num);
2300 
2301  if (ep->type != EP_TYPE_ISOC)
2302  {
2303  /* Configure NAK status for the Endpoint */
2304  PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_NAK);
2305  }
2306  }
2307  else
2308  {
2309  PCD_CLEAR_RX_DTOG(USBx, ep->num);
2310 
2311  /* Configure VALID status for the Endpoint*/
2312  PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_VALID);
2313  }
2314  }
2315 
2316  return HAL_OK;
2317 }
return HAL_OK

◆ USB_EPSetStall() [1/2]

HAL_StatusTypeDef USB_EPSetStall ( USB_OTG_GlobalTypeDef *  USBx,
USB_OTG_EPTypeDef ep 
)

USB_EPSetStall : set a stall condition over an EP.

Parameters
USBxSelected device
eppointer to endpoint structure
Return values
HALstatus

Definition at line 854 of file stm32l4xx_ll_usb.c.

855 {
856  uint32_t USBx_BASE = (uint32_t)USBx;
857  uint32_t epnum = (uint32_t)ep->num;
858 
859  if (ep->is_in == 1U)
860  {
861  if (((USBx_INEP(epnum)->DIEPCTL & USB_OTG_DIEPCTL_EPENA) == 0U) && (epnum != 0U))
862  {
863  USBx_INEP(epnum)->DIEPCTL &= ~(USB_OTG_DIEPCTL_EPDIS);
864  }
865  USBx_INEP(epnum)->DIEPCTL |= USB_OTG_DIEPCTL_STALL;
866  }
867  else
868  {
869  if (((USBx_OUTEP(epnum)->DOEPCTL & USB_OTG_DOEPCTL_EPENA) == 0U) && (epnum != 0U))
870  {
871  USBx_OUTEP(epnum)->DOEPCTL &= ~(USB_OTG_DOEPCTL_EPDIS);
872  }
873  USBx_OUTEP(epnum)->DOEPCTL |= USB_OTG_DOEPCTL_STALL;
874  }
875 
876  return HAL_OK;
877 }
if(lpuartdiv >=LPUART_BRR_MIN_VALUE)
return HAL_OK

◆ USB_EPSetStall() [2/2]

HAL_StatusTypeDef USB_EPSetStall ( USB_TypeDef *  USBx,
USB_EPTypeDef ep 
)

USB_EPSetStall : set a stall condition over an EP.

Parameters
USBx: Selected device
eppointer to endpoint structure
Return values
HALstatus

Definition at line 2273 of file stm32l4xx_ll_usb.c.

2274 {
2275  if (ep->is_in != 0U)
2276  {
2277  PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_STALL);
2278  }
2279  else
2280  {
2281  PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_STALL);
2282  }
2283 
2284  return HAL_OK;
2285 }
return HAL_OK

◆ USB_EPStartXfer() [1/2]

HAL_StatusTypeDef USB_EPStartXfer ( USB_OTG_GlobalTypeDef *  USBx,
USB_OTG_EPTypeDef ep 
)

USB_EPStartXfer : setup and starts a transfer over an EP.

Parameters
USBxSelected device
eppointer to endpoint structure
Return values
HALstatus

Definition at line 630 of file stm32l4xx_ll_usb.c.

631 {
632  uint32_t USBx_BASE = (uint32_t)USBx;
633  uint32_t epnum = (uint32_t)ep->num;
634  uint16_t pktcnt;
635 
636  /* IN endpoint */
637  if (ep->is_in == 1U)
638  {
639  /* Zero Length Packet? */
640  if (ep->xfer_len == 0U)
641  {
642  USBx_INEP(epnum)->DIEPTSIZ &= ~(USB_OTG_DIEPTSIZ_PKTCNT);
643  USBx_INEP(epnum)->DIEPTSIZ |= (USB_OTG_DIEPTSIZ_PKTCNT & (1U << 19));
644  USBx_INEP(epnum)->DIEPTSIZ &= ~(USB_OTG_DIEPTSIZ_XFRSIZ);
645  }
646  else
647  {
648  /* Program the transfer size and packet count
649  * as follows: xfersize = N * maxpacket +
650  * short_packet pktcnt = N + (short_packet
651  * exist ? 1 : 0)
652  */
653  USBx_INEP(epnum)->DIEPTSIZ &= ~(USB_OTG_DIEPTSIZ_XFRSIZ);
654  USBx_INEP(epnum)->DIEPTSIZ &= ~(USB_OTG_DIEPTSIZ_PKTCNT);
655  USBx_INEP(epnum)->DIEPTSIZ |= (USB_OTG_DIEPTSIZ_PKTCNT & (((ep->xfer_len + ep->maxpacket - 1U) / ep->maxpacket) << 19));
656  USBx_INEP(epnum)->DIEPTSIZ |= (USB_OTG_DIEPTSIZ_XFRSIZ & ep->xfer_len);
657 
658  if (ep->type == EP_TYPE_ISOC)
659  {
660  USBx_INEP(epnum)->DIEPTSIZ &= ~(USB_OTG_DIEPTSIZ_MULCNT);
661  USBx_INEP(epnum)->DIEPTSIZ |= (USB_OTG_DIEPTSIZ_MULCNT & (1U << 29));
662  }
663  }
664  /* EP enable, IN data in FIFO */
665  USBx_INEP(epnum)->DIEPCTL |= (USB_OTG_DIEPCTL_CNAK | USB_OTG_DIEPCTL_EPENA);
666 
667  if (ep->type != EP_TYPE_ISOC)
668  {
669  /* Enable the Tx FIFO Empty Interrupt for this EP */
670  if (ep->xfer_len > 0U)
671  {
672  USBx_DEVICE->DIEPEMPMSK |= 1UL << (ep->num & EP_ADDR_MSK);
673  }
674  }
675  else
676  {
677  if ((USBx_DEVICE->DSTS & (1U << 8)) == 0U)
678  {
679  USBx_INEP(epnum)->DIEPCTL |= USB_OTG_DIEPCTL_SODDFRM;
680  }
681  else
682  {
683  USBx_INEP(epnum)->DIEPCTL |= USB_OTG_DIEPCTL_SD0PID_SEVNFRM;
684  }
685 
686  (void)USB_WritePacket(USBx, ep->xfer_buff, ep->num, (uint16_t)ep->xfer_len);
687  }
688  }
689  else /* OUT endpoint */
690  {
691  /* Program the transfer size and packet count as follows:
692  * pktcnt = N
693  * xfersize = N * maxpacket
694  */
695  USBx_OUTEP(epnum)->DOEPTSIZ &= ~(USB_OTG_DOEPTSIZ_XFRSIZ);
696  USBx_OUTEP(epnum)->DOEPTSIZ &= ~(USB_OTG_DOEPTSIZ_PKTCNT);
697 
698  if (ep->xfer_len == 0U)
699  {
700  USBx_OUTEP(epnum)->DOEPTSIZ |= (USB_OTG_DOEPTSIZ_XFRSIZ & ep->maxpacket);
701  USBx_OUTEP(epnum)->DOEPTSIZ |= (USB_OTG_DOEPTSIZ_PKTCNT & (1U << 19));
702  }
703  else
704  {
705  pktcnt = (uint16_t)((ep->xfer_len + ep->maxpacket - 1U) / ep->maxpacket);
706  USBx_OUTEP(epnum)->DOEPTSIZ |= USB_OTG_DOEPTSIZ_PKTCNT & ((uint32_t)pktcnt << 19);
707  USBx_OUTEP(epnum)->DOEPTSIZ |= USB_OTG_DOEPTSIZ_XFRSIZ & (ep->maxpacket * pktcnt);
708  }
709 
710  if (ep->type == EP_TYPE_ISOC)
711  {
712  if ((USBx_DEVICE->DSTS & (1U << 8)) == 0U)
713  {
714  USBx_OUTEP(epnum)->DOEPCTL |= USB_OTG_DOEPCTL_SODDFRM;
715  }
716  else
717  {
718  USBx_OUTEP(epnum)->DOEPCTL |= USB_OTG_DOEPCTL_SD0PID_SEVNFRM;
719  }
720  }
721  /* EP enable */
722  USBx_OUTEP(epnum)->DOEPCTL |= (USB_OTG_DOEPCTL_CNAK | USB_OTG_DOEPCTL_EPENA);
723  }
724 
725  return HAL_OK;
726 }
if(lpuartdiv >=LPUART_BRR_MIN_VALUE)
return HAL_OK
HAL_StatusTypeDef USB_WritePacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *src, uint8_t ch_ep_num, uint16_t len)
USB_WritePacket : Writes a packet into the Tx FIFO associated with the EP/channel.

◆ USB_EPStartXfer() [2/2]

HAL_StatusTypeDef USB_EPStartXfer ( USB_TypeDef *  USBx,
USB_EPTypeDef ep 
)

USB_EPStartXfer : setup and starts a transfer over an EP.

Parameters
USBx: Selected device
eppointer to endpoint structure
Return values
HALstatus

Definition at line 2144 of file stm32l4xx_ll_usb.c.

2145 {
2146  uint16_t pmabuffer;
2147  uint32_t len;
2148 
2149  /* IN endpoint */
2150  if (ep->is_in == 1U)
2151  {
2152  /*Multi packet transfer*/
2153  if (ep->xfer_len > ep->maxpacket)
2154  {
2155  len = ep->maxpacket;
2156  ep->xfer_len -= len;
2157  }
2158  else
2159  {
2160  len = ep->xfer_len;
2161  ep->xfer_len = 0U;
2162  }
2163 
2164  /* configure and validate Tx endpoint */
2165  if (ep->doublebuffer == 0U)
2166  {
2167  USB_WritePMA(USBx, ep->xfer_buff, ep->pmaadress, (uint16_t)len);
2168  PCD_SET_EP_TX_CNT(USBx, ep->num, len);
2169  }
2170  else
2171  {
2172  /* Write the data to the USB endpoint */
2173  if ((PCD_GET_ENDPOINT(USBx, ep->num) & USB_EP_DTOG_TX) != 0U)
2174  {
2175  /* Set the Double buffer counter for pmabuffer1 */
2176  PCD_SET_EP_DBUF1_CNT(USBx, ep->num, ep->is_in, len);
2177  pmabuffer = ep->pmaaddr1;
2178  }
2179  else
2180  {
2181  /* Set the Double buffer counter for pmabuffer0 */
2182  PCD_SET_EP_DBUF0_CNT(USBx, ep->num, ep->is_in, len);
2183  pmabuffer = ep->pmaaddr0;
2184  }
2185  USB_WritePMA(USBx, ep->xfer_buff, pmabuffer, (uint16_t)len);
2186  PCD_FreeUserBuffer(USBx, ep->num, ep->is_in);
2187  }
2188 
2189  PCD_SET_EP_TX_STATUS(USBx, ep->num, USB_EP_TX_VALID);
2190  }
2191  else /* OUT endpoint */
2192  {
2193  /* Multi packet transfer*/
2194  if (ep->xfer_len > ep->maxpacket)
2195  {
2196  len = ep->maxpacket;
2197  ep->xfer_len -= len;
2198  }
2199  else
2200  {
2201  len = ep->xfer_len;
2202  ep->xfer_len = 0U;
2203  }
2204 
2205  /* configure and validate Rx endpoint */
2206  if (ep->doublebuffer == 0U)
2207  {
2208  /*Set RX buffer count*/
2209  PCD_SET_EP_RX_CNT(USBx, ep->num, len);
2210  }
2211  else
2212  {
2213  /*Set the Double buffer counter*/
2214  PCD_SET_EP_DBUF_CNT(USBx, ep->num, ep->is_in, len);
2215  }
2216 
2217  PCD_SET_EP_RX_STATUS(USBx, ep->num, USB_EP_RX_VALID);
2218  }
2219 
2220  return HAL_OK;
2221 }
void USB_WritePMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes)
Copy a buffer from user memory area to packet memory area (PMA)
return HAL_OK
uint8_t * xfer_buff

◆ USB_FlushRxFifo() [1/2]

HAL_StatusTypeDef USB_FlushRxFifo ( USB_OTG_GlobalTypeDef *  USBx)

USB_FlushRxFifo : Flush Rx FIFO.

Parameters
USBxSelected device
Return values
HALstatus

Definition at line 425 of file stm32l4xx_ll_usb.c.

426 {
427  uint32_t count = 0;
428 
429  USBx->GRSTCTL = USB_OTG_GRSTCTL_RXFFLSH;
430 
431  do
432  {
433  if (++count > 200000U)
434  {
435  return HAL_TIMEOUT;
436  }
437  }
438  while ((USBx->GRSTCTL & USB_OTG_GRSTCTL_RXFFLSH) == USB_OTG_GRSTCTL_RXFFLSH);
439 
440  return HAL_OK;
441 }
return HAL_OK

◆ USB_FlushRxFifo() [2/2]

HAL_StatusTypeDef USB_FlushRxFifo ( USB_TypeDef *  USBx)

USB_FlushRxFifo : Flush Rx FIFO.

Parameters
USBx: Selected device
Return values
HALstatus

Definition at line 1956 of file stm32l4xx_ll_usb.c.

1957 {
1958  /* Prevent unused argument(s) compilation warning */
1959  UNUSED(USBx);
1960 
1961  /* NOTE : - This function is not required by USB Device FS peripheral, it is used
1962  only by USB OTG FS peripheral.
1963  - This function is added to ensure compatibility across platforms.
1964  */
1965 
1966  return HAL_OK;
1967 }
return HAL_OK

◆ USB_FlushTxFifo() [1/2]

HAL_StatusTypeDef USB_FlushTxFifo ( USB_OTG_GlobalTypeDef *  USBx,
uint32_t  num 
)

USB_OTG_FlushTxFifo : Flush a Tx FIFO.

Parameters
USBxSelected device
numFIFO number This parameter can be a value from 1 to 15 15 means Flush all Tx FIFOs
Return values
HALstatus

Definition at line 402 of file stm32l4xx_ll_usb.c.

403 {
404  uint32_t count = 0U;
405 
406  USBx->GRSTCTL = (USB_OTG_GRSTCTL_TXFFLSH | (num << 6));
407 
408  do
409  {
410  if (++count > 200000U)
411  {
412  return HAL_TIMEOUT;
413  }
414  }
415  while ((USBx->GRSTCTL & USB_OTG_GRSTCTL_TXFFLSH) == USB_OTG_GRSTCTL_TXFFLSH);
416 
417  return HAL_OK;
418 }
return HAL_OK

◆ USB_FlushTxFifo() [2/2]

HAL_StatusTypeDef USB_FlushTxFifo ( USB_TypeDef *  USBx,
uint32_t  num 
)

USB_FlushTxFifo : Flush a Tx FIFO.

Parameters
USBx: Selected device
num: FIFO number This parameter can be a value from 1 to 15 15 means Flush all Tx FIFOs
Return values
HALstatus

Definition at line 1937 of file stm32l4xx_ll_usb.c.

1938 {
1939  /* Prevent unused argument(s) compilation warning */
1940  UNUSED(USBx);
1941  UNUSED(num);
1942 
1943  /* NOTE : - This function is not required by USB Device FS peripheral, it is used
1944  only by USB OTG FS peripheral.
1945  - This function is added to ensure compatibility across platforms.
1946  */
1947 
1948  return HAL_OK;
1949 }
return HAL_OK

◆ USB_GetCurrentFrame()

uint32_t USB_GetCurrentFrame ( USB_OTG_GlobalTypeDef *  USBx)

Return Host Current Frame number.

Parameters
USBxSelected device
Return values
currentframe number

Definition at line 1360 of file stm32l4xx_ll_usb.c.

1361 {
1362  uint32_t USBx_BASE = (uint32_t)USBx;
1363 
1364  return (USBx_HOST->HFNUM & USB_OTG_HFNUM_FRNUM);
1365 }

◆ USB_GetDevSpeed()

uint8_t USB_GetDevSpeed ( USB_OTG_GlobalTypeDef *  USBx)

USB_GetDevSpeed Return the Dev Speed.

Parameters
USBxSelected device
Return values
speeddevice speed This parameter can be one of these values:
  • PCD_SPEED_FULL: Full speed mode

Definition at line 467 of file stm32l4xx_ll_usb.c.

468 {
469  uint32_t USBx_BASE = (uint32_t)USBx;
470  uint8_t speed;
471  uint32_t DevEnumSpeed = USBx_DEVICE->DSTS & USB_OTG_DSTS_ENUMSPD;
472 
473  if ((DevEnumSpeed == DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ) ||
474  (DevEnumSpeed == DSTS_ENUMSPD_FS_PHY_48MHZ))
475  {
476  speed = USBD_FS_SPEED;
477  }
478  else
479  {
480  speed = 0xFU;
481  }
482 
483  return speed;
484 }

◆ USB_GetHostSpeed()

uint32_t USB_GetHostSpeed ( USB_OTG_GlobalTypeDef *  USBx)

Return Host Core speed.

Parameters
USBxSelected device
Return values
speed: Host speed This parameter can be one of these values:
  • HCD_SPEED_FULL: Full speed mode
  • HCD_SPEED_LOW: Low speed mode

Definition at line 1346 of file stm32l4xx_ll_usb.c.

1347 {
1348  uint32_t USBx_BASE = (uint32_t)USBx;
1349  __IO uint32_t hprt0 = 0U;
1350 
1351  hprt0 = USBx_HPRT0;
1352  return ((hprt0 & USB_OTG_HPRT_PSPD) >> 17);
1353 }

◆ USB_GetMode()

uint32_t USB_GetMode ( USB_OTG_GlobalTypeDef *  USBx)

Returns USB core mode.

Parameters
USBxSelected device
Return values
returncore mode : Host or Device This parameter can be one of these values: 0 : Host 1 : Device

Definition at line 1099 of file stm32l4xx_ll_usb.c.

1100 {
1101  return ((USBx->GINTSTS) & 0x1U);
1102 }

◆ USB_HC_Halt()

HAL_StatusTypeDef USB_HC_Halt ( USB_OTG_GlobalTypeDef *  USBx,
uint8_t  hc_num 
)

Halt a host channel.

Parameters
USBxSelected device
hc_numHost Channel number This parameter can be a value from 1 to 15
Return values
HALstate

Definition at line 1615 of file stm32l4xx_ll_usb.c.

1616 {
1617  uint32_t USBx_BASE = (uint32_t)USBx;
1618  uint32_t hcnum = (uint32_t)hc_num;
1619  uint32_t count = 0U;
1620  uint32_t HcEpType = (USBx_HC(hcnum)->HCCHAR & USB_OTG_HCCHAR_EPTYP) >> 18;
1621 
1622  /* Check for space in the request queue to issue the halt. */
1623  if ((HcEpType == HCCHAR_CTRL) || (HcEpType == HCCHAR_BULK))
1624  {
1625  USBx_HC(hcnum)->HCCHAR |= USB_OTG_HCCHAR_CHDIS;
1626 
1627  if ((USBx->HNPTXSTS & (0xFFU << 16)) == 0U)
1628  {
1629  USBx_HC(hcnum)->HCCHAR &= ~USB_OTG_HCCHAR_CHENA;
1630  USBx_HC(hcnum)->HCCHAR |= USB_OTG_HCCHAR_CHENA;
1631  USBx_HC(hcnum)->HCCHAR &= ~USB_OTG_HCCHAR_EPDIR;
1632  do
1633  {
1634  if (++count > 1000U)
1635  {
1636  break;
1637  }
1638  }
1639  while ((USBx_HC(hcnum)->HCCHAR & USB_OTG_HCCHAR_CHENA) == USB_OTG_HCCHAR_CHENA);
1640  }
1641  else
1642  {
1643  USBx_HC(hcnum)->HCCHAR |= USB_OTG_HCCHAR_CHENA;
1644  }
1645  }
1646  else
1647  {
1648  USBx_HC(hcnum)->HCCHAR |= USB_OTG_HCCHAR_CHDIS;
1649 
1650  if ((USBx_HOST->HPTXSTS & (0xFFU << 16)) == 0U)
1651  {
1652  USBx_HC(hcnum)->HCCHAR &= ~USB_OTG_HCCHAR_CHENA;
1653  USBx_HC(hcnum)->HCCHAR |= USB_OTG_HCCHAR_CHENA;
1654  USBx_HC(hcnum)->HCCHAR &= ~USB_OTG_HCCHAR_EPDIR;
1655  do
1656  {
1657  if (++count > 1000U)
1658  {
1659  break;
1660  }
1661  }
1662  while ((USBx_HC(hcnum)->HCCHAR & USB_OTG_HCCHAR_CHENA) == USB_OTG_HCCHAR_CHENA);
1663  }
1664  else
1665  {
1666  USBx_HC(hcnum)->HCCHAR |= USB_OTG_HCCHAR_CHENA;
1667  }
1668  }
1669 
1670  return HAL_OK;
1671 }
return HAL_OK

◆ USB_HC_Init()

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.

Parameters
USBxSelected device
ch_numChannel number This parameter can be a value from 1 to 15
epnumEndpoint number This parameter can be a value from 1 to 15
dev_addressCurrent device address This parameter can be a value from 0 to 255
speedCurrent device speed This parameter can be one of these values:
  • USB_OTG_SPEED_FULL: Full speed mode
  • USB_OTG_SPEED_LOW: Low speed mode
ep_typeEndpoint Type This parameter can be one of these values:
  • EP_TYPE_CTRL: Control type
  • EP_TYPE_ISOC: Isochronous type
  • EP_TYPE_BULK: Bulk type
  • EP_TYPE_INTR: Interrupt type
mpsMax Packet Size This parameter can be a value from 0 to32K
Return values
HALstate

Definition at line 1390 of file stm32l4xx_ll_usb.c.

1397 {
1398  HAL_StatusTypeDef ret = HAL_OK;
1399  uint32_t USBx_BASE = (uint32_t)USBx;
1400  uint32_t HCcharEpDir, HCcharLowSpeed;
1401 
1402  /* Clear old interrupt conditions for this host channel. */
1403  USBx_HC((uint32_t)ch_num)->HCINT = 0xFFFFFFFFU;
1404 
1405  /* Enable channel interrupts required for this transfer. */
1406  switch (ep_type)
1407  {
1408  case EP_TYPE_CTRL:
1409  case EP_TYPE_BULK:
1410  USBx_HC((uint32_t)ch_num)->HCINTMSK = USB_OTG_HCINTMSK_XFRCM |
1411  USB_OTG_HCINTMSK_STALLM |
1412  USB_OTG_HCINTMSK_TXERRM |
1413  USB_OTG_HCINTMSK_DTERRM |
1414  USB_OTG_HCINTMSK_AHBERR |
1415  USB_OTG_HCINTMSK_NAKM;
1416 
1417  if ((epnum & 0x80U) == 0x80U)
1418  {
1419  USBx_HC((uint32_t)ch_num)->HCINTMSK |= USB_OTG_HCINTMSK_BBERRM;
1420  }
1421  break;
1422 
1423  case EP_TYPE_INTR:
1424  USBx_HC((uint32_t)ch_num)->HCINTMSK = USB_OTG_HCINTMSK_XFRCM |
1425  USB_OTG_HCINTMSK_STALLM |
1426  USB_OTG_HCINTMSK_TXERRM |
1427  USB_OTG_HCINTMSK_DTERRM |
1428  USB_OTG_HCINTMSK_NAKM |
1429  USB_OTG_HCINTMSK_AHBERR |
1430  USB_OTG_HCINTMSK_FRMORM;
1431 
1432  if ((epnum & 0x80U) == 0x80U)
1433  {
1434  USBx_HC((uint32_t)ch_num)->HCINTMSK |= USB_OTG_HCINTMSK_BBERRM;
1435  }
1436 
1437  break;
1438 
1439  case EP_TYPE_ISOC:
1440  USBx_HC((uint32_t)ch_num)->HCINTMSK = USB_OTG_HCINTMSK_XFRCM |
1441  USB_OTG_HCINTMSK_ACKM |
1442  USB_OTG_HCINTMSK_AHBERR |
1443  USB_OTG_HCINTMSK_FRMORM;
1444 
1445  if ((epnum & 0x80U) == 0x80U)
1446  {
1447  USBx_HC((uint32_t)ch_num)->HCINTMSK |= (USB_OTG_HCINTMSK_TXERRM | USB_OTG_HCINTMSK_BBERRM);
1448  }
1449  break;
1450 
1451  default:
1452  ret = HAL_ERROR;
1453  break;
1454  }
1455 
1456  /* Enable the top level host channel interrupt. */
1457  USBx_HOST->HAINTMSK |= 1UL << (ch_num & 0xFU);
1458 
1459  /* Make sure host channel interrupts are enabled. */
1460  USBx->GINTMSK |= USB_OTG_GINTMSK_HCIM;
1461 
1462  /* Program the HCCHAR register */
1463  if ((epnum & 0x80U) == 0x80U)
1464  {
1465  HCcharEpDir = (0x1U << 15) & USB_OTG_HCCHAR_EPDIR;
1466  }
1467  else
1468  {
1469  HCcharEpDir = 0U;
1470  }
1471 
1472  if (speed == HPRT0_PRTSPD_LOW_SPEED)
1473  {
1474  HCcharLowSpeed = (0x1U << 17) & USB_OTG_HCCHAR_LSDEV;
1475  }
1476  else
1477  {
1478  HCcharLowSpeed = 0U;
1479  }
1480 
1481  USBx_HC((uint32_t)ch_num)->HCCHAR = (((uint32_t)dev_address << 22) & USB_OTG_HCCHAR_DAD) |
1482  ((((uint32_t)epnum & 0x7FU) << 11) & USB_OTG_HCCHAR_EPNUM) |
1483  (((uint32_t)ep_type << 18) & USB_OTG_HCCHAR_EPTYP) |
1484  ((uint32_t)mps & USB_OTG_HCCHAR_MPSIZ) | HCcharEpDir | HCcharLowSpeed;
1485 
1486  if (ep_type == EP_TYPE_INTR)
1487  {
1488  USBx_HC((uint32_t)ch_num)->HCCHAR |= USB_OTG_HCCHAR_ODDFRM ;
1489  }
1490 
1491  return ret;
1492 }
return HAL_OK

◆ USB_HC_ReadInterrupt()

uint32_t USB_HC_ReadInterrupt ( USB_OTG_GlobalTypeDef *  USBx)

Read all host channel interrupts status.

Parameters
USBxSelected device
Return values
HALstate

Definition at line 1601 of file stm32l4xx_ll_usb.c.

1602 {
1603  uint32_t USBx_BASE = (uint32_t)USBx;
1604 
1605  return ((USBx_HOST->HAINT) & 0xFFFFU);
1606 }

◆ USB_HC_StartXfer()

HAL_StatusTypeDef USB_HC_StartXfer ( USB_OTG_GlobalTypeDef *  USBx,
USB_OTG_HCTypeDef hc 
)

Start a transfer over a host channel.

Parameters
USBxSelected device
hcpointer to host channel structure
Return values
HALstate

Definition at line 1500 of file stm32l4xx_ll_usb.c.

1501 {
1502  uint32_t USBx_BASE = (uint32_t)USBx;
1503  uint32_t ch_num = (uint32_t)hc->ch_num;
1504  static __IO uint32_t tmpreg = 0U;
1505  uint8_t is_oddframe;
1506  uint16_t len_words;
1507  uint16_t num_packets;
1508  uint16_t max_hc_pkt_count = 256U;
1509 
1510  /* Compute the expected number of packets associated to the transfer */
1511  if (hc->xfer_len > 0U)
1512  {
1513  num_packets = (uint16_t)((hc->xfer_len + hc->max_packet - 1U) / hc->max_packet);
1514 
1515  if (num_packets > max_hc_pkt_count)
1516  {
1517  num_packets = max_hc_pkt_count;
1518  hc->xfer_len = (uint32_t)num_packets * hc->max_packet;
1519  }
1520  }
1521  else
1522  {
1523  num_packets = 1U;
1524  }
1525  if (hc->ep_is_in != 0U)
1526  {
1527  hc->xfer_len = (uint32_t)num_packets * hc->max_packet;
1528  }
1529 
1530  /* Initialize the HCTSIZn register */
1531  USBx_HC(ch_num)->HCTSIZ = (hc->xfer_len & USB_OTG_HCTSIZ_XFRSIZ) |
1532  (((uint32_t)num_packets << 19) & USB_OTG_HCTSIZ_PKTCNT) |
1533  (((uint32_t)hc->data_pid << 29) & USB_OTG_HCTSIZ_DPID);
1534 
1535  is_oddframe = (((uint32_t)USBx_HOST->HFNUM & 0x01U) != 0U) ? 0U : 1U;
1536  USBx_HC(ch_num)->HCCHAR &= ~USB_OTG_HCCHAR_ODDFRM;
1537  USBx_HC(ch_num)->HCCHAR |= (uint32_t)is_oddframe << 29;
1538 
1539  /* Set host channel enable */
1540  tmpreg = USBx_HC(ch_num)->HCCHAR;
1541  tmpreg &= ~USB_OTG_HCCHAR_CHDIS;
1542 
1543  /* make sure to set the correct ep direction */
1544  if (hc->ep_is_in != 0U)
1545  {
1546  tmpreg |= USB_OTG_HCCHAR_EPDIR;
1547  }
1548  else
1549  {
1550  tmpreg &= ~USB_OTG_HCCHAR_EPDIR;
1551  }
1552  tmpreg |= USB_OTG_HCCHAR_CHENA;
1553  USBx_HC(ch_num)->HCCHAR = tmpreg;
1554 
1555  if ((hc->ep_is_in == 0U) && (hc->xfer_len > 0U))
1556  {
1557  switch (hc->ep_type)
1558  {
1559  /* Non periodic transfer */
1560  case EP_TYPE_CTRL:
1561  case EP_TYPE_BULK:
1562 
1563  len_words = (uint16_t)((hc->xfer_len + 3U) / 4U);
1564 
1565  /* check if there is enough space in FIFO space */
1566  if (len_words > (USBx->HNPTXSTS & 0xFFFFU))
1567  {
1568  /* need to process data in nptxfempty interrupt */
1569  USBx->GINTMSK |= USB_OTG_GINTMSK_NPTXFEM;
1570  }
1571  break;
1572 
1573  /* Periodic transfer */
1574  case EP_TYPE_INTR:
1575  case EP_TYPE_ISOC:
1576  len_words = (uint16_t)((hc->xfer_len + 3U) / 4U);
1577  /* check if there is enough space in FIFO space */
1578  if (len_words > (USBx_HOST->HPTXSTS & 0xFFFFU)) /* split the transfer */
1579  {
1580  /* need to process data in ptxfempty interrupt */
1581  USBx->GINTMSK |= USB_OTG_GINTMSK_PTXFEM;
1582  }
1583  break;
1584 
1585  default:
1586  break;
1587  }
1588 
1589  /* Write packet into the Tx FIFO. */
1590  (void)USB_WritePacket(USBx, hc->xfer_buff, hc->ch_num, (uint16_t)hc->xfer_len);
1591  }
1592 
1593  return HAL_OK;
1594 }
if(lpuartdiv >=LPUART_BRR_MIN_VALUE)
return HAL_OK
HAL_StatusTypeDef USB_WritePacket(USB_OTG_GlobalTypeDef *USBx, uint8_t *src, uint8_t ch_ep_num, uint16_t len)
USB_WritePacket : Writes a packet into the Tx FIFO associated with the EP/channel.

◆ USB_HostInit()

HAL_StatusTypeDef USB_HostInit ( USB_OTG_GlobalTypeDef *  USBx,
USB_OTG_CfgTypeDef  cfg 
)

USB_HostInit : Initializes the USB OTG controller registers for Host mode.

Parameters
USBxSelected device
cfgpointer to a USB_OTG_CfgTypeDef structure that contains the configuration information for the specified USBx peripheral.
Return values
HALstatus

Definition at line 1196 of file stm32l4xx_ll_usb.c.

1197 {
1198  uint32_t USBx_BASE = (uint32_t)USBx;
1199  uint32_t i;
1200 
1201  /* Restart the Phy Clock */
1202  USBx_PCGCCTL = 0U;
1203 
1204  /* Disable VBUS sensing */
1205  USBx->GCCFG &= ~(USB_OTG_GCCFG_VBDEN);
1206 
1207  /* Disable Battery chargin detector */
1208  USBx->GCCFG &= ~(USB_OTG_GCCFG_BCDEN);
1209 
1210  /* Set default Max speed support */
1211  USBx_HOST->HCFG &= ~(USB_OTG_HCFG_FSLSS);
1212 
1213  /* Make sure the FIFOs are flushed. */
1214  (void)USB_FlushTxFifo(USBx, 0x10U); /* all Tx FIFOs */
1215  (void)USB_FlushRxFifo(USBx);
1216 
1217  /* Clear all pending HC Interrupts */
1218  for (i = 0U; i < cfg.Host_channels; i++)
1219  {
1220  USBx_HC(i)->HCINT = 0xFFFFFFFFU;
1221  USBx_HC(i)->HCINTMSK = 0U;
1222  }
1223 
1224  /* Enable VBUS driving */
1225  (void)USB_DriveVbus(USBx, 1U);
1226 
1227  HAL_Delay(200U);
1228 
1229  /* Disable all interrupts. */
1230  USBx->GINTMSK = 0U;
1231 
1232  /* Clear any pending interrupts */
1233  USBx->GINTSTS = 0xFFFFFFFFU;
1234 
1235  /* set Rx FIFO size */
1236  USBx->GRXFSIZ = 0x80U;
1237  USBx->DIEPTXF0_HNPTXFSIZ = (uint32_t)(((0x60U << 16) & USB_OTG_NPTXFD) | 0x80U);
1238  USBx->HPTXFSIZ = (uint32_t)(((0x40U << 16)& USB_OTG_HPTXFSIZ_PTXFD) | 0xE0U);
1239  /* Enable the common interrupts */
1240  USBx->GINTMSK |= USB_OTG_GINTMSK_RXFLVLM;
1241 
1242  /* Enable interrupts matching to the Host mode ONLY */
1243  USBx->GINTMSK |= (USB_OTG_GINTMSK_PRTIM | USB_OTG_GINTMSK_HCIM | \
1244  USB_OTG_GINTMSK_SOFM | USB_OTG_GINTSTS_DISCINT | \
1245  USB_OTG_GINTMSK_PXFRM_IISOOXFRM | USB_OTG_GINTMSK_WUIM);
1246 
1247  return HAL_OK;
1248 }
HAL_StatusTypeDef USB_DriveVbus(USB_OTG_GlobalTypeDef *USBx, uint8_t state)
USB_DriveVbus : activate or de-activate vbus.
void HAL_Delay(uint32_t Delay)
This function provides minimum delay (in milliseconds) based on variable incremented.
return HAL_OK
HAL_StatusTypeDef USB_FlushTxFifo(USB_OTG_GlobalTypeDef *USBx, uint32_t num)
USB_OTG_FlushTxFifo : Flush a Tx FIFO.
HAL_StatusTypeDef USB_FlushRxFifo(USB_OTG_GlobalTypeDef *USBx)
USB_FlushRxFifo : Flush Rx FIFO.

◆ USB_InitFSLSPClkSel()

HAL_StatusTypeDef USB_InitFSLSPClkSel ( USB_OTG_GlobalTypeDef *  USBx,
uint8_t  freq 
)

USB_InitFSLSPClkSel : Initializes the FSLSPClkSel field of the HCFG register on the PHY type and set the right frame interval.

Parameters
USBxSelected device
freqclock frequency This parameter can be one of these values: HCFG_48_MHZ : Full Speed 48 MHz Clock HCFG_6_MHZ : Low Speed 6 MHz Clock
Return values
HALstatus

Definition at line 1260 of file stm32l4xx_ll_usb.c.

1261 {
1262  uint32_t USBx_BASE = (uint32_t)USBx;
1263 
1264  USBx_HOST->HCFG &= ~(USB_OTG_HCFG_FSLSPCS);
1265  USBx_HOST->HCFG |= (uint32_t)freq & USB_OTG_HCFG_FSLSPCS;
1266 
1267  if (freq == HCFG_48_MHZ)
1268  {
1269  USBx_HOST->HFIR = 48000U;
1270  }
1271  else if (freq == HCFG_6_MHZ)
1272  {
1273  USBx_HOST->HFIR = 6000U;
1274  }
1275  else
1276  {
1277  /* ... */
1278  }
1279 
1280  return HAL_OK;
1281 }
return HAL_OK

◆ USB_ReadDevAllInEpInterrupt() [1/2]

uint32_t USB_ReadDevAllInEpInterrupt ( USB_OTG_GlobalTypeDef *  USBx)

USB_ReadDevAllInEpInterrupt: return the USB device IN endpoints interrupt status.

Parameters
USBxSelected device
Return values
HALstatus

Definition at line 1031 of file stm32l4xx_ll_usb.c.

1032 {
1033  uint32_t USBx_BASE = (uint32_t)USBx;
1034  uint32_t tmpreg;
1035 
1036  tmpreg = USBx_DEVICE->DAINT;
1037  tmpreg &= USBx_DEVICE->DAINTMSK;
1038 
1039  return ((tmpreg & 0xFFFFU));
1040 }

◆ USB_ReadDevAllInEpInterrupt() [2/2]

uint32_t USB_ReadDevAllInEpInterrupt ( USB_TypeDef *  USBx)

USB_ReadDevAllInEpInterrupt: return the USB device IN endpoints interrupt status.

Parameters
USBx: Selected device
Return values
HALstatus

Definition at line 2416 of file stm32l4xx_ll_usb.c.

2417 {
2418  /* Prevent unused argument(s) compilation warning */
2419  UNUSED(USBx);
2420  /* NOTE : - This function is not required by USB Device FS peripheral, it is used
2421  only by USB OTG FS peripheral.
2422  - This function is added to ensure compatibility across platforms.
2423  */
2424  return (0);
2425 }

◆ USB_ReadDevAllOutEpInterrupt() [1/2]

uint32_t USB_ReadDevAllOutEpInterrupt ( USB_OTG_GlobalTypeDef *  USBx)

USB_ReadDevAllOutEpInterrupt: return the USB device OUT endpoints interrupt status.

Parameters
USBxSelected device
Return values
HALstatus

Definition at line 1015 of file stm32l4xx_ll_usb.c.

1016 {
1017  uint32_t USBx_BASE = (uint32_t)USBx;
1018  uint32_t tmpreg;
1019 
1020  tmpreg = USBx_DEVICE->DAINT;
1021  tmpreg &= USBx_DEVICE->DAINTMSK;
1022 
1023  return ((tmpreg & 0xffff0000U) >> 16);
1024 }

◆ USB_ReadDevAllOutEpInterrupt() [2/2]

uint32_t USB_ReadDevAllOutEpInterrupt ( USB_TypeDef *  USBx)

USB_ReadDevAllOutEpInterrupt: return the USB device OUT endpoints interrupt status.

Parameters
USBx: Selected device
Return values
HALstatus

Definition at line 2400 of file stm32l4xx_ll_usb.c.

2401 {
2402  /* Prevent unused argument(s) compilation warning */
2403  UNUSED(USBx);
2404  /* NOTE : - This function is not required by USB Device FS peripheral, it is used
2405  only by USB OTG FS peripheral.
2406  - This function is added to ensure compatibility across platforms.
2407  */
2408  return (0);
2409 }

◆ USB_ReadDevInEPInterrupt() [1/2]

uint32_t USB_ReadDevInEPInterrupt ( USB_OTG_GlobalTypeDef *  USBx,
uint8_t  epnum 
)

Returns Device IN EP Interrupt register.

Parameters
USBxSelected device
epnumendpoint number This parameter can be a value from 0 to 15
Return values
DeviceIN EP Interrupt register

Definition at line 1067 of file stm32l4xx_ll_usb.c.

1068 {
1069  uint32_t USBx_BASE = (uint32_t)USBx;
1070  uint32_t tmpreg, msk, emp;
1071 
1072  msk = USBx_DEVICE->DIEPMSK;
1073  emp = USBx_DEVICE->DIEPEMPMSK;
1074  msk |= ((emp >> (epnum & EP_ADDR_MSK)) & 0x1U) << 7;
1075  tmpreg = USBx_INEP((uint32_t)epnum)->DIEPINT & msk;
1076 
1077  return tmpreg;
1078 }

◆ USB_ReadDevInEPInterrupt() [2/2]

uint32_t USB_ReadDevInEPInterrupt ( USB_TypeDef *  USBx,
uint8_t  epnum 
)

Returns Device IN EP Interrupt register.

Parameters
USBx: Selected device
epnum: endpoint number This parameter can be a value from 0 to 15
Return values
DeviceIN EP Interrupt register

Definition at line 2453 of file stm32l4xx_ll_usb.c.

2454 {
2455  /* Prevent unused argument(s) compilation warning */
2456  UNUSED(USBx);
2457  UNUSED(epnum);
2458  /* NOTE : - This function is not required by USB Device FS peripheral, it is used
2459  only by USB OTG FS peripheral.
2460  - This function is added to ensure compatibility across platforms.
2461  */
2462  return (0);
2463 }

◆ USB_ReadDevOutEPInterrupt() [1/2]

uint32_t USB_ReadDevOutEPInterrupt ( USB_OTG_GlobalTypeDef *  USBx,
uint8_t  epnum 
)

Returns Device OUT EP Interrupt register.

Parameters
USBxSelected device
epnumendpoint number This parameter can be a value from 0 to 15
Return values
DeviceOUT EP Interrupt register

Definition at line 1049 of file stm32l4xx_ll_usb.c.

1050 {
1051  uint32_t USBx_BASE = (uint32_t)USBx;
1052  uint32_t tmpreg;
1053 
1054  tmpreg = USBx_OUTEP((uint32_t)epnum)->DOEPINT;
1055  tmpreg &= USBx_DEVICE->DOEPMSK;
1056 
1057  return tmpreg;
1058 }

◆ USB_ReadDevOutEPInterrupt() [2/2]

uint32_t USB_ReadDevOutEPInterrupt ( USB_TypeDef *  USBx,
uint8_t  epnum 
)

Returns Device OUT EP Interrupt register.

Parameters
USBx: Selected device
epnum: endpoint number This parameter can be a value from 0 to 15
Return values
DeviceOUT EP Interrupt register

Definition at line 2434 of file stm32l4xx_ll_usb.c.

2435 {
2436  /* Prevent unused argument(s) compilation warning */
2437  UNUSED(USBx);
2438  UNUSED(epnum);
2439  /* NOTE : - This function is not required by USB Device FS peripheral, it is used
2440  only by USB OTG FS peripheral.
2441  - This function is added to ensure compatibility across platforms.
2442  */
2443  return (0);
2444 }

◆ USB_ReadInterrupts() [1/2]

uint32_t USB_ReadInterrupts ( USB_OTG_GlobalTypeDef *  USBx)

USB_ReadInterrupts: return the global USB interrupt status.

Parameters
USBxSelected device
Return values
HALstatus

Definition at line 1000 of file stm32l4xx_ll_usb.c.

1001 {
1002  uint32_t tmpreg;
1003 
1004  tmpreg = USBx->GINTSTS;
1005  tmpreg &= USBx->GINTMSK;
1006 
1007  return tmpreg;
1008 }

◆ USB_ReadInterrupts() [2/2]

uint32_t USB_ReadInterrupts ( USB_TypeDef *  USBx)

USB_ReadInterrupts: return the global USB interrupt status.

Parameters
USBx: Selected device
Return values
HALstatus

Definition at line 2387 of file stm32l4xx_ll_usb.c.

2388 {
2389  uint32_t tmpreg;
2390 
2391  tmpreg = USBx->ISTR;
2392  return tmpreg;
2393 }

◆ USB_ReadPacket() [1/2]

void* USB_ReadPacket ( USB_OTG_GlobalTypeDef *  USBx,
uint8_t *  dest,
uint16_t  len 
)

USB_ReadPacket : read a packet from the RX FIFO.

Parameters
USBxSelected device
destsource pointer
lenNumber of bytes to read
Return values
pointerto destination buffer

Definition at line 832 of file stm32l4xx_ll_usb.c.

833 {
834  uint32_t USBx_BASE = (uint32_t)USBx;
835  uint32_t *pDest = (uint32_t *)dest;
836  uint32_t i;
837  uint32_t count32b = ((uint32_t)len + 3U) / 4U;
838 
839  for (i = 0U; i < count32b; i++)
840  {
841  __UNALIGNED_UINT32_WRITE(pDest, USBx_DFIFO(0U));
842  pDest++;
843  }
844 
845  return ((void *)pDest);
846 }

◆ USB_ReadPacket() [2/2]

void* USB_ReadPacket ( USB_TypeDef *  USBx,
uint8_t *  dest,
uint16_t  len 
)

USB_ReadPacket : read a packet from the Tx FIFO associated with the EP/channel.

Parameters
USBx: Selected device
dest: destination pointer
len: Number of bytes to read
Return values
pointerto destination buffer

Definition at line 2254 of file stm32l4xx_ll_usb.c.

2255 {
2256  /* Prevent unused argument(s) compilation warning */
2257  UNUSED(USBx);
2258  UNUSED(dest);
2259  UNUSED(len);
2260  /* NOTE : - This function is not required by USB Device FS peripheral, it is used
2261  only by USB OTG FS peripheral.
2262  - This function is added to ensure compatibility across platforms.
2263  */
2264  return ((void *)NULL);
2265 }

◆ USB_ReadPMA()

void USB_ReadPMA ( USB_TypeDef *  USBx,
uint8_t *  pbUsrBuf,
uint16_t  wPMABufAddr,
uint16_t  wNBytes 
)

Copy a buffer from user memory area to packet memory area (PMA)

Parameters
USBxUSB peripheral instance register address.
pbUsrBufpointer to user memory area.
wPMABufAddraddress into PMA.
wNBytesno. of bytes to be copied.
Return values
None

Definition at line 2565 of file stm32l4xx_ll_usb.c.

2566 {
2567  uint32_t n = (uint32_t)wNBytes >> 1;
2568  uint32_t BaseAddr = (uint32_t)USBx;
2569  uint32_t i, temp;
2570  uint16_t *pdwVal;
2571  uint8_t *pBuf = pbUsrBuf;
2572 
2573  pdwVal = (uint16_t *)(BaseAddr + 0x400U + ((uint32_t)wPMABufAddr * PMA_ACCESS));
2574 
2575  for (i = n; i != 0U; i--)
2576  {
2577  temp = *pdwVal;
2578  pdwVal++;
2579  *pBuf = (uint8_t)((temp >> 0) & 0xFFU);
2580  pBuf++;
2581  *pBuf = (uint8_t)((temp >> 8) & 0xFFU);
2582  pBuf++;
2583 
2584 #if PMA_ACCESS > 1U
2585  pdwVal++;
2586 #endif
2587  }
2588 
2589  if ((wNBytes % 2U) != 0U)
2590  {
2591  temp = *pdwVal;
2592  *pBuf = (uint8_t)((temp >> 0) & 0xFFU);
2593  }
2594 }

◆ USB_ResetPort()

HAL_StatusTypeDef USB_ResetPort ( USB_OTG_GlobalTypeDef *  USBx)

USB_OTG_ResetPort : Reset Host Port.

Parameters
USBxSelected device
Return values
HALstatus
Note
(1)The application must wait at least 10 ms before clearing the reset bit.

Definition at line 1290 of file stm32l4xx_ll_usb.c.

1291 {
1292  uint32_t USBx_BASE = (uint32_t)USBx;
1293 
1294  __IO uint32_t hprt0 = 0U;
1295 
1296  hprt0 = USBx_HPRT0;
1297 
1298  hprt0 &= ~(USB_OTG_HPRT_PENA | USB_OTG_HPRT_PCDET |
1299  USB_OTG_HPRT_PENCHNG | USB_OTG_HPRT_POCCHNG);
1300 
1301  USBx_HPRT0 = (USB_OTG_HPRT_PRST | hprt0);
1302  HAL_Delay(100U); /* See Note #1 */
1303  USBx_HPRT0 = ((~USB_OTG_HPRT_PRST) & hprt0);
1304  HAL_Delay(10U);
1305 
1306  return HAL_OK;
1307 }
void HAL_Delay(uint32_t Delay)
This function provides minimum delay (in milliseconds) based on variable incremented.
return HAL_OK

◆ USB_SetCurrentMode() [1/2]

HAL_StatusTypeDef USB_SetCurrentMode ( USB_OTG_GlobalTypeDef *  USBx,
USB_ModeTypeDef  mode 
)

USB_SetCurrentMode : Set functional mode.

Parameters
USBxSelected device
modecurrent core mode This parameter can be one of these values:
  • USB_DEVICE_MODE: Peripheral mode
  • USB_HOST_MODE: Host mode
  • USB_DRD_MODE: Dual Role Device mode
Return values
HALstatus

Definition at line 239 of file stm32l4xx_ll_usb.c.

240 {
241  USBx->GUSBCFG &= ~(USB_OTG_GUSBCFG_FHMOD | USB_OTG_GUSBCFG_FDMOD);
242 
243  if (mode == USB_HOST_MODE)
244  {
245  USBx->GUSBCFG |= USB_OTG_GUSBCFG_FHMOD;
246  }
247  else if (mode == USB_DEVICE_MODE)
248  {
249  USBx->GUSBCFG |= USB_OTG_GUSBCFG_FDMOD;
250  }
251  else
252  {
253  return HAL_ERROR;
254  }
255  HAL_Delay(50U);
256 
257  return HAL_OK;
258 }
void HAL_Delay(uint32_t Delay)
This function provides minimum delay (in milliseconds) based on variable incremented.
return HAL_OK

◆ USB_SetCurrentMode() [2/2]

HAL_StatusTypeDef USB_SetCurrentMode ( USB_TypeDef *  USBx,
USB_ModeTypeDef  mode 
)

USB_SetCurrentMode : Set functional mode.

Parameters
USBx: Selected device
mode: current core mode This parameter can be one of the these values:
  • USB_DEVICE_MODE: Peripheral mode mode
Return values
HALstatus

Definition at line 1863 of file stm32l4xx_ll_usb.c.

1864 {
1865  /* Prevent unused argument(s) compilation warning */
1866  UNUSED(USBx);
1867  UNUSED(mode);
1868 
1869  /* NOTE : - This function is not required by USB Device FS peripheral, it is used
1870  only by USB OTG FS peripheral.
1871  - This function is added to ensure compatibility across platforms.
1872  */
1873  return HAL_OK;
1874 }
return HAL_OK

◆ USB_SetDevAddress() [1/2]

HAL_StatusTypeDef USB_SetDevAddress ( USB_OTG_GlobalTypeDef *  USBx,
uint8_t  address 
)

USB_SetDevAddress : Stop the usb device mode.

Parameters
USBxSelected device
addressnew device address to be assigned This parameter can be a value from 0 to 255
Return values
HALstatus

Definition at line 955 of file stm32l4xx_ll_usb.c.

956 {
957  uint32_t USBx_BASE = (uint32_t)USBx;
958 
959  USBx_DEVICE->DCFG &= ~(USB_OTG_DCFG_DAD);
960  USBx_DEVICE->DCFG |= ((uint32_t)address << 4) & USB_OTG_DCFG_DAD;
961 
962  return HAL_OK;
963 }
return HAL_OK

◆ USB_SetDevAddress() [2/2]

HAL_StatusTypeDef USB_SetDevAddress ( USB_TypeDef *  USBx,
uint8_t  address 
)

USB_SetDevAddress : Stop the usb device mode.

Parameters
USBx: Selected device
address: new device address to be assigned This parameter can be a value from 0 to 255
Return values
HALstatus

Definition at line 2345 of file stm32l4xx_ll_usb.c.

2346 {
2347  if (address == 0U)
2348  {
2349  /* set device address and enable function */
2350  USBx->DADDR = USB_DADDR_EF;
2351  }
2352 
2353  return HAL_OK;
2354 }
return HAL_OK

◆ USB_SetDevSpeed() [1/2]

HAL_StatusTypeDef USB_SetDevSpeed ( USB_OTG_GlobalTypeDef *  USBx,
uint8_t  speed 
)

USB_SetDevSpeed Initializes the DevSpd field of DCFG register depending the PHY type and the enumeration speed of the device.

Parameters
USBxSelected device
speeddevice speed This parameter can be one of these values:
  • USB_OTG_SPEED_FULL: Full speed mode
Return values
Halstatus

Definition at line 452 of file stm32l4xx_ll_usb.c.

453 {
454  uint32_t USBx_BASE = (uint32_t)USBx;
455 
456  USBx_DEVICE->DCFG |= speed;
457  return HAL_OK;
458 }
return HAL_OK

◆ USB_SetDevSpeed() [2/2]

HAL_StatusTypeDef USB_SetDevSpeed ( USB_TypeDef *  USBx,
uint8_t  speed 
)

USB_SetDevSpeed :Initializes the device speed depending on the PHY type and the enumeration speed of the device.

Parameters
USBxSelected device
speeddevice speed
Return values
Halstatus

Definition at line 1915 of file stm32l4xx_ll_usb.c.

1916 {
1917  /* Prevent unused argument(s) compilation warning */
1918  UNUSED(USBx);
1919  UNUSED(speed);
1920 
1921  /* NOTE : - This function is not required by USB Device FS peripheral, it is used
1922  only by USB OTG FS peripheral.
1923  - This function is added to ensure compatibility across platforms.
1924  */
1925 
1926  return HAL_OK;
1927 }
return HAL_OK

◆ USB_SetTurnaroundTime()

HAL_StatusTypeDef USB_SetTurnaroundTime ( USB_OTG_GlobalTypeDef *  USBx,
uint32_t  hclk,
uint8_t  speed 
)

Set the USB turnaround time.

Parameters
USBxUSB Instance
hclkAHB clock frequency
Return values
USBturnaround time In PHY Clocks number

Definition at line 132 of file stm32l4xx_ll_usb.c.

134 {
135  uint32_t UsbTrd;
136 
137  /* The USBTRD is configured according to the tables below, depending on AHB frequency
138  used by application. In the low AHB frequency range it is used to stretch enough the USB response
139  time to IN tokens, the USB turnaround time, so to compensate for the longer AHB read access
140  latency to the Data FIFO */
141  if (speed == USBD_FS_SPEED)
142  {
143  if ((hclk >= 14200000U) && (hclk < 15000000U))
144  {
145  /* hclk Clock Range between 14.2-15 MHz */
146  UsbTrd = 0xFU;
147  }
148  else if ((hclk >= 15000000U) && (hclk < 16000000U))
149  {
150  /* hclk Clock Range between 15-16 MHz */
151  UsbTrd = 0xEU;
152  }
153  else if ((hclk >= 16000000U) && (hclk < 17200000U))
154  {
155  /* hclk Clock Range between 16-17.2 MHz */
156  UsbTrd = 0xDU;
157  }
158  else if ((hclk >= 17200000U) && (hclk < 18500000U))
159  {
160  /* hclk Clock Range between 17.2-18.5 MHz */
161  UsbTrd = 0xCU;
162  }
163  else if ((hclk >= 18500000U) && (hclk < 20000000U))
164  {
165  /* hclk Clock Range between 18.5-20 MHz */
166  UsbTrd = 0xBU;
167  }
168  else if ((hclk >= 20000000U) && (hclk < 21800000U))
169  {
170  /* hclk Clock Range between 20-21.8 MHz */
171  UsbTrd = 0xAU;
172  }
173  else if ((hclk >= 21800000U) && (hclk < 24000000U))
174  {
175  /* hclk Clock Range between 21.8-24 MHz */
176  UsbTrd = 0x9U;
177  }
178  else if ((hclk >= 24000000U) && (hclk < 27700000U))
179  {
180  /* hclk Clock Range between 24-27.7 MHz */
181  UsbTrd = 0x8U;
182  }
183  else if ((hclk >= 27700000U) && (hclk < 32000000U))
184  {
185  /* hclk Clock Range between 27.7-32 MHz */
186  UsbTrd = 0x7U;
187  }
188  else /* if(hclk >= 32000000) */
189  {
190  /* hclk Clock Range between 32-200 MHz */
191  UsbTrd = 0x6U;
192  }
193  }
194  else
195  {
196  UsbTrd = USBD_DEFAULT_TRDT_VALUE;
197  }
198 
199  USBx->GUSBCFG &= ~USB_OTG_GUSBCFG_TRDT;
200  USBx->GUSBCFG |= (uint32_t)((UsbTrd << 10) & USB_OTG_GUSBCFG_TRDT);
201 
202  return HAL_OK;
203 }
return HAL_OK

◆ USB_StopDevice() [1/2]

HAL_StatusTypeDef USB_StopDevice ( USB_OTG_GlobalTypeDef *  USBx)

USB_StopDevice : Stop the usb device mode.

Parameters
USBxSelected device
Return values
HALstatus

Definition at line 914 of file stm32l4xx_ll_usb.c.

915 {
916  HAL_StatusTypeDef ret;
917  uint32_t USBx_BASE = (uint32_t)USBx;
918  uint32_t i;
919 
920  /* Clear Pending interrupt */
921  for (i = 0U; i < 15U; i++)
922  {
923  USBx_INEP(i)->DIEPINT = 0xFB7FU;
924  USBx_OUTEP(i)->DOEPINT = 0xFB7FU;
925  }
926 
927  /* Clear interrupt masks */
928  USBx_DEVICE->DIEPMSK = 0U;
929  USBx_DEVICE->DOEPMSK = 0U;
930  USBx_DEVICE->DAINTMSK = 0U;
931 
932  /* Flush the FIFO */
933  ret = USB_FlushRxFifo(USBx);
934  if (ret != HAL_OK)
935  {
936  return ret;
937  }
938 
939  ret = USB_FlushTxFifo(USBx, 0x10U);
940  if (ret != HAL_OK)
941  {
942  return ret;
943  }
944 
945  return ret;
946 }
return HAL_OK
HAL_StatusTypeDef USB_FlushTxFifo(USB_OTG_GlobalTypeDef *USBx, uint32_t num)
USB_OTG_FlushTxFifo : Flush a Tx FIFO.
HAL_StatusTypeDef USB_FlushRxFifo(USB_OTG_GlobalTypeDef *USBx)
USB_FlushRxFifo : Flush Rx FIFO.

◆ USB_StopDevice() [2/2]

HAL_StatusTypeDef USB_StopDevice ( USB_TypeDef *  USBx)

USB_StopDevice : Stop the usb device mode.

Parameters
USBx: Selected device
Return values
HALstatus

Definition at line 2324 of file stm32l4xx_ll_usb.c.

2325 {
2326  /* disable all interrupts and force USB reset */
2327  USBx->CNTR = USB_CNTR_FRES;
2328 
2329  /* clear interrupt status register */
2330  USBx->ISTR = 0;
2331 
2332  /* switch-off device */
2333  USBx->CNTR = (USB_CNTR_FRES | USB_CNTR_PDWN);
2334 
2335  return HAL_OK;
2336 }
return HAL_OK

◆ USB_StopHost()

HAL_StatusTypeDef USB_StopHost ( USB_OTG_GlobalTypeDef *  USBx)

Stop Host Core.

Parameters
USBxSelected device
Return values
HALstate

Definition at line 1704 of file stm32l4xx_ll_usb.c.

1705 {
1706  uint32_t USBx_BASE = (uint32_t)USBx;
1707  uint32_t count = 0U;
1708  uint32_t value;
1709  uint32_t i;
1710 
1711 
1712  (void)USB_DisableGlobalInt(USBx);
1713 
1714  /* Flush FIFO */
1715  (void)USB_FlushTxFifo(USBx, 0x10U);
1716  (void)USB_FlushRxFifo(USBx);
1717 
1718  /* Flush out any leftover queued requests. */
1719  for (i = 0U; i <= 15U; i++)
1720  {
1721  value = USBx_HC(i)->HCCHAR;
1722  value |= USB_OTG_HCCHAR_CHDIS;
1723  value &= ~USB_OTG_HCCHAR_CHENA;
1724  value &= ~USB_OTG_HCCHAR_EPDIR;
1725  USBx_HC(i)->HCCHAR = value;
1726  }
1727 
1728  /* Halt all channels to put them into a known state. */
1729  for (i = 0U; i <= 15U; i++)
1730  {
1731  value = USBx_HC(i)->HCCHAR;
1732  value |= USB_OTG_HCCHAR_CHDIS;
1733  value |= USB_OTG_HCCHAR_CHENA;
1734  value &= ~USB_OTG_HCCHAR_EPDIR;
1735  USBx_HC(i)->HCCHAR = value;
1736 
1737  do
1738  {
1739  if (++count > 1000U)
1740  {
1741  break;
1742  }
1743  }
1744  while ((USBx_HC(i)->HCCHAR & USB_OTG_HCCHAR_CHENA) == USB_OTG_HCCHAR_CHENA);
1745  }
1746 
1747  /* Clear any pending Host interrupts */
1748  USBx_HOST->HAINT = 0xFFFFFFFFU;
1749  USBx->GINTSTS = 0xFFFFFFFFU;
1750  (void)USB_EnableGlobalInt(USBx);
1751 
1752  return HAL_OK;
1753 }
HAL_StatusTypeDef USB_EnableGlobalInt(USB_OTG_GlobalTypeDef *USBx)
USB_EnableGlobalInt Enables the controller&#39;s Global Int in the AHB Config reg.
HAL_StatusTypeDef USB_DisableGlobalInt(USB_OTG_GlobalTypeDef *USBx)
USB_DisableGlobalInt Disable the controller&#39;s Global Int in the AHB Config reg.
return HAL_OK
HAL_StatusTypeDef USB_FlushTxFifo(USB_OTG_GlobalTypeDef *USBx, uint32_t num)
USB_OTG_FlushTxFifo : Flush a Tx FIFO.
HAL_StatusTypeDef USB_FlushRxFifo(USB_OTG_GlobalTypeDef *USBx)
USB_FlushRxFifo : Flush Rx FIFO.

◆ USB_WritePacket() [1/2]

HAL_StatusTypeDef USB_WritePacket ( USB_OTG_GlobalTypeDef *  USBx,
uint8_t *  src,
uint8_t  ch_ep_num,
uint16_t  len 
)

USB_WritePacket : Writes a packet into the Tx FIFO associated with the EP/channel.

Parameters
USBxSelected device
srcpointer to source buffer
ch_ep_numendpoint or host channel number
lenNumber of bytes to write
Return values
HALstatus

Definition at line 809 of file stm32l4xx_ll_usb.c.

810 {
811  uint32_t USBx_BASE = (uint32_t)USBx;
812  uint32_t *pSrc = (uint32_t *)src;
813  uint32_t count32b, i;
814 
815  count32b = ((uint32_t)len + 3U) / 4U;
816  for (i = 0U; i < count32b; i++)
817  {
818  USBx_DFIFO((uint32_t)ch_ep_num) = __UNALIGNED_UINT32_READ(pSrc);
819  pSrc++;
820  }
821 
822  return HAL_OK;
823 }
return HAL_OK

◆ USB_WritePacket() [2/2]

HAL_StatusTypeDef USB_WritePacket ( USB_TypeDef *  USBx,
uint8_t *  src,
uint8_t  ch_ep_num,
uint16_t  len 
)

USB_WritePacket : Writes a packet into the Tx FIFO associated with the EP/channel.

Parameters
USBx: Selected device
src: pointer to source buffer
ch_ep_num: endpoint or host channel number
len: Number of bytes to write
Return values
HALstatus

Definition at line 2232 of file stm32l4xx_ll_usb.c.

2233 {
2234  /* Prevent unused argument(s) compilation warning */
2235  UNUSED(USBx);
2236  UNUSED(src);
2237  UNUSED(ch_ep_num);
2238  UNUSED(len);
2239  /* NOTE : - This function is not required by USB Device FS peripheral, it is used
2240  only by USB OTG FS peripheral.
2241  - This function is added to ensure compatibility across platforms.
2242  */
2243  return HAL_OK;
2244 }
return HAL_OK

◆ USB_WritePMA()

void USB_WritePMA ( USB_TypeDef *  USBx,
uint8_t *  pbUsrBuf,
uint16_t  wPMABufAddr,
uint16_t  wNBytes 
)

Copy a buffer from user memory area to packet memory area (PMA)

Parameters
USBxUSB peripheral instance register address.
pbUsrBufpointer to user memory area.
wPMABufAddraddress into PMA.
wNBytesno. of bytes to be copied.
Return values
None

Definition at line 2531 of file stm32l4xx_ll_usb.c.

2532 {
2533  uint32_t n = ((uint32_t)wNBytes + 1U) >> 1;
2534  uint32_t BaseAddr = (uint32_t)USBx;
2535  uint32_t i, temp1, temp2;
2536  uint16_t *pdwVal;
2537  uint8_t *pBuf = pbUsrBuf;
2538 
2539  pdwVal = (uint16_t *)(BaseAddr + 0x400U + ((uint32_t)wPMABufAddr * PMA_ACCESS));
2540 
2541  for (i = n; i != 0U; i--)
2542  {
2543  temp1 = (uint16_t) * pBuf;
2544  pBuf++;
2545  temp2 = temp1 | ((uint16_t)((uint16_t) * pBuf << 8));
2546  *pdwVal = (uint16_t)temp2;
2547  pdwVal++;
2548 
2549 #if PMA_ACCESS > 1U
2550  pdwVal++;
2551 #endif
2552 
2553  pBuf++;
2554  }
2555 }