STM32L4xx_HAL_Driver  1.14.0
Peripheral Control functions

management functions More...

Functions

HAL_StatusTypeDef HAL_PCD_DevConnect (PCD_HandleTypeDef *hpcd)
 Connect the USB device. More...
 
HAL_StatusTypeDef HAL_PCD_DevDisconnect (PCD_HandleTypeDef *hpcd)
 Disconnect the USB device. More...
 
HAL_StatusTypeDef HAL_PCD_SetAddress (PCD_HandleTypeDef *hpcd, uint8_t address)
 Set the USB Device address. More...
 
HAL_StatusTypeDef HAL_PCD_EP_Open (PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint16_t ep_mps, uint8_t ep_type)
 Open and configure an endpoint. More...
 
HAL_StatusTypeDef HAL_PCD_EP_Close (PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
 Deactivate an endpoint. More...
 
HAL_StatusTypeDef HAL_PCD_EP_Receive (PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len)
 Receive an amount of data. More...
 
HAL_StatusTypeDef HAL_PCD_EP_Transmit (PCD_HandleTypeDef *hpcd, uint8_t ep_addr, uint8_t *pBuf, uint32_t len)
 Send an amount of data. More...
 
uint32_t HAL_PCD_EP_GetRxCount (PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
 Get Received Data Size. More...
 
HAL_StatusTypeDef HAL_PCD_EP_SetStall (PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
 Set a STALL condition over an endpoint. More...
 
HAL_StatusTypeDef HAL_PCD_EP_ClrStall (PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
 Clear a STALL condition over in an endpoint. More...
 
HAL_StatusTypeDef HAL_PCD_EP_Flush (PCD_HandleTypeDef *hpcd, uint8_t ep_addr)
 Flush an endpoint. More...
 
HAL_StatusTypeDef HAL_PCD_ActivateRemoteWakeup (PCD_HandleTypeDef *hpcd)
 Activate remote wakeup signalling. More...
 
HAL_StatusTypeDef HAL_PCD_DeActivateRemoteWakeup (PCD_HandleTypeDef *hpcd)
 De-activate remote wakeup signalling. More...
 

Detailed Description

management functions

 ===============================================================================
                      ##### Peripheral Control functions #####
 ===============================================================================
    [..]
    This subsection provides a set of functions allowing to control the PCD data
    transfers.

Function Documentation

◆ HAL_PCD_ActivateRemoteWakeup()

HAL_StatusTypeDef HAL_PCD_ActivateRemoteWakeup ( PCD_HandleTypeDef hpcd)

Activate remote wakeup signalling.

Parameters
hpcdPCD handle
Return values
HALstatus

Definition at line 2042 of file stm32l4xx_hal_pcd.c.

2043 {
2044  return (USB_ActivateRemoteWakeup(hpcd->Instance));
2045 }
HAL_StatusTypeDef USB_ActivateRemoteWakeup(USB_OTG_GlobalTypeDef *USBx)
USB_ActivateRemoteWakeup active remote wakeup signalling.

◆ HAL_PCD_DeActivateRemoteWakeup()

HAL_StatusTypeDef HAL_PCD_DeActivateRemoteWakeup ( PCD_HandleTypeDef hpcd)

De-activate remote wakeup signalling.

Parameters
hpcdPCD handle
Return values
HALstatus

Definition at line 2052 of file stm32l4xx_hal_pcd.c.

2053 {
2054  return (USB_DeActivateRemoteWakeup(hpcd->Instance));
2055 }
HAL_StatusTypeDef USB_DeActivateRemoteWakeup(USB_OTG_GlobalTypeDef *USBx)
USB_DeActivateRemoteWakeup de-active remote wakeup signalling.

◆ HAL_PCD_DevConnect()

HAL_StatusTypeDef HAL_PCD_DevConnect ( PCD_HandleTypeDef hpcd)

Connect the USB device.

Parameters
hpcdPCD handle
Return values
HALstatus

Definition at line 1728 of file stm32l4xx_hal_pcd.c.

1729 {
1730 #if defined (USB_OTG_FS)
1731  USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
1732 #endif /* defined (USB_OTG_FS) */
1733 
1734  __HAL_LOCK(hpcd);
1735 #if defined (USB_OTG_FS)
1736  if (hpcd->Init.battery_charging_enable == 1U)
1737  {
1738  /* Enable USB Transceiver */
1739  USBx->GCCFG |= USB_OTG_GCCFG_PWRDWN;
1740  }
1741 #endif /* defined (USB_OTG_FS) */
1742  (void)USB_DevConnect(hpcd->Instance);
1743  __HAL_UNLOCK(hpcd);
1744  return HAL_OK;
1745 }
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
HAL_StatusTypeDef USB_DevConnect(USB_OTG_GlobalTypeDef *USBx)
USB_DevConnect : Connect the USB device by enabling the pull-up/pull-down.

◆ HAL_PCD_DevDisconnect()

HAL_StatusTypeDef HAL_PCD_DevDisconnect ( PCD_HandleTypeDef hpcd)

Disconnect the USB device.

Parameters
hpcdPCD handle
Return values
HALstatus

Definition at line 1752 of file stm32l4xx_hal_pcd.c.

1753 {
1754 #if defined (USB_OTG_FS)
1755  USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
1756 
1757 #endif /* defined (USB_OTG_FS) */
1758  __HAL_LOCK(hpcd);
1759  (void)USB_DevDisconnect(hpcd->Instance);
1760 #if defined (USB_OTG_FS)
1761  if (hpcd->Init.battery_charging_enable == 1U)
1762  {
1763  /* Disable USB Transceiver */
1764  USBx->GCCFG &= ~(USB_OTG_GCCFG_PWRDWN);
1765  }
1766 #endif /* defined (USB_OTG_FS) */
1767  __HAL_UNLOCK(hpcd);
1768  return HAL_OK;
1769 }
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
HAL_StatusTypeDef USB_DevDisconnect(USB_OTG_GlobalTypeDef *USBx)
USB_DevDisconnect : Disconnect the USB device by disabling the pull-up/pull-down. ...

◆ HAL_PCD_EP_Close()

HAL_StatusTypeDef HAL_PCD_EP_Close ( PCD_HandleTypeDef hpcd,
uint8_t  ep_addr 
)

Deactivate an endpoint.

Parameters
hpcdPCD handle
ep_addrendpoint address
Return values
HALstatus

Definition at line 1837 of file stm32l4xx_hal_pcd.c.

1838 {
1839  PCD_EPTypeDef *ep;
1840 
1841  if ((ep_addr & 0x80U) == 0x80U)
1842  {
1843  ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK];
1844  ep->is_in = 1U;
1845  }
1846  else
1847  {
1848  ep = &hpcd->OUT_ep[ep_addr & EP_ADDR_MSK];
1849  ep->is_in = 0U;
1850  }
1851  ep->num = ep_addr & EP_ADDR_MSK;
1852 
1853  __HAL_LOCK(hpcd);
1854  (void)USB_DeactivateEndpoint(hpcd->Instance, ep);
1855  __HAL_UNLOCK(hpcd);
1856  return HAL_OK;
1857 }
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
HAL_StatusTypeDef USB_DeactivateEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
De-activate and de-initialize an endpoint.

◆ HAL_PCD_EP_ClrStall()

HAL_StatusTypeDef HAL_PCD_EP_ClrStall ( PCD_HandleTypeDef hpcd,
uint8_t  ep_addr 
)

Clear a STALL condition over in an endpoint.

Parameters
hpcdPCD handle
ep_addrendpoint address
Return values
HALstatus

Definition at line 1983 of file stm32l4xx_hal_pcd.c.

1984 {
1985  PCD_EPTypeDef *ep;
1986 
1987  if (((uint32_t)ep_addr & 0x0FU) > hpcd->Init.dev_endpoints)
1988  {
1989  return HAL_ERROR;
1990  }
1991 
1992  if ((0x80U & ep_addr) == 0x80U)
1993  {
1994  ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK];
1995  ep->is_in = 1U;
1996  }
1997  else
1998  {
1999  ep = &hpcd->OUT_ep[ep_addr & EP_ADDR_MSK];
2000  ep->is_in = 0U;
2001  }
2002 
2003  ep->is_stall = 0U;
2004  ep->num = ep_addr & EP_ADDR_MSK;
2005 
2006  __HAL_LOCK(hpcd);
2007  (void)USB_EPClearStall(hpcd->Instance, ep);
2008  __HAL_UNLOCK(hpcd);
2009 
2010  return HAL_OK;
2011 }
__HAL_UNLOCK(hrtc)
HAL_StatusTypeDef USB_EPClearStall(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
USB_EPClearStall : Clear a stall condition over an EP.
__HAL_LOCK(hrtc)
return HAL_OK

◆ HAL_PCD_EP_Flush()

HAL_StatusTypeDef HAL_PCD_EP_Flush ( PCD_HandleTypeDef hpcd,
uint8_t  ep_addr 
)

Flush an endpoint.

Parameters
hpcdPCD handle
ep_addrendpoint address
Return values
HALstatus

Definition at line 2019 of file stm32l4xx_hal_pcd.c.

2020 {
2021  __HAL_LOCK(hpcd);
2022 
2023  if ((ep_addr & 0x80U) == 0x80U)
2024  {
2025  (void)USB_FlushTxFifo(hpcd->Instance, (uint32_t)ep_addr & EP_ADDR_MSK);
2026  }
2027  else
2028  {
2029  (void)USB_FlushRxFifo(hpcd->Instance);
2030  }
2031 
2032  __HAL_UNLOCK(hpcd);
2033 
2034  return HAL_OK;
2035 }
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
HAL_StatusTypeDef USB_FlushRxFifo(USB_OTG_GlobalTypeDef *USBx)
USB_FlushRxFifo : Flush Rx FIFO.
HAL_StatusTypeDef USB_FlushTxFifo(USB_OTG_GlobalTypeDef *USBx, uint32_t num)
USB_OTG_FlushTxFifo : Flush a Tx FIFO.

◆ HAL_PCD_EP_GetRxCount()

uint32_t HAL_PCD_EP_GetRxCount ( PCD_HandleTypeDef hpcd,
uint8_t  ep_addr 
)

Get Received Data Size.

Parameters
hpcdPCD handle
ep_addrendpoint address
Return values
DataSize

Definition at line 1899 of file stm32l4xx_hal_pcd.c.

1900 {
1901  return hpcd->OUT_ep[ep_addr & EP_ADDR_MSK].xfer_count;
1902 }

◆ HAL_PCD_EP_Open()

HAL_StatusTypeDef HAL_PCD_EP_Open ( PCD_HandleTypeDef hpcd,
uint8_t  ep_addr,
uint16_t  ep_mps,
uint8_t  ep_type 
)

Open and configure an endpoint.

Parameters
hpcdPCD handle
ep_addrendpoint address
ep_mpsendpoint max packet size
ep_typeendpoint type
Return values
HALstatus

Definition at line 1793 of file stm32l4xx_hal_pcd.c.

1794 {
1795  HAL_StatusTypeDef ret = HAL_OK;
1796  PCD_EPTypeDef *ep;
1797 
1798  if ((ep_addr & 0x80U) == 0x80U)
1799  {
1800  ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK];
1801  ep->is_in = 1U;
1802  }
1803  else
1804  {
1805  ep = &hpcd->OUT_ep[ep_addr & EP_ADDR_MSK];
1806  ep->is_in = 0U;
1807  }
1808 
1809  ep->num = ep_addr & EP_ADDR_MSK;
1810  ep->maxpacket = ep_mps;
1811  ep->type = ep_type;
1812 
1813  if (ep->is_in != 0U)
1814  {
1815  /* Assign a Tx FIFO */
1816  ep->tx_fifo_num = ep->num;
1817  }
1818  /* Set initial data PID. */
1819  if (ep_type == EP_TYPE_BULK)
1820  {
1821  ep->data_pid_start = 0U;
1822  }
1823 
1824  __HAL_LOCK(hpcd);
1825  (void)USB_ActivateEndpoint(hpcd->Instance, ep);
1826  __HAL_UNLOCK(hpcd);
1827 
1828  return ret;
1829 }
HAL_StatusTypeDef USB_ActivateEndpoint(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
Activate and configure an endpoint.
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK

◆ HAL_PCD_EP_Receive()

HAL_StatusTypeDef HAL_PCD_EP_Receive ( PCD_HandleTypeDef hpcd,
uint8_t  ep_addr,
uint8_t *  pBuf,
uint32_t  len 
)

Receive an amount of data.

Parameters
hpcdPCD handle
ep_addrendpoint address
pBufpointer to the reception buffer
lenamount of data to be received
Return values
HALstatus

Definition at line 1868 of file stm32l4xx_hal_pcd.c.

1869 {
1870  PCD_EPTypeDef *ep;
1871 
1872  ep = &hpcd->OUT_ep[ep_addr & EP_ADDR_MSK];
1873 
1874  /*setup and start the Xfer */
1875  ep->xfer_buff = pBuf;
1876  ep->xfer_len = len;
1877  ep->xfer_count = 0U;
1878  ep->is_in = 0U;
1879  ep->num = ep_addr & EP_ADDR_MSK;
1880 
1881  if ((ep_addr & EP_ADDR_MSK) == 0U)
1882  {
1883  (void)USB_EP0StartXfer(hpcd->Instance, ep);
1884  }
1885  else
1886  {
1887  (void)USB_EPStartXfer(hpcd->Instance, ep);
1888  }
1889 
1890  return HAL_OK;
1891 }
HAL_StatusTypeDef USB_EPStartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
USB_EPStartXfer : setup and starts a transfer over an EP.
HAL_StatusTypeDef USB_EP0StartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
USB_EP0StartXfer : setup and starts a transfer over the EP 0.
return HAL_OK

◆ HAL_PCD_EP_SetStall()

HAL_StatusTypeDef HAL_PCD_EP_SetStall ( PCD_HandleTypeDef hpcd,
uint8_t  ep_addr 
)

Set a STALL condition over an endpoint.

Parameters
hpcdPCD handle
ep_addrendpoint address
Return values
HALstatus

Definition at line 1942 of file stm32l4xx_hal_pcd.c.

1943 {
1944  PCD_EPTypeDef *ep;
1945 
1946  if (((uint32_t)ep_addr & EP_ADDR_MSK) > hpcd->Init.dev_endpoints)
1947  {
1948  return HAL_ERROR;
1949  }
1950 
1951  if ((0x80U & ep_addr) == 0x80U)
1952  {
1953  ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK];
1954  ep->is_in = 1U;
1955  }
1956  else
1957  {
1958  ep = &hpcd->OUT_ep[ep_addr];
1959  ep->is_in = 0U;
1960  }
1961 
1962  ep->is_stall = 1U;
1963  ep->num = ep_addr & EP_ADDR_MSK;
1964 
1965  __HAL_LOCK(hpcd);
1966 
1967  (void)USB_EPSetStall(hpcd->Instance, ep);
1968  if ((ep_addr & EP_ADDR_MSK) == 0U)
1969  {
1970  (void)USB_EP0_OutStart(hpcd->Instance, (uint8_t *)hpcd->Setup);
1971  }
1972  __HAL_UNLOCK(hpcd);
1973 
1974  return HAL_OK;
1975 }
HAL_StatusTypeDef USB_EP0_OutStart(USB_OTG_GlobalTypeDef *USBx, uint8_t *psetup)
Prepare the EP0 to start the first control setup.
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
HAL_StatusTypeDef USB_EPSetStall(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
USB_EPSetStall : set a stall condition over an EP.

◆ HAL_PCD_EP_Transmit()

HAL_StatusTypeDef HAL_PCD_EP_Transmit ( PCD_HandleTypeDef hpcd,
uint8_t  ep_addr,
uint8_t *  pBuf,
uint32_t  len 
)

Send an amount of data.

Parameters
hpcdPCD handle
ep_addrendpoint address
pBufpointer to the transmission buffer
lenamount of data to be sent
Return values
HALstatus

Definition at line 1911 of file stm32l4xx_hal_pcd.c.

1912 {
1913  PCD_EPTypeDef *ep;
1914 
1915  ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK];
1916 
1917  /*setup and start the Xfer */
1918  ep->xfer_buff = pBuf;
1919  ep->xfer_len = len;
1920  ep->xfer_count = 0U;
1921  ep->is_in = 1U;
1922  ep->num = ep_addr & EP_ADDR_MSK;
1923 
1924  if ((ep_addr & EP_ADDR_MSK) == 0U)
1925  {
1926  (void)USB_EP0StartXfer(hpcd->Instance, ep);
1927  }
1928  else
1929  {
1930  (void)USB_EPStartXfer(hpcd->Instance, ep);
1931  }
1932 
1933  return HAL_OK;
1934 }
HAL_StatusTypeDef USB_EPStartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
USB_EPStartXfer : setup and starts a transfer over an EP.
HAL_StatusTypeDef USB_EP0StartXfer(USB_OTG_GlobalTypeDef *USBx, USB_OTG_EPTypeDef *ep)
USB_EP0StartXfer : setup and starts a transfer over the EP 0.
return HAL_OK

◆ HAL_PCD_SetAddress()

HAL_StatusTypeDef HAL_PCD_SetAddress ( PCD_HandleTypeDef hpcd,
uint8_t  address 
)

Set the USB Device address.

Parameters
hpcdPCD handle
addressnew device address
Return values
HALstatus

Definition at line 1777 of file stm32l4xx_hal_pcd.c.

1778 {
1779  __HAL_LOCK(hpcd);
1780  hpcd->USB_Address = address;
1781  (void)USB_SetDevAddress(hpcd->Instance, address);
1782  __HAL_UNLOCK(hpcd);
1783  return HAL_OK;
1784 }
HAL_StatusTypeDef USB_SetDevAddress(USB_OTG_GlobalTypeDef *USBx, uint8_t address)
USB_SetDevAddress : Stop the usb device mode.
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK