USB operation functions

Data transfers functions. More...

Functions

hal_status_t hal_usb_reset (usb_handle_t *p_usb)
 usb modlue reset the basic configuration during host reset More...
 
uint8_t hal_usb_get_connect_state (void)
 usb module gets whether the device is connected to the host. More...
 
hal_status_t hal_usb_ep_write_start (usb_handle_t *p_usb, hal_usb_ep_t ep)
 usb ep start transmit data. More...
 
hal_status_t hal_usb_ep_write_end (usb_handle_t *p_usb, hal_usb_ep_t ep)
 usbd inform host transmit data end. More...
 
hal_status_t hal_usb_ep_read_start (usb_handle_t *p_usb, hal_usb_ep_t ep)
 usb ep start receive data. More...
 
hal_status_t hal_usb_ep_read_end (usb_handle_t *p_usb, hal_usb_ep_t ep)
 usbd inform host receive data end. More...
 
hal_status_t hal_usb_ep_transmit_dma (usb_handle_t *p_usb, hal_usb_ep_t ep, uint8_t *p_data, uint32_t length)
 Transmit an amount of data to USB endpoint in dma mode. More...
 
hal_status_t hal_usb_ep_receive_dma (usb_handle_t *p_usb, hal_usb_ep_t ep, uint8_t *p_data, uint32_t length)
 Receive an amount of data to USB endpoint in dma mode. More...
 
hal_status_t hal_usb_set_addr (usb_handle_t *p_usb, uint32_t addr)
 set USB devcice address. More...
 
uint32_t hal_usb_get_addr (usb_handle_t *p_usb)
 get USB devcice address More...
 
hal_status_t hal_usb_write_ep_fifo (usb_handle_t *p_usb, hal_usb_ep_t ep, uint32_t value, uint32_t ep4_wr_byte)
 write 32bit value to USB endpoit FIFO. More...
 
uint32_t hal_usb_read_ep_fifo (usb_handle_t *p_usb, hal_usb_ep_t ep)
 read 32bit value from USB endpoit FIFO. More...
 
hal_status_t hal_usb_set_ep_attr (usb_handle_t *p_usb, hal_usb_ep_t ep, uint32_t attr)
 set USB EP attribute. More...
 
uint32_t hal_usb_get_ep_attr (usb_handle_t *p_usb, hal_usb_ep_t ep)
 get USB EP attribute setting. More...
 
hal_status_t hal_usb_halt_ep (usb_handle_t *p_usb, hal_usb_ep_t ep)
 USB halt the endpoint. More...
 
hal_status_t hal_usb_un_halt_ep (usb_handle_t *p_usb, hal_usb_ep_t ep)
 USB un halt the endpoint. More...
 
hal_status_t hal_usb_set_and_unhalt_ep (usb_handle_t *p_usb, hal_usb_ep_t ep, uint32_t attr)
 USB un halt the endpoint and set the endpoint attribute. More...
 
uint32_t hal_usb_get_ep0_rx_data_sum (usb_handle_t *p_usb)
 get USB EP0 received data sum. More...
 
uint32_t hal_usb_get_it_flag (usb_handle_t *p_usb)
 get USB all interrupt status. More...
 
uint32_t hal_usb_get_ep1_rx_data_sum (usb_handle_t *p_usb)
 get USB EP1 received data sum. More...
 
uint32_t hal_usb_get_ep5_rx_data_sum (usb_handle_t *p_usb)
 get USB EP5 received data sum. More...
 
hal_status_t hal_usb_set_cmd_ok (usb_handle_t *p_usb)
 send ok command to USB host(EP0). More...
 
hal_status_t hal_usb_set_cmd_err (usb_handle_t *p_usb)
 send error command to USB host(EP0). More...
 

Detailed Description

Data transfers functions.

  ==============================================================================
                      ##### USB operation functions #####
 ===============================================================================
 [..]
    This subsection provides a set of functions allowing to manage the USB
    data transfers.

    [..] The USB supports master and slave mode:

    (#) There are two modes of transfer:
       (++) Blocking mode: The communication is performed in polling mode.
            The HAL status of all data processing is returned by the same function
            after finishing transfer.
       (++) No-Blocking mode: The communication is performed using Interrupts
            or DMA, These APIs return the HAL status.
            The end of the data processing will be indicated through the
            dedicated USB IRQ when using Interrupt mode or the DMA IRQ when
            using DMA mode.
            The hal_usb_tx_cplt_callback(), hal_usb_rx_cplt_callback() and hal_usb_tx_rx_cplt_callback() user callbacks
            will be executed respectively at the end of the transmit or Receive process
            The hal_usb_error_callback() user callback will be executed when a communication error is detected.

    (#) APIs provided for these 2 transfer modes (Blocking mode or Non blocking mode using either Interrupt or DMA)
        exist for 1-Line (simplex) and 2-Line (full duplex) modes.

Function Documentation

◆ hal_usb_ep_read_end()

hal_status_t hal_usb_ep_read_end ( usb_handle_t p_usb,
hal_usb_ep_t  ep 
)

usbd inform host receive data end.

Parameters
[in]p_usbPointer to an USB handle which contains the configuration information for the specified USB module.
[in]epUSB endpoit number(only EP0 EP1 EP5 supported)
Return values
HAL_OKOperation is OK.
HAL_ERRORParameter error or operation not supported.
HAL_BUSYDriver is busy.
HAL_TIMEOUTTimeout occurred.

◆ hal_usb_ep_read_start()

hal_status_t hal_usb_ep_read_start ( usb_handle_t p_usb,
hal_usb_ep_t  ep 
)

usb ep start receive data.

Parameters
[in]p_usbPointer to an USB handle which contains the configuration information for the specified USB module.
[in]epUSB endpoit number(only EP0 EP1 EP5 supported)
Return values
HAL_OKOperation is OK.
HAL_ERRORParameter error or operation not supported.
HAL_BUSYDriver is busy.
HAL_TIMEOUTTimeout occurred.

◆ hal_usb_ep_receive_dma()

hal_status_t hal_usb_ep_receive_dma ( usb_handle_t p_usb,
hal_usb_ep_t  ep,
uint8_t *  p_data,
uint32_t  length 
)

Receive an amount of data to USB endpoint in dma mode.

Parameters
[in]p_usbPointer to an USB handle which contains the configuration information for the specified USB module.
[in]epUSB endpoit number(EP5 support dma receive mode)
[in]p_dataPointer to AHB master buffer adderss
[in]lengthAmount of data receive during dma mode.
Return values
HAL_OKOperation is OK.
HAL_ERRORParameter error or operation not supported.
HAL_BUSYDriver is busy.
HAL_TIMEOUTTimeout occurred.

◆ hal_usb_ep_transmit_dma()

hal_status_t hal_usb_ep_transmit_dma ( usb_handle_t p_usb,
hal_usb_ep_t  ep,
uint8_t *  p_data,
uint32_t  length 
)

Transmit an amount of data to USB endpoint in dma mode.

Parameters
[in]p_usbPointer to an USB handle which contains the configuration information for the specified USB module.
[in]epUSB endpoit number( EP3 or EP4 support dma transmit mode)
[in]p_dataPointer to ahbm buffer adderss
[in]lengthAmount of data transmit during dma mode.
Return values
HAL_OKOperation is OK.
HAL_ERRORParameter error or operation not supported.
HAL_BUSYDriver is busy.
HAL_TIMEOUTTimeout occurred.

◆ hal_usb_ep_write_end()

hal_status_t hal_usb_ep_write_end ( usb_handle_t p_usb,
hal_usb_ep_t  ep 
)

usbd inform host transmit data end.

Parameters
[in]p_usbPointer to an USB handle which contains the configuration information for the specified USB module.
[in]epUSB endpoit number(only EP0 EP2 EP3 EP4 supported)
Return values
HAL_OKOperation is OK.
HAL_ERRORParameter error or operation not supported.
HAL_BUSYDriver is busy.
HAL_TIMEOUTTimeout occurred.

◆ hal_usb_ep_write_start()

hal_status_t hal_usb_ep_write_start ( usb_handle_t p_usb,
hal_usb_ep_t  ep 
)

usb ep start transmit data.

Parameters
[in]p_usbPointer to an USB handle which contains the configuration information for the specified USB module.
[in]epUSB endpoit number(only EP0 EP2 EP3 EP4 supported)
Return values
HAL_OKOperation is OK.
HAL_ERRORParameter error or operation not supported.
HAL_BUSYDriver is busy.
HAL_TIMEOUTTimeout occurred.

◆ hal_usb_get_addr()

uint32_t hal_usb_get_addr ( usb_handle_t p_usb)

get USB devcice address

Parameters
[in]p_usbPointer to an USB handle which contains the configuration information for the specified USB module.
Returns
USB devcice address form host

◆ hal_usb_get_connect_state()

uint8_t hal_usb_get_connect_state ( void  )

usb module gets whether the device is connected to the host.

Return values
::0usb device is disconnected to the host.
::1usb device is connected to the host.

◆ hal_usb_get_ep0_rx_data_sum()

uint32_t hal_usb_get_ep0_rx_data_sum ( usb_handle_t p_usb)

get USB EP0 received data sum.

Parameters
[in]p_usbPointer to an USB handle which contains the configuration information for the specified USB module.
Returns
USB received data sum in the EP0 IN FIFO
  • 0x0 ~ 0xFF.

◆ hal_usb_get_ep1_rx_data_sum()

uint32_t hal_usb_get_ep1_rx_data_sum ( usb_handle_t p_usb)

get USB EP1 received data sum.

Parameters
[in]p_usbPointer to an USB handle which contains the configuration information for the specified USB module.
Returns
USB received data sum in the EP IN FIFO
  • 0x0 ~ 0xFF.

◆ hal_usb_get_ep5_rx_data_sum()

uint32_t hal_usb_get_ep5_rx_data_sum ( usb_handle_t p_usb)

get USB EP5 received data sum.

Parameters
[in]p_usbPointer to an USB handle which contains the configuration information for the specified USB module.
Returns
USB received data sum in the EP IN FIFO
  • 0x0 ~ 0xFF.

◆ hal_usb_get_ep_attr()

uint32_t hal_usb_get_ep_attr ( usb_handle_t p_usb,
hal_usb_ep_t  ep 
)

get USB EP attribute setting.

Parameters
[in]p_usbPointer to an USB handle which contains the configuration information for the specified USB module.
[in]epep EP1 EP2 EP3
Returns
USB attribute setting This parameter can be one of the following values:

◆ hal_usb_get_it_flag()

uint32_t hal_usb_get_it_flag ( usb_handle_t p_usb)

get USB all interrupt status.

Parameters
[in]p_usbPointer to an USB handle which contains the configuration information for the specified USB module.
Returns
USB all interrupt flag

◆ hal_usb_halt_ep()

hal_status_t hal_usb_halt_ep ( usb_handle_t p_usb,
hal_usb_ep_t  ep 
)

USB halt the endpoint.

Parameters
[in]p_usbPointer to an USB handle which contains the configuration information for the specified USB module.
[in]epep EP1 EP2 EP3
Return values
HAL_OKOperation is OK.
HAL_ERRORParameter error or operation not supported.
HAL_BUSYDriver is busy.
HAL_TIMEOUTTimeout occurred.

◆ hal_usb_read_ep_fifo()

uint32_t hal_usb_read_ep_fifo ( usb_handle_t p_usb,
hal_usb_ep_t  ep 
)

read 32bit value from USB endpoit FIFO.

Parameters
[in]p_usbPointer to an USB handle which contains the configuration information for the specified USB module.
[in]epep EP0 EP1 EP5
Return values
:value USB endpoit FIFO 32bit data

◆ hal_usb_reset()

hal_status_t hal_usb_reset ( usb_handle_t p_usb)

usb modlue reset the basic configuration during host reset

Parameters
[in]p_usbPointer to an USB handle which contains the configuration information for the specified USB module.
Return values
HAL_OKOperation is OK.
HAL_ERRORParameter error or operation not supported.
HAL_BUSYDriver is busy.
HAL_TIMEOUTTimeout occurred.

◆ hal_usb_set_addr()

hal_status_t hal_usb_set_addr ( usb_handle_t p_usb,
uint32_t  addr 
)

set USB devcice address.

Parameters
[in]p_usbPointer to an USB handle which contains the configuration information for the specified USB module.
[in]addrUSB device address.
Return values
HAL_OKOperation is OK.
HAL_ERRORParameter error or operation not supported.
HAL_BUSYDriver is busy.
HAL_TIMEOUTTimeout occurred.

◆ hal_usb_set_and_unhalt_ep()

hal_status_t hal_usb_set_and_unhalt_ep ( usb_handle_t p_usb,
hal_usb_ep_t  ep,
uint32_t  attr 
)

USB un halt the endpoint and set the endpoint attribute.

Parameters
[in]p_usbPointer to an USB handle which contains the configuration information for the specified USB module.
[in]epep EP1 EP2 EP3
[in]attrUSB attribute setting.
Return values
HAL_OKOperation is OK.
HAL_ERRORParameter error or operation not supported.
HAL_BUSYDriver is busy.
HAL_TIMEOUTTimeout occurred.

◆ hal_usb_set_cmd_err()

hal_status_t hal_usb_set_cmd_err ( usb_handle_t p_usb)

send error command to USB host(EP0).

Parameters
[in]p_usbPointer to an USB handle which contains the configuration information for the specified USB module.
Return values
HAL_OKOperation is OK.
HAL_ERRORParameter error or operation not supported.
HAL_BUSYDriver is busy.
HAL_TIMEOUTTimeout occurred.

◆ hal_usb_set_cmd_ok()

hal_status_t hal_usb_set_cmd_ok ( usb_handle_t p_usb)

send ok command to USB host(EP0).

Parameters
[in]p_usbPointer to an USB handle which contains the configuration information for the specified USB module.
Return values
HAL_OKOperation is OK.
HAL_ERRORParameter error or operation not supported.
HAL_BUSYDriver is busy.
HAL_TIMEOUTTimeout occurred.

◆ hal_usb_set_ep_attr()

hal_status_t hal_usb_set_ep_attr ( usb_handle_t p_usb,
hal_usb_ep_t  ep,
uint32_t  attr 
)

set USB EP attribute.

Parameters
[in]p_usbPointer to an USB handle which contains the configuration information for the specified USB module.
[in]epep EP1 EP2 EP3
[in]attrUSB attribute setting. This parameter can be one of the following values:
Return values
HAL_OKOperation is OK.
HAL_ERRORParameter error or operation not supported.
HAL_BUSYDriver is busy.
HAL_TIMEOUTTimeout occurred.

◆ hal_usb_un_halt_ep()

hal_status_t hal_usb_un_halt_ep ( usb_handle_t p_usb,
hal_usb_ep_t  ep 
)

USB un halt the endpoint.

Parameters
[in]p_usbPointer to an USB handle which contains the configuration information for the specified USB module.
[in]epep EP1 EP2 EP3
Return values
HAL_OKOperation is OK.
HAL_ERRORParameter error or operation not supported.
HAL_BUSYDriver is busy.
HAL_TIMEOUTTimeout occurred.

◆ hal_usb_write_ep_fifo()

hal_status_t hal_usb_write_ep_fifo ( usb_handle_t p_usb,
hal_usb_ep_t  ep,
uint32_t  value,
uint32_t  ep4_wr_byte 
)

write 32bit value to USB endpoit FIFO.

Parameters
[in]p_usbPointer to an USB handle which contains the configuration information for the specified USB module.
[in]epUSB endpoit number(only EP0 EP2 EP3 EP4 supported)
[in]valueUSB endpoit FIFO 32bit data
[in]ep4_wr_byteUSB ep4 write fifo effective byte USB_EP4_FIFO_WEN_DEFAULT USB_EP4_FIFO_WEN_1BYTE USB_EP4_FIFO_WEN_2BYTE USB_EP4_FIFO_WEN_3BYTE USB_EP4_FIFO_WEN_4BYTE
Return values
HAL_OKOperation is OK.
HAL_ERRORParameter error or operation not supported.
HAL_BUSYDriver is busy.
HAL_TIMEOUTTimeout occurred.