MT2523 API Reference  LinkIt SDK v4
USB

This section introduces the USB APIs including terms and acronyms, supported features, software architecture, details on how to use this driver, enumerations, structures and functions. More...

Overview

This section introduces the USB APIs including terms and acronyms, supported features, software architecture, details on how to use this driver, enumerations, structures and functions.

Terms Details
USB Universal Serial Bus. USB was designed to standardize the connection of computer peripherals (including keyboards, pointing devices, digital cameras, printers, portable media players, disk drives and network adapters) to personal computers, both to communicate and to supply electric power. It has become commonplace on other devices, such as smart phones, PDAs and video game consoles.[3] USB has effectively replaced a variety of earlier interfaces, such as serial and parallel ports, as well as separate power chargers for portable devices. For more information, please refer to an introduction to the USB in Wikipedia.
PIO Programmed Input / Output. It is a transmission mode to use CPU to move data.

Supported features.

Software architecture of the USB driver.

The software architecture of the USB driver is shown in the diagram below.

hal_usb_archi.png

How to use this driver.

Functions

hal_usb_status_t hal_usb_init (void)
 This function initializes the USB hardware module. More...
 
hal_usb_status_t hal_usb_configure_driver (void)
 This function initializes the USB HAL driver. More...
 
hal_usb_status_t hal_usb_register_driver_callback (hal_usb_driver_handler_type_t type, uint32_t ep_num, hal_usb_driver_interrupt_handler_t hdlr)
 This function registers a callback function. More...
 
hal_usb_status_t hal_usb_pull_up_dp_line (void)
 This function pulls the USB DP pin to high. More...
 
hal_usb_status_t hal_usb_reset_hardware (void)
 This function applies the USB hardware soft reset. More...
 
hal_usb_status_t hal_usb_reset_fifo (void)
 This function applies USB FIFO address reset at all endpoints. More...
 
hal_usb_status_t hal_usb_deinit (void)
 This function releases the USB hardware resource. More...
 
hal_usb_status_t hal_usb_set_address (uint8_t addr, hal_usb_set_address_state_t state)
 This function configures the USB address. More...
 
hal_usb_status_t hal_usb_init_tx_endpoint (uint32_t ep_num, uint16_t data_size, hal_usb_endpoint_transfer_type_t type, bool double_fifo)
 This function initializes the USB endpoint in TX direction. More...
 
hal_usb_status_t hal_usb_init_rx_endpoint (uint32_t ep_num, uint16_t data_size, hal_usb_endpoint_transfer_type_t type, bool double_fifo)
 This function initialize the USB endpoint in RX direction. More...
 
hal_usb_status_t hal_usb_enable_tx_endpoint (uint32_t ep_num, hal_usb_endpoint_transfer_type_t ep_type, hal_usb_dma_usage_t dma_usage_type, bool is_flush)
 This function enables the USB endpoint TX interrupt. More...
 
hal_usb_status_t hal_usb_enable_rx_endpoint (uint32_t ep_num, hal_usb_endpoint_transfer_type_t ep_type, hal_usb_dma_usage_t dma_usage_type, bool is_flush)
 This function enables the USB endpoint RX interrupt. More...
 
hal_usb_status_t hal_usb_disable_tx_endpoint (uint32_t ep_num)
 This function disables the USB endpoint TX interrupt. More...
 
hal_usb_status_t hal_usb_disable_rx_endpoint (uint32_t ep_num)
 This function disables the USB endpoint RX interrupt. More...
 
hal_usb_status_t hal_usb_clear_tx_endpoint_data_toggle (uint32_t ep_num)
 This function clears the TX endpoint data toggle. More...
 
hal_usb_status_t hal_usb_clear_rx_endpoint_data_toggle (uint32_t ep_num)
 This function clears the TX endpoint data toggle. More...
 
hal_usb_status_t hal_usb_read_endpoint_fifo (uint32_t ep_num, uint16_t nBytes, void *pDst)
 This function reads the USB data from FIFO. More...
 
hal_usb_status_t hal_usb_write_endpoint_fifo (uint32_t ep_num, uint16_t nBytes, void *pSrc)
 This function writes the USB data to FIFO. More...
 
hal_usb_status_t hal_usb_set_endpoint_stall (uint32_t ep_num, hal_usb_endpoint_direction_t direction, bool stall_enable)
 This function sets the USB endpoint n to stall, flush or clear data toggle. More...
 
bool hal_usb_get_endpoint_stall_status (uint32_t ep_num, hal_usb_endpoint_direction_t direction)
 This function queries the stall status of the USB endpoint n. More...
 
hal_usb_status_t hal_usb_get_endpoint_0_status (bool *p_transaction_end, bool *p_sent_stall)
 This function gets the USB control pipe hardware status. More...
 
hal_usb_status_t hal_usb_update_endpoint_0_state (hal_usb_endpoint_0_driver_state_t state, bool stall, bool end)
 This function sets the USB control pipe hardware status. More...
 
uint32_t hal_usb_get_rx_packet_length (uint32_t ep_num)
 This function gets the data packet length at the RX endpoint. More...
 
hal_usb_status_t hal_usb_set_endpoint_tx_ready (uint32_t ep_num)
 This function sets the USB packet ready once the data is fully written into FIFO. More...
 
hal_usb_status_t hal_usb_set_endpoint_rx_ready (uint32_t ep_num)
 This function sets the USB packet ready once the data is fully read from FIFO. More...
 
hal_usb_status_t hal_usb_clear_tx_endpoint_fifo (uint32_t ep_num, hal_usb_endpoint_transfer_type_t ep_type, bool b_reset_toggle)
 This function flushes data packet in the TX FIFO and clears data toggle by request. More...
 
hal_usb_status_t hal_usb_clear_rx_endpoint_fifo (uint32_t ep_num, hal_usb_endpoint_transfer_type_t ep_type, bool b_reset_toggle)
 This function flushes data packet in RX FIFO and clears the data toggle by request. More...
 
hal_usb_status_t hal_usb_get_dma_channel (uint32_t ep_tx_num, uint32_t ep_rx_num, hal_usb_endpoint_direction_t direction, bool same_chan)
 This function allocates a USB DMA channel For more information on the number of DMA channels on the LinkIt platform for RTOS, please refer to HAL_USB_MAX_NUMBER_ENDPOINT. More...
 
hal_usb_status_t hal_usb_release_dma_channel (uint32_t ep_tx_num, uint32_t ep_rx_num, hal_usb_endpoint_direction_t direction, bool same_chan)
 This function frees a USB DMA channel resource. More...
 
hal_usb_status_t hal_usb_start_dma_channel (uint32_t ep_num, hal_usb_endpoint_direction_t direction, hal_usb_endpoint_transfer_type_t ep_type, void *addr, uint32_t length, hal_usb_dma_handler_t callback, bool callback_upd_run, hal_usb_dma_type_t dma_type)
 This function sets up the USB DMA channel to transfer data. More...
 
hal_usb_status_t hal_usb_stop_dma_channel (uint32_t ep_num, hal_usb_endpoint_direction_t direction)
 This function stops the USB DMA channel and clears pending DMA interrupts. More...
 
bool hal_usb_is_dma_running (uint32_t ep_num, hal_usb_endpoint_direction_t direction)
 This function queries the DMA execution status. More...
 
bool hal_usb_is_high_speed (void)
 This function queries current USB speed. More...
 
bool hal_usb_is_endpoint_tx_empty (uint32_t ep_num)
 This function checks if the TX endpoint FIFO is empty or not. More...
 
bool hal_usb_is_endpoint_rx_empty (uint32_t ep_num)
 This function checks if the RX endpoint FIFO is empty or not. More...
 
hal_usb_status_t hal_usb_enter_test_mode (hal_usb_test_mode_type_t test_selector)
 This function sets the USB hardware into test mode. More...
 

Modules

 Define
 
 Enum.
 
 Typedefs.
 

Function Documentation

hal_usb_status_t hal_usb_clear_rx_endpoint_data_toggle ( uint32_t  ep_num)

This function clears the TX endpoint data toggle.

It's to force the endpoint data toggle to switch and the data packet to be cleared from the FIFO, regardless if the acknowledgement was received.

Parameters
[in]ep_numis the endpoint number to clear data toggle.
Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
Sample code:
1 void USB_endpoint_disable (void)
2 {
3  int ep_num = 1;
4  hal_usb_clear_rx_endpoint_data_toggle(ep_num);
5 }
hal_usb_status_t hal_usb_clear_rx_endpoint_fifo ( uint32_t  ep_num,
hal_usb_endpoint_transfer_type_t  ep_type,
bool  b_reset_toggle 
)

This function flushes data packet in RX FIFO and clears the data toggle by request.

Parameters
[in]ep_numis the endpoint number.
[in]ep_typeis the endpoint type defined in USB 2.0 Specification, such as CTRL, BULK, INTR, ISO endpoint.
[in]b_reset_toggleis set to true to execute clear data toggle.
Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
Sample code:
1 void usb_fifo_flush(void)
2 {
3  int ep_num = 1;
4  bool clear_data_toggle = false;
5 
6  hal_usb_clear_rx_endpoint_fifo(ep_num, HAL_USB_ENDPT_BULK, clear_data_toggle);
7 }
hal_usb_status_t hal_usb_clear_tx_endpoint_data_toggle ( uint32_t  ep_num)

This function clears the TX endpoint data toggle.

It's to force the endpoint data toggle to switch and the data packet to be cleared from the FIFO, regardless if the acknowledgement was received.

Parameters
[in]ep_numis the endpoint number to clear data toggle.
Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
Sample code:
1 void USB_endpoint_disable (void)
2 {
3  int ep_num = 1;
4  hal_usb_clear_tx_endpoint_data_toggle(ep_num);
5 }
hal_usb_status_t hal_usb_clear_tx_endpoint_fifo ( uint32_t  ep_num,
hal_usb_endpoint_transfer_type_t  ep_type,
bool  b_reset_toggle 
)

This function flushes data packet in the TX FIFO and clears data toggle by request.

Parameters
[in]ep_numis the endpoint number.
[in]ep_typeis the endpoint type defined in USB 2.0 Specification, such as CTRL, BULK, INTR, ISO endpoint.
[in]b_reset_toggleis set to true to execute clear data toggle.
Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
Sample code:
1 void usb_fifo_flush(void)
2 {
3  int ep_num = 1;
4  bool clear_data_toggle = false;
5 
6  hal_usb_clear_tx_endpoint_fifo(ep_num, HAL_USB_ENDPT_BULK, clear_data_toggle);
7 }
hal_usb_status_t hal_usb_configure_driver ( void  )

This function initializes the USB HAL driver.

This function will initialize all required parameters, callback function and endpoint information in USB HAL driver.

Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
Please refer to "Initial USB hardware" in How to use this driver..
hal_usb_status_t hal_usb_deinit ( void  )

This function releases the USB hardware resource.

This function deinitializes the USB hardware, sets the USB hardware in low power mode and releases the USB related clock tree and power source.

Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
Please refer to "De-initialize the USB hardware" in How to use this driver..
hal_usb_status_t hal_usb_disable_rx_endpoint ( uint32_t  ep_num)

This function disables the USB endpoint RX interrupt.

Parameters
[in]ep_numis the endpoint number to disable.
Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
Sample code:
1 void USB_endpoint_disable (void)
2 {
3  int ep_num = 1;
4  hal_usb_disable_rx_endpoint(ep_num);
5 }
hal_usb_status_t hal_usb_disable_tx_endpoint ( uint32_t  ep_num)

This function disables the USB endpoint TX interrupt.

Parameters
[in]ep_numis the endpoint number to disable.
Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
Sample code:
1 void USB_endpoint_disable (void)
2 {
3  int ep_num = 1;
4  hal_usb_disable_tx_endpoint(ep_num);
5 }
hal_usb_status_t hal_usb_enable_rx_endpoint ( uint32_t  ep_num,
hal_usb_endpoint_transfer_type_t  ep_type,
hal_usb_dma_usage_t  dma_usage_type,
bool  is_flush 
)

This function enables the USB endpoint RX interrupt.

Parameters
[in]ep_numis the endpoint to initialize.
[in]ep_typeis the endpoint type defined in USB 2.0 Specification. Such as CTRL, BULK, INTR, ISO endpoint.
[in]dma_usage_typeis set to PIO or DMA mode.
[in]is_flushflushes the USB FIFO data when the function is executed.
Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
Please refer to "USB endpoint setup" in How to use this driver..
hal_usb_status_t hal_usb_enable_tx_endpoint ( uint32_t  ep_num,
hal_usb_endpoint_transfer_type_t  ep_type,
hal_usb_dma_usage_t  dma_usage_type,
bool  is_flush 
)

This function enables the USB endpoint TX interrupt.

Parameters
[in]ep_numis the endpoint to initialize.
[in]ep_typeis the endpoint type defined in USB 2.0 Specification, such as CTRL, BULK, INTR, ISO endpoint.
[in]dma_usage_typeis set to PIO or DMA mode.
[in]is_flushflushes the USB FIFO data when the function is executed.
Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
Please refer to "USB endpoint setup" in How to use this driver..
hal_usb_status_t hal_usb_enter_test_mode ( hal_usb_test_mode_type_t  test_selector)

This function sets the USB hardware into test mode.

To activate a test mode, the USB 2.0 Specification defines the SET_FEATURE command as the desired interface. The USB-IF offers a free High Speed electrical Test Tool (HSET) for Microsoft Windows OS, to activate the various test modes and operations

Parameters
[in]test_selectorselect the test function.
Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
Sample code:
1 void usb_test_mode(void)
2 {
3  hal_usb_enter_test_mode(HAL_USB_TEST_MODE_TYPE_J);
4  hal_usb_enter_test_mode(HAL_USB_TEST_MODE_TYPE_K);
5  hal_usb_enter_test_mode(HAL_USB_TEST_MODE_TYPE_SE0_NAK);
6  hal_usb_enter_test_mode(HAL_USB_TEST_MODE_TYPE_PACKET);
7  }
hal_usb_status_t hal_usb_get_dma_channel ( uint32_t  ep_tx_num,
uint32_t  ep_rx_num,
hal_usb_endpoint_direction_t  direction,
bool  same_chan 
)

This function allocates a USB DMA channel For more information on the number of DMA channels on the LinkIt platform for RTOS, please refer to HAL_USB_MAX_NUMBER_ENDPOINT.

Parameters
[in]ep_tx_numis the endpoint number in TX direction.
[in]ep_rx_numis the endpoint number in RX direction.
[in]directionis the USB endpoint direction. This parameter is ignored, if the same channel is used.
[in]same_chanthe TX and RX use the same DMA channel.
Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
An example implementation can be found in "USB DMA Usage." in How to use this driver..
hal_usb_status_t hal_usb_get_endpoint_0_status ( bool *  p_transaction_end,
bool *  p_sent_stall 
)

This function gets the USB control pipe hardware status.

p_transaction_end: This bit is set when a control transaction ends before the DataEnd bit is set. An interrupt will be generated and the FIFO flushed. p_sent_stall: This bit is set when a STALL handshake is transmitted.

Parameters
[out]p_transaction_endis the result of control pipe transaction end.
[out]p_sent_stallis the result of control pipe sent stall.
Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
Sample code:
1 void USB_Endpoint0_Hdlr(void)
2 {
3  bool b_transaction_end;
4  bool b_sent_stall;
5 
6  hal_usb_get_endpoint_0_status(&b_transaction_end, &b_sent_stall);
7 }
bool hal_usb_get_endpoint_stall_status ( uint32_t  ep_num,
hal_usb_endpoint_direction_t  direction 
)

This function queries the stall status of the USB endpoint n.

It is usually used to response to the host endpoint 0 command: GET_STATUS

Parameters
[in]ep_numis the endpoint number.
[in]directionis the USB endpoint direction.
Returns
True, if stall is enabled.
Example
Sample code please refers to "USB Endpoint0 Handler" in How to use this driver..
1 void USB_Endpoint0_Hdlr(void)
2 {
3  int ep_num = 1;
4  bool status;
5 
6  status = (uint16_t)hal_usb_get_endpoint_stall_status(ep_num, HAL_USB_EP_TX_DIR);
7 }
uint32_t hal_usb_get_rx_packet_length ( uint32_t  ep_num)

This function gets the data packet length at the RX endpoint.

Parameters
[in]ep_numis the endpoint number.
Returns
the length of packet size in bytes.
Example
For an example implementation, please refer to "USB PIO data read" in How to use this driver..
hal_usb_status_t hal_usb_init ( void  )

This function initializes the USB hardware module.

Call this function before using the USB service. It also enables the USB related clock tree and power source.

Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
Please refer to "Initialize the USB hardware" in How to use this driver..
hal_usb_status_t hal_usb_init_rx_endpoint ( uint32_t  ep_num,
uint16_t  data_size,
hal_usb_endpoint_transfer_type_t  type,
bool  double_fifo 
)

This function initialize the USB endpoint in RX direction.

Parameters
[in]ep_numis the endpoint to initialize.
[in]data_sizeis the maximum packet size at this endpoint. For more details about maximum packet size, please refer to USB 2.0 Specification.
[in]typeis the endpoint type defined in USB 2.0 Specification, such as CTRL, BULK, INTR, ISO endpoint.
[in]double_fifoallocates two FIFO buffers, if double_fifo is enabled.
Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
Please refer to "USB endpoint setup" in How to use this driver..
hal_usb_status_t hal_usb_init_tx_endpoint ( uint32_t  ep_num,
uint16_t  data_size,
hal_usb_endpoint_transfer_type_t  type,
bool  double_fifo 
)

This function initializes the USB endpoint in TX direction.

Parameters
[in]ep_numis the endpoint to initialize.
[in]data_sizeis the maximum packet size at this endpoint. For more details about maximum packet size, please refer to USB 2.0 Specification.
[in]typeis the endpoint type defined in USB 2.0 Specification, such as CTRL, BULK, INTR, ISO endpoint.
[in]double_fifotwo FIFO buffers are allocated, if double_fifo is enabled. It may cost more FIFO SRAM.
Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
Please refer to "USB endpoint setup" in How to use this driver..
bool hal_usb_is_dma_running ( uint32_t  ep_num,
hal_usb_endpoint_direction_t  direction 
)

This function queries the DMA execution status.

Parameters
[in]ep_numis the endpoint number.
[in]directionis the USB endpoint direction.
Returns
True, if the DMA is running.
Example
An example implementation can be found in "USB DMA Usage." in How to use this driver..
bool hal_usb_is_endpoint_rx_empty ( uint32_t  ep_num)

This function checks if the RX endpoint FIFO is empty or not.

Parameters
[in]ep_numis the endpoint number.
Returns
False, if there is data in FIFO pending to read.
Example
Sample code:
1 void query_fifo_status(void)
2 {
3  int ep_num = 1;
4 
5  if (hal_usb_is_endpoint_rx_empty(ep_num))
6  printf("USB rx FIFO is empty\n");
7  else
8  printf("USB rx FIFO still has data\n");
9 }
bool hal_usb_is_endpoint_tx_empty ( uint32_t  ep_num)

This function checks if the TX endpoint FIFO is empty or not.

Parameters
[in]ep_numis the endpoint number.
Returns
False, if there is data in FIFO pending to send.
Example
Sample code:
1 void query_fifo_status(void)
2 {
3  int ep_num = 1;
4 
5  if (hal_usb_is_endpoint_tx_empty(ep_num))
6  printf("USB tx FIFO is empty\n");
7  else
8  printf("USB tx FIFO still has data\n");
9 }
bool hal_usb_is_high_speed ( void  )

This function queries current USB speed.

Returns
True, if using high-speed USB.
Example
Sample code:
1 void get_usb_speed(void)
2 {
3  if (hal_usb_is_high_speed())
4  printf("USB is high speed mode\n");
5  else
6  printf("USB is full speed mode\n");
7 }
hal_usb_status_t hal_usb_pull_up_dp_line ( void  )

This function pulls the USB DP pin to high.

It starts the USB connection flow. For more details on DP, please refer to the USB 2.0 Specification.

Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
Please refer to "Initialize the USB hardware" in How to use this driver..
hal_usb_status_t hal_usb_read_endpoint_fifo ( uint32_t  ep_num,
uint16_t  nBytes,
void *  pDst 
)

This function reads the USB data from FIFO.

Reading from these addresses unloads data from the RX FIFO for the corresponding endpoint.

Parameters
[in]ep_numis the endpoint number.
[in]nBytesis the number of bytes to read.
[in]pDstis a pointer to the destination.
Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
Sample code please refers to "USB PIO data read." in How to use this driver..
hal_usb_status_t hal_usb_register_driver_callback ( hal_usb_driver_handler_type_t  type,
uint32_t  ep_num,
hal_usb_driver_interrupt_handler_t  hdlr 
)

This function registers a callback function.

Parameters
[in]typeis the interrupt handler type. Please refer to hal_usb_driver_handler_type_t.
[in]ep_numis the endpoint number. The interrupt handler must be binding to a specific endpoint number if it uses HAL_USB_DRV_HDLR_EP_TX and HAL_USB_DRV_HDLR_EP_RX.
[in]hdlris the callback function. Please refer to hal_usb_driver_interrupt_handler_t.
Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
Please refer to "Initialize the USB hardware" in How to use this driver..
hal_usb_status_t hal_usb_release_dma_channel ( uint32_t  ep_tx_num,
uint32_t  ep_rx_num,
hal_usb_endpoint_direction_t  direction,
bool  same_chan 
)

This function frees a USB DMA channel resource.

For more information on the number of DMA channels on the LinkIt platform for RTOS, please refer to HAL_USB_MAX_NUMBER_ENDPOINT.

Parameters
[in]ep_tx_numis the endpoint number in TX direction.
[in]ep_rx_numis the endpoint number in RX direction.
[in]directionis the USB endpoint direction. This parameter is ignored, if the same channel is used.
[in]same_chanthe TX and RX use the same DMA channel.
Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
An example implementation can be found in "USB DMA Usage." in How to use this driver..
hal_usb_status_t hal_usb_reset_fifo ( void  )

This function applies USB FIFO address reset at all endpoints.

Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
Please refer to "Initialize the USB hardware" in How to use this driver..
hal_usb_status_t hal_usb_reset_hardware ( void  )

This function applies the USB hardware soft reset.

Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
Please refer to "Initialize the USB hardware" in How to use this driver..
hal_usb_status_t hal_usb_set_address ( uint8_t  addr,
hal_usb_set_address_state_t  state 
)

This function configures the USB address.

In the USB 2.0 Specifications, the USB address is set by the USB control pipe. The address is 1~127(7-bits). This address should be written with the address received through a SET_ADDRESS command, which will then be used for decoding the function address in subsequent token packets.

Parameters
[in]addrthe USB address set by the USB control pipe through a SET_ADDRESS command.
[in]statethe current state for the set address function. The address writes to hardware only in HAL_USB_SET_ADDR_STATUS state. It must make sure the SET_ADDRESS command is completed.
Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
Please refer to "USB Endpoint0 Handler" in How to use this driver..
hal_usb_status_t hal_usb_set_endpoint_rx_ready ( uint32_t  ep_num)

This function sets the USB packet ready once the data is fully read from FIFO.

Hardware issues an interrupt if RX endpoint received a packet. Hardware will start to receive the next packet if data is read from FIFO and RX packet is set to ready.

Parameters
[in]ep_numis the endpoint number.
Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
For an example implementation, please refer to "USB PIO data read." in How to use this driver..
hal_usb_status_t hal_usb_set_endpoint_stall ( uint32_t  ep_num,
hal_usb_endpoint_direction_t  direction,
bool  stall_enable 
)

This function sets the USB endpoint n to stall, flush or clear data toggle.

This function is used to execute (1) endpoint stall, (2) FIFO flush and (3) clear data toggle.

Parameters
[in]ep_numis the endpoint number.
[in]directionis the USB endpoint direction.
[in]stall_enableenables or disables the stall operation.
Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
Sample code please refers to "USB Endpoint0 Handler" in How to use this driver..
hal_usb_status_t hal_usb_set_endpoint_tx_ready ( uint32_t  ep_num)

This function sets the USB packet ready once the data is fully written into FIFO.

Hardware will send the packet out if data is written to the FIFO and the TX packet is set to ready. Null length packet (ZLP) will be sent if the data is not written to the FIFO.

Parameters
[in]ep_numis the endpoint number.
Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
Sample code please refers to "USB PIO data write." in How to use this driver..
hal_usb_status_t hal_usb_start_dma_channel ( uint32_t  ep_num,
hal_usb_endpoint_direction_t  direction,
hal_usb_endpoint_transfer_type_t  ep_type,
void *  addr,
uint32_t  length,
hal_usb_dma_handler_t  callback,
bool  callback_upd_run,
hal_usb_dma_type_t  dma_type 
)

This function sets up the USB DMA channel to transfer data.

Parameters
[in]ep_numis the endpoint number.
[in]directionis the USB endpoint direction.
[in]ep_typeis the endpoint type defined in USB 2.0 Specification. Such as CTRL, BULK, INTR, ISO endpoint.
[in]addris a pointer to the address to apply the DMA transaction.
[in]lengthis the data length in bytes.
[in]callbackis called once the DMA transaction is complete.
[in]callback_upd_runconfigures the DMA running state. Set true, if application callback function requests to clear the DMA running by itself.
[in]dma_typeexecutes a single packet operation or multiple packets operation, hal_usb_dma_type_t.
Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
An example implementation can be found in "USB DMA Usage." in How to use this driver..
hal_usb_status_t hal_usb_stop_dma_channel ( uint32_t  ep_num,
hal_usb_endpoint_direction_t  direction 
)

This function stops the USB DMA channel and clears pending DMA interrupts.

After that, drop data in FIFO.

Parameters
[in]ep_numis the endpoint number.
[in]directionis the USB endpoint direction.
Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
An example implementation can be found in "USB DMA Usage." in How to use this driver..
hal_usb_status_t hal_usb_update_endpoint_0_state ( hal_usb_endpoint_0_driver_state_t  state,
bool  stall,
bool  end 
)

This function sets the USB control pipe hardware status.

Parameters
[in]stateis the endpoint0 hardware control state. Please refer to hal_usb_endpoint_0_driver_state_t.
[in]stallis set to true to execute endpoint stall.
[in]endis set to true to execute transaction end.
Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
Sample code:
1 // It shows 3 examples in this function call.
2 void USB_Endpoint0_State(void)
3 {
4  bool transaction_end;
5  bool sent_stall;
6 
7  //example1: read data end and stall this transaction.
8  sent_stall = true;
9  transaction_end = false;
10  hal_usb_update_endpoint_0_state(HAL_USB_EP0_DRV_STATE_READ_END, sent_stall, transaction_end);
11 
12  //example2: write data ready and set this transaction completed.
13  sent_stall = false;
14  transaction_end = true;
15  hal_usb_update_endpoint_0_state(HAL_USB_EP0_DRV_STATE_WRITE_RDY, sent_stall, transaction_end);
16 
17  //example3: transaction end and clear the transaction_end hardware status.
18  sent_stall = false;
19  transaction_end = true;
20  hal_usb_update_endpoint_0_state(HAL_USB_EP0_DRV_STATE_TRANSACTION_END, sent_stall, transaction_end);
21 }
hal_usb_status_t hal_usb_write_endpoint_fifo ( uint32_t  ep_num,
uint16_t  nBytes,
void *  pSrc 
)

This function writes the USB data to FIFO.

Writing to these addresses loads data into the TX FIFO for the corresponding endpoint.

Parameters
[in]ep_numis the endpoint number.
[in]nBytesis the number of bytes to write.
[in]pSrcis a pointer to the source.
Returns
HAL_USB_STATUS_OK, if the operation completed successfully.
Example
Sample code please refers to "USB PIO data write." in How to use this driver..