Functions
USB operation functions
Peripheral Driver » HAL Driver » USB » Functions

Data transfers functions. More...

Collaboration diagram for USB operation functions:

## 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_usb | Pointer to an USB handle which contains the configuration information for the specified USB module.
  [in] | ep | USB endpoit number(only EP0 EP1 EP5 supported)

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout 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_usb | Pointer to an USB handle which contains the configuration information for the specified USB module.
  [in] | ep | USB endpoit number(only EP0 EP1 EP5 supported)

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout 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_usb | Pointer to an USB handle which contains the configuration information for the specified USB module.
  [in] | ep | USB endpoit number(EP5 support dma receive mode)
  [in] | p_data | Pointer to AHB master buffer adderss
  [in] | length | Amount of data receive during dma mode.

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout 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_usb | Pointer to an USB handle which contains the configuration information for the specified USB module.
  [in] | ep | USB endpoit number( EP3 or EP4 support dma transmit mode)
  [in] | p_data | Pointer to ahbm buffer adderss
  [in] | length | Amount of data transmit during dma mode.

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout 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_usb | Pointer to an USB handle which contains the configuration information for the specified USB module.
  [in] | ep | USB endpoit number(only EP0 EP2 EP3 EP4 supported)

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout 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_usb | Pointer to an USB handle which contains the configuration information for the specified USB module.
  [in] | ep | USB endpoit number(only EP0 EP2 EP3 EP4 supported)

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout occurred.

## ◆ hal_usb_get_addr()

uint32_t hal_usb_get_addr | ( | usb_handle_t * | p_usb | ) |

get USB devcice address

Parameters

  [in] | p_usb | Pointer 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

  ::0 | usb device is disconnected to the host.
  ::1 | usb 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_usb | Pointer 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_usb | Pointer 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_usb | Pointer 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_usb | Pointer to an USB handle which contains the configuration information for the specified USB module.
  [in] | ep | ep EP1 EP2 EP3

Returns
  USB attribute setting This parameter can be one of the following values:
  - USB_EP_ATTR_INT Endpoint attribute setting: interrupt
  - USB_EP_ATTR_ISO Endpoint attribute setting: Isochronous
  - USB_EP_ATTR_BULK Endpoint attribute setting: bulk

## ◆ 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_usb | Pointer 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_usb | Pointer to an USB handle which contains the configuration information for the specified USB module.
  [in] | ep | ep EP1 EP2 EP3

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout 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_usb | Pointer to an USB handle which contains the configuration information for the specified USB module.
  [in] | ep | ep 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_usb | Pointer to an USB handle which contains the configuration information for the specified USB module.

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout 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_usb | Pointer to an USB handle which contains the configuration information for the specified USB module.
  [in] | addr | USB device address.

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout 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_usb | Pointer to an USB handle which contains the configuration information for the specified USB module.
  [in] | ep | ep EP1 EP2 EP3
  [in] | attr | USB attribute setting.

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout 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_usb | Pointer to an USB handle which contains the configuration information for the specified USB module.

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout 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_usb | Pointer to an USB handle which contains the configuration information for the specified USB module.

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout 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_usb | Pointer to an USB handle which contains the configuration information for the specified USB module.
  [in] | ep | ep EP1 EP2 EP3
  [in] | attr | USB attribute setting. This parameter can be one of the following values: USB_EP_ATTR_INT Endpoint attribute setting: interrupt USB_EP_ATTR_ISO Endpoint attribute setting: Isochronous USB_EP_ATTR_BULK Endpoint attribute setting: bulk

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout 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_usb | Pointer to an USB handle which contains the configuration information for the specified USB module.
  [in] | ep | ep EP1 EP2 EP3

Return values

  HAL_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout 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_usb | Pointer to an USB handle which contains the configuration information for the specified USB module.
  [in] | ep | USB endpoit number(only EP0 EP2 EP3 EP4 supported)
  [in] | value | USB endpoit FIFO 32bit data
  [in] | ep4_wr_byte | USB 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_OK | Operation is OK.
  HAL_ERROR | Parameter error or operation not supported.
  HAL_BUSY | Driver is busy.
  HAL_TIMEOUT | Timeout occurred.