CDC in a composite device

A USB Composite Device is a USB Device which uses more than one USB class. In this use case, the "USB CDC (Composite Device)" module is used to create a USB composite device. Thus, this USB module can be associated with another "Composite Device" module, like "USB HID Mouse (Composite Device)".

Also, you can refer to application note AVR4902 ASF - USB Composite Device.

Setup steps

For the setup code of this use case to work, the basic use case must be followed.

Usage steps

Example code

Content of conf_usb.h:

#define USB_DEVICE_EP_CTRL_SIZE 64
#define USB_DEVICE_NB_INTERFACE (X+2)
#define USB_DEVICE_MAX_EP (X+3)
#define UDI_CDC_DATA_EP_IN_0 (1 | USB_EP_DIR_IN) // TX
#define UDI_CDC_DATA_EP_OUT_0 (2 | USB_EP_DIR_OUT) // RX
#define UDI_CDC_COMM_EP_0 (3 | USB_EP_DIR_IN) // Notify endpoint
#define UDI_CDC_COMM_IFACE_NUMBER_0 X+0
#define UDI_CDC_DATA_IFACE_NUMBER_0 X+1
#define UDI_COMPOSITE_DESC_T \
usb_iad_desc_t udi_cdc_iad; \
udi_cdc_comm_desc_t udi_cdc_comm; \
udi_cdc_data_desc_t udi_cdc_data; \
...
#define UDI_COMPOSITE_DESC_FS \
.udi_cdc_iad = UDI_CDC_IAD_DESC_0, \
.udi_cdc_comm = UDI_CDC_COMM_DESC_0, \
.udi_cdc_data = UDI_CDC_DATA_DESC_0_FS, \
...
#define UDI_COMPOSITE_DESC_HS \
.udi_cdc_iad = UDI_CDC_IAD_DESC_0, \
.udi_cdc_comm = UDI_CDC_COMM_DESC_0, \
.udi_cdc_data = UDI_CDC_DATA_DESC_0_HS, \
...
#define UDI_COMPOSITE_API \
&udi_api_cdc_comm, \
&udi_api_cdc_data, \
...

Workflow

  1. Ensure that conf_usb.h is available and contains the following parameters required for a USB composite device configuration:
    • // Endpoint control size, This must be:
      // - 8, 16, 32 or 64 for full speed device (8 is recommended to save RAM)
      // - 64 for a high speed device
      #define USB_DEVICE_EP_CTRL_SIZE 64
      // Total Number of interfaces on this USB device.
      // Add 2 for CDC.
      #define USB_DEVICE_NB_INTERFACE (X+2)
      // Total number of endpoints on this USB device.
      // This must include each endpoint for each interface.
      // Add 3 for CDC.
      #define USB_DEVICE_MAX_EP (X+3)
  2. Ensure that conf_usb.h contains the description of composite device:
    • // The endpoint numbers chosen by you for the CDC.
      // The endpoint numbers starting from 1.
      #define UDI_CDC_DATA_EP_IN_0 (1 | USB_EP_DIR_IN) // TX
      #define UDI_CDC_DATA_EP_OUT_0 (2 | USB_EP_DIR_OUT) // RX
      #define UDI_CDC_COMM_EP_0 (3 | USB_EP_DIR_IN) // Notify endpoint
      // The interface index of an interface starting from 0
      #define UDI_CDC_COMM_IFACE_NUMBER_0 X+0
      #define UDI_CDC_DATA_IFACE_NUMBER_0 X+1
  3. Ensure that conf_usb.h contains the following parameters required for a USB composite device configuration:
    • // USB Interfaces descriptor structure
      #define UDI_COMPOSITE_DESC_T \
      ...
      usb_iad_desc_t udi_cdc_iad; \
      udi_cdc_comm_desc_t udi_cdc_comm; \
      udi_cdc_data_desc_t udi_cdc_data; \
      ...
      // USB Interfaces descriptor value for Full Speed
      #define UDI_COMPOSITE_DESC_FS \
      ...
      .udi_cdc_iad = UDI_CDC_IAD_DESC_0, \
      .udi_cdc_comm = UDI_CDC_COMM_DESC_0, \
      .udi_cdc_data = UDI_CDC_DATA_DESC_0_FS, \
      ...
      // USB Interfaces descriptor value for High Speed
      #define UDI_COMPOSITE_DESC_HS \
      ...
      .udi_cdc_iad = UDI_CDC_IAD_DESC_0, \
      .udi_cdc_comm = UDI_CDC_COMM_DESC_0, \
      .udi_cdc_data = UDI_CDC_DATA_DESC_0_HS, \
      ...
      // USB Interface APIs
      #define UDI_COMPOSITE_API \
      ...
      ...
    • Note
      The descriptors order given in the four lists above must be the same as the order defined by all interface indexes. The interface index orders are defined through UDI_X_IFACE_NUMBER defines.
      Also, the CDC requires a USB Interface Association Descriptor (IAD) for composite device.


inertial_sense_ros
Author(s):
autogenerated on Sat Sep 19 2020 03:19:07