High level interface for interacting with the USB Device.
This block supports one control endpoint (EP0) and one or more data endpoints. See the device datasheet for the number of data endpoints supported.
Four transfer types are supported (see cyhal_usb_dev_ep_type_t):
cyhal_usb_dev_init can be used for initialization of USB by providing the USBDP and USBDM pins. See Snippet 1: USB Device Initialization for the initialization code snippet.
The following section initializes the USB Device and assigns the USBDM and USBDP pins using cyhal_usb_dev_init. The clock parameter clk is optional and need not be provided (NULL), to generate and use an available clock resource with a default frequency. The device can be made physically visible to the USB Host by using cyhal_usb_dev_connect
USB events (see cyhal_usb_dev_event_t) like Bus Reset, EP0 transaction, EP0 Setup can be mapped to an interrupt and assigned a callback function. The callback function needs to be first registered using cyhal_usb_dev_register_event_callback. Use different callback functions to handle events individually.
The following section illustrates how to set up the IRQ interrupt handler for USB device. Inside the handler cyhal_usb_dev_process_irq has been used to process the interrupts.
The following section shows how to add endpoint to the USB device and configure the endpoint using cyhal_usb_dev_endpoint_add. The interrupts associated with the endpoints are handled by a callback function registered using cyhal_usb_dev_register_endpoint_callback. The endpoint can also be configured using ModusToolbox USB Configurator
API Reference | |
USB Device HAL Results | |
USB Device specific return codes. | |
Endpoint | |
APIs relating to endpoint management. | |
Common | |
EP0 | |
APIs relating specifically to management of endpoint zero. | |