This is the quick start guide for the USB Device Vendor Module (UDI Vendor) with step-by-step instructions on how to configure and use the modules in a selection of use cases.
The use cases highlights several code fragments. The code fragments in the steps for setup can be copied into a custom initialization function, while the steps for usage can be copied into, e.g., the main application function.
Basic Use Case
In this basic use case, the "USB Vendor (Single Class support)" module is used. The "USB Vendor (Composite Device)" module usage is described in Advanced Use Cases.
Setup Steps
As a USB device, it follows common USB device setup steps. Refer to USB Device Basic Setup.
Usage Steps
Example code
Content of conf_usb.h:
* #define UDI_VENDOR_ENABLE_EXT() my_callback_vendor_enable()
* extern bool my_callback_vendor_enable(void);
* #define UDI_VENDOR_DISABLE_EXT() my_callback_vendor_disable()
* extern void my_callback_vendor_disable(void);
*
* #define UDI_VENDOR_SETUP_OUT_RECEIVED() my_vendor_setup_out_received()
* extern bool my_vendor_setup_out_received(void);
* #define UDI_VENDOR_SETUP_IN_RECEIVED() my_vendor_setup_in_received()
* extern bool my_vendor_setup_in_received(void);
*
* #define UDI_VENDOR_EPS_SIZE_INT_FS 64
* #define UDI_VENDOR_EPS_SIZE_BULK_FS 64
* #define UDI_VENDOR_EPS_SIZE_ISO_FS 256
* #define UDI_VENDOR_EPS_SIZE_INT_HS 64
* #define UDI_VENDOR_EPS_SIZE_BULK_HS 512
* #define UDI_VENDOR_EPS_SIZE_ISO_HS 64
* #include "udi_vendor_conf.h"
Add to application C-file:
static bool my_flag_autorize_vendor_transfert = false;
bool my_callback_vendor_enable(void)
{
my_flag_autorize_vendor_transfert = true;
return true;
}
void my_callback_vendor_disable(void)
{
my_flag_autorize_vendor_transfert = false;
}
uint8_t global_buffer[X];
void task(void)
{
if (my_flag_autorize_vendor_transfert) {
global_buffer,
sizeof(global_buffer),
NULL);
global_buffer,
sizeof(global_buffer),
NULL);
...
}
}
Workflow
- Ensure that conf_usb.h is available and contains the following configuration, which is the USB device Vendor configuration:
#define UDI_VENDOR_ENABLE_EXT() my_callback_vendor_enable()
extern bool my_callback_vendor_enable(void);
- Note
- After the device enumeration (detecting and identifying USB devices), the USB host starts the device configuration. When the USB Vendor interface from the device is accepted by the host, the USB host enables this interface and the UDI_VENDOR_ENABLE_EXT() callback function is called and return true. Thus, when this event is received, the Vendor transfers can start.
#define UDI_VENDOR_DISABLE_EXT() my_callback_vendor_disable()
extern void my_callback_vendor_disable(void);
- Note
- When the USB device is unplugged or is reset by the USB host, the USB interface is disabled and the UDI_VENDOR_DISABLE_EXT() callback function is called. Thus, it is recommended to disable the data Vendor transfer.
#define UDI_VENDOR_SETUP_OUT_RECEIVED() my_vendor_setup_out_received()
extern bool my_vendor_setup_out_received(void);
#define UDI_VENDOR_SETUP_IN_RECEIVED() my_vendor_setup_in_received()
extern bool my_vendor_setup_in_received(void);
- Note
- The control requests for the interface Vendor will be processed through these both callbacks.
#define UDI_VENDOR_EPS_SIZE_INT_FS 64
#define UDI_VENDOR_EPS_SIZE_BULK_FS 64
#define UDI_VENDOR_EPS_SIZE_ISO_FS 256
#define UDI_VENDOR_EPS_SIZE_INT_HS 64
#define UDI_VENDOR_EPS_SIZE_BULK_HS 512
#define UDI_VENDOR_EPS_SIZE_ISO_HS 64
- Note
- The endpoint size is defined by the final application, and can be disabled if the full speed size is zero.
- The Vendor transfers on interrupt, bulk, and isochronous endpoints are done through these functions:
Advanced Use Cases
For multiple interface use of UDI Vendor module, see the following:
For more advanced use of the UDI Vendor module, see the following: