Static Stack Configuration
µC/USB-Device is configurable at compile time via approximately 20 #defines
in the application’s copy of usbd_cfg.h
. µC/USB-Device uses #defines
when possible, because they allow code and data sizes to be scaled at compile time based on enabled features and the configured number of USB objects. This allows the Read-Only Memory (ROM) and Random-Access Memory (RAM) footprints of µC/USB-Device to be adjusted based on application requirements.
It is recommended that the configuration process begins with the default configuration values which in the next sections will be shown in bold.
The sections in this chapter are organized following the order in µC/USB-Device’s template configuration file, usbd_cfg.h
.
Core Configuration
Generic Configuration
Constant | Description | Possible values |
---|---|---|
USBD_CFG_OPTIMIZE_SPD | Optimizes for either better performance or for smallest code size. Enabling this define will optimize µC/USB-Device code for better performance and disabling this define will lead to smaller code size. | DEF_ENABLED or DEF_DISABLED |
USBD_CFG_MAX_NBR_DEV | Configures the maximum number of devices. This value should be set to the number of device controllers used on your platform. | Default value is 1. |
USBD_CFG_BUF_ALIGN_OCTETS | Configures the alignment in octets that internal stack’s buffer needs. This value should be set in function of your platform/hardware requirements. If your platform does not require buffer alignment, this should be set to the size of a CPU word (sizeof(CPU_ALIGN) ). | Typically 1, 2, 4 or 8. Default value is sizeof(CPU_ALIGN). |
USBD_ERR_CFG_ARG_CHK_EXT_EN | Allows code to be generated to check arguments for functions that can be called by the user and, for functions which are internal but receive arguments from an API that the user can call. | DEF_ENABLED or
|
USBD_CFG_MS_OS_DESC_EN | Enables or disables support of Microsoft OS descriptors. Enabling this feature will cause the device to respond to Microsoft OS string descriptor requests and Microsoft OS specific descriptors. For more information on Microsoft OS descriptors, refer to the Microsoft Hardware Dev Center. | DEF_ENABLED or DEF_DISABLED |
USB Device Configuration
Constant | Description | Possible Values |
---|---|---|
USBD_CFG_MAX_NBR_CFG | Sets the maximum number of USB configurations used by your device. Keep in mind that if you use a high-speed USB device controller, you will need at least two USB configurations, one for low and full-speed and another for high-speed. Refer to the Universal Serial Bus specification, Revision 2.0, section 9.2.3 for more details on USB configuration. | From 1 (low- or full-speed) or 2 (high-speed) to 254. Default value is 2. |
USBD_CFG_EP_ISOC_EN | Selected portions of μC/USB-Device code required only for isochronous transfers may be disabled to reduce the code size by configuring USBD_CFG_EP_ISOC_EN . This define should be set to DEF_DISABLED if isochronous transfers are not required, to save space. | DEF_ENABLED or DEF_DISABLED |
USBD_CFG_HS_EN | Selected portions of μC/USB-Device code required only for high-speed operation may be disabled to reduce the code size by configuring USBD_CFG_HS_EN . This define should be set to DEF_ENABLED if the USB device controller supports high-speed, or to DEF_DISABLED otherwise. | DEF_ENABLED or DEF_DISABLED |
USBD_CFG_CTRL_REQ_TIMEOUT_mS | Sets the timeout in milliseconds for the Data and the Status phases of a control transfer. This timeout prevent from a deadlock situation during a control transfer processing by the core layer. Thus a value of 0, meaning wait forever, is not allowed. | From 1 to 65535. Default value is 5000. |
Interface Configuration
Constant | Description | Possible Values |
---|---|---|
USBD_CFG_MAX_NBR_IF | Configures the maximum number of interfaces available. This value should at least be equal to USBD_CFG_MAX_NBR_CFG and greatly depends on the USB class(es) used. It represents the total number of interfaces usable for all configurations of your device. Each class instance requires at least one interface, while CDC-ACM requires two.Refer to the Universal Serial Bus specification, Revision 2.0, section 9.2.3 for more details on USB interfaces. | From 1 to 254. Default value is 2. |
USBD_CFG_MAX_NBR_IF_ALT | Defines the maximum number of alternate interfaces (alternate settings) available. This value should at least be equal to USBD_CFG_MAX_NBR_IF and represents the total number of alternate interfaces usable by all interfaces of your device. Refer to the Universal Serial Bus specification, Revision 2.0, section 9.2.3 for more details on alternate settings. | From 1 to 254. Default value is 2. |
USBD_CFG_MAX_NBR_IF_GRP | Defines the maximum number of interface groups or associations available. For the moment, Micrium offers only one USB class (CDC-ACM) that requires interface groups. Refer to the Interface Association Descriptors USB Engineering Change Notice for more details about interface associations. | From 0 to 254. Default value is 0 (should be equal to the number of instances of CDC-ACM). |
USBD_CFG_MAX_NBR_EP_DESC | Defines the maximum number of endpoint descriptors available. This value greatly depends on the USB class(es) used. For information on how many endpoints are needed for each class, refer to the class specific chapter. Keep in mind that control endpoints do not need any endpoint descriptors. | From 0 to 254. Default value is 2. |
USBD_CFG_MAX_NBR_EP_OPEN | Configures the maximum number of opened endpoints per device. If you use more than one device, set this value to the worst case. This value greatly depends on the USB class(es) used. For information on how many endpoints are needed for each class, refer to the class specific chapter. | From 2 to 32. Default value is 4 (2 control plus 2 other endpoints). |
USBD_CFG_MAX_NBR_URB_EXTRA | Defines the number of additional URBs that are used for asynchronous transfers only. Since these URBs are shared between every endpoint, if one endpoint uses them all, other endpoints will not be able to queue any transfer, although it is guaranteed that every endpoint always has one URB still available, to ensure that a transfer can be done at any time. | From 0 to (65535 - USBD_CFG_MAX_NBR_EP_OPEN - USBD_CORE_EVENT_URB_NBR_TOTAL ). Default value is 0. |
String Configuration
Constant | Description | Possible Values |
---|---|---|
USBD_CFG_MAX_NBR_STR | Configures the maximum number of string descriptors supported. This value can be increased if, for example, you plan to add interface specific strings. | From 1 to 254. Default value is 3 (1 descriptor for Manufacturer string, Product string and Serial Number string). |
Debug Configuration
Configurations in this section only need to be set if you use the core debugging service. For more information on that service, see the Debug and Trace page.
Constant | Description | Possible Values | |
---|---|---|---|
USBD_CFG_DBG_TRACE_EN | Enables or disables the core debug trace engine. | DEF_ENABLED or DEF_DISABLED | |
USBD_CFG_DBG_TRACE_NBR_EVENTS | Defines the maximum number of debug trace events that can be queued by the core debug trace engine. This configuration constant has no effect and will not allocate any memory if USBD_CFG_DBG_TRACE_EN is set to DEF_DISABLED . | From 1 to 65535. Default value is 10. |
Classes Configuration
Audio Class Configuration
Constant Description Enables or disables record. Configures the alignment in octets that audio buffers allocated for each AudioStreaming interface will use. The alignment is dependent of the peripheral used to move data between the memory and the audio peripheral. Note that this buffer alignment should be a multiple of the internal stack's buffer alignment set with the constant If the CPU cache is used with the audio buffers, If all above requirements must be taken into account, Possible Values USBD_AUDIO_CFG_PLAYBACK_EN
Enables or disables playback.
DEF_ENABLED
or DEF_DISABLED
USBD_AUDIO_CFG_RECORD_EN
USBD_AUDIO_CFG_PLAYBACK_EN
and USBD_AUDIO_CFG_RECORD_EN
can be DEF_DISABLED
at the same time. In that case, only the AudioControl interface is active. No AudioStreaming interface can be defined. It may be useful to configure an audio device which does not interact with the host through USB for audio streaming.
DEF_ENABLED
or DEF_DISABLED
USBD_AUDIO_CFG_FU_MAX_CTRL
Enables all Feature Unit controls or disables all optional controls. When disabled, only the mute and volume controls are kept. DEF_ENABLED
or
DEF_DISABLED
USBD_AUDIO_CFG_MAX_NBR_AIC
Configures the maximum number of class instances. Unless you plan on having multiple configurations or interfaces using different class instances, this can be set to 1. From 1 to 254. Default value is 1 . USBD_AUDIO_CFG_MAX_NBR_CFG
Configures the maximum number of configurations in which audio class is used. Keep in mind that if you use a high-speed device, two configurations will be built, one for full-speed and another for high-speed. From 1 (full-speed) or 2 (high-speed) to 254. Default value is 2. USBD_AUDIO_CFG_MAX_NBR_IT
Configures the maximum number of input terminals. From 1 to 255. Default value is 2. USBD_AUDIO_CFG_MAX_NBR_OT
Configures the maximum number of output terminals. From 1 to 255. Default value is 2 . USBD_AUDIO_CFG_MAX_NBR_FU
Configures the maximum number of feature units. From 1 to 255. Default value is 2 . USBD_AUDIO_CFG_MAX_NBR_MU
Configures the maximum number of mixer units. A Mixer Unit is optional. From 0 to 255. Default value is 0 . USBD_AUDIO_CFG_MAX_NBR_SU
Configures the maximum number of selector units. A Selector Unit is optional. From 0 to 255. Default value is 0 . USBD_AUDIO_CFG_MAX_NBR_AS_IF_PLAYBACK
Configures the maximum number of playback AudioStreaming interfaces per class instance. From 1 to 255. Default value is 1 .
USBD_AUDIO_CFG_MAX_NBR_AS_IF_RECORD
Configures the maximum number of record AudioStreaming interfaces per class instance. From 1 to 255. Default value is 1 . USBD_AUDIO_CFG_MAX_NBR_IF_ALT
Configures the maximum number of operational alternate setting interfaces per AudioStreaming interface. From 1 to 255. Default value is 2 . USBD_AUDIO_CFG_CLASS_REQ_MAX_LEN
Configures the maximum class-specific request playload length in bytes. Among all class-specific requests supported by Audio 1.0 class, the Graphic Equalizer control of the Feature Unit use the longest payload size for the SET_CUR request. The payload for the Graphic Equalizer control can take up to 34 bytes depending of the number of frequency bands present. If the Graphical Equalizer control is not used by any feature unit, this constant can be set to 4. Refer to audio 1.0 specification, Table 5-27 for more details about Graphic Equalizer control. From 1 to 34. Default value is 4 . USBD_AUDIO_CFG_BUF_ALIGN_OCTETS
USBD_CFG_BUF_ALIGN_OCTETS
as the audio buffers are passed to the USB device controller that can also have its alignment requirement. If your platform does not require buffer alignment, this should be set to USBD_AUDIO_CFG_BUF_ALIGN_OCTETS
.USBD_AUDIO_CFG_BUF_ALIGN_OCTETS
should also take into account the cache line size requirement. To sum up, the value of USBD_AUDIO_CFG_BUF_ALIGN_OCTETS
is influenced by:USBD_AUDIO_CFG_BUF_ALIGN_OCTETS
will be the worst case among all alignment requirements.Typically 1, 2, 4 or 8. Default value is
USBD_CFG_BUF_ALIGN_OCTETS
.USBD_AUDIO_CFG_PLAYBACK_FEEDBACK_EN
Enables or disables the playback feedback support. If an isochronous OUT endpoint using the asynchronous synchronization is associated to an AudioStreaming interface, you need to set
DEF_ENABLED
to enable the feedback support. Refer to section Playback Feedback Correction for more details about the audio feedback.DEF_ENABLED
or
DEF_DISABLED
USBD_AUDIO_CFG_PLAYBACK_CORR_EN
Enables or disables built-in playback stream correction. DEF_ENABLED
or
DEF_DISABLED
USBD_AUDIO_CFG_RECORD_CORR_EN
Enables or disables built-in record stream correction. DEF_ENABLED
or
DEF_DISABLED
USBD_AUDIO_CFG_STAT_EN
Enables or disables audio statistics for playback and record. DEF_ENABLED
or
DEF_DISABLED
Communication Device Class Configuration
Some constants are available to customize the CDC base class. These constants are located in the USB device configuration file, usbd_cfg.h
. Table - CDC Class Configuration Constants shows their description.Constant Description Possible Values USBD_CDC_CFG_MAX_NBR_DEV
Configures the maximum number of class instances. Each associated subclass also defines a maximum number of subclass instances. The sum of all the maximum numbers of subclass instances must not be greater than USBD_CDC_CFG_MAX_NBR_DEV
.From 1 to 254. Default value is 1. USBD_CDC_CFG_MAX_NBR_CFG
Configures the maximum number of configurations in which CDC class is used. Keep in mind that if you use a high-speed device, two configurations will be built, one for full-speed and another for high-speed. From 1 (low- and full-speed) or 2 (high-speed) to 254. Default value is 2. USBD_CDC_CFG_MAX_NBR_DATA_IF
Configures the maximum number of Data interfaces. From 1 to 254. The default value is 1.
CDC Abstract Control Model Serial Class Configuration
usbd_cfg.h
.Constant Description Possible Values USBD_ACM_SERIAL_CFG_MAX_NBR_DEV
Configures the maximum number of subclass instances. The constant value cannot be greater than USBD_CDC_CFG_MAX_NBR_DEV
. Unless you plan on having multiple configurations or interfaces using different class instances, this can be set to the default value.From 1 to USBD_CDC_CFG_MAX_NBR_DEV
. Default value is 1.
Communication Device Class Ethernet Emulation Model Subclass Configuration
There are various configuration constants necessary to customize the CDC EEM subclass. These constants are located in the usbd_cfg
.h file. Table - CDC EEM Configuration Constants shows a description of each constant.Constant Description Possible Values USBD_CDC_EEM_CFG_MAX_NBR_DEV
Configures the maximum number of class instances. Unless you plan having multiple configuration or interfaces using different class instances, this should be set to 1. From 1 to 254. Default value is 1. USBD_CDC_EEM_CFG_MAX_NBR_CFG
Configures the maximum number of configuration in which CDC EEM is used. Keep in mind that if you use a high-speed device, two configurations will be built, one for full-speed and another for high-speed. From 1 (full-speed) or 2 (high-speed) to 254. Default value is 2. USBD_CDC_EEM_CFG_RX_BUF_LEN
Configures the length, in octets, of the buffer(s) used to receive the data from the host. This buffer must ideally be a multiple of the max packet size of the endpoint. However, most of the time this can be set to the Ethernet Maximum Transmit Unit (MTU -> 1518) + 2 for the CDC EEM header for better performances. 64 or more. Multiple of maximum packet size if below (MTU + 2). Default value is 1520. USBD_CDC_EEM_CFG_ECHO_BUF_LEN
Configures the length, in octets, of the echo buffer used to transmit an echo response command upon reception of an echo command from the host. Size of this buffer depends on the largest possible echo data that can be sent by the host. Higher than 2. Default value is 64. USBD_CDC_EEM_CFG_RX_BUF_QTY_PER_DEV
(optional)Configures the quantity of receive buffers to be used to receive data from the host. It is not mandatory to set the value in your usbd_cfg.h
file. Before setting this value to something higher than 1, you MUST ensure that you USB device driver supports URB queuing. You must also correctly configure the constant USBD_CFG_MAX_NBR_URB_EXTRA
. Increasing this value will improve the data reception performances by providing multiple buffering mechanism.1 or more. Default value is 1.
Human Interface Device Class Configuration
The HID class uses an internal task to manage periodic input reports. The task priority and stack size shown in Table - HID Internal Task’s Configuration Constants are defined in the application configuration file, Constant Description Possible Values USBD_HID_CFG_MAX_NBR_DEV
Configures the maximum number of class instances. Unless you plan on having multiple configurations or interfaces using different class instances, this can be set to the default value. From 1 to 254. Default value is 1. USBD_HID_CFG_MAX_NBR_CFG
Configures the maximum number of configurations in which HID class is used. Keep in mind that if you use a high-speed device, two configurations will be built, one for full-speed and another for high-speed. From 1 (low- and full-speed) or 2 (high-speed) to 254. Default value is 2. USBD_HID_CFG_MAX_NBR_REPORT_ID
Configures the maximum number of report IDs allowed in a report. The value should be set properly to accommodate the number of report ID to be used in the report. From 1 to 65535. Default value is 1. USBD_HID_CFG_MAX_NBR_REPORT_PUSHPOP
Configures the maximum number of Push and Pop items used in a report. If the constant is set to 0, no Push and Pop items are present in the report. From 0 to 254. Default value is 0. app_cfg.h
. Refer to the HID Periodic Input Reports Task page for more details about the HID internal task.Constant Description Possible Values USBD_HID_OS_CFG_TMR_TASK_PRIO
Configures the priority of the HID periodic input reports task. From the lowest to the highest priority supported by the OS used. USBD_HID_OS_CFG_TMR_TASK_STK_SIZE
Configures the stack size of the HID periodic input reports task. The required size of the stack can greatly vary depending on the OS used, the CPU architecture, the type of application, etc. Refer to the documentation of the OS for more details about tasks and stack size calculation. From the minimal to the maximal stack size supported by the OS used.
Mass Storage Class Configuration
There are various configuration constants necessary to customize the MSC device. These constants are located in the usbd_cfg.h file. Table - MSC Configuration Constants shows a description of each constant. Since MSC device relies on a task handler to implement the MSC protocol, this OS-task’s priority and stack size constants need to be configured if µC/OS-II or µC/OS-III RTOS is used. Moreover if Constant Description Possible Values USBD_MSC_CFG_MAX_NBR_DEV
Configures the maximum number of class instances. Unless you plan having multiple configuration or interfaces using different class instances, this should be set to 1. From 1 to 254. Default value is 1. USBD_MSC_CFG_MAX_NBR_CFG
Configures the maximum number of configuration in which MSC is used. Keep in mind that if you use a high-speed device, two configurations will be built, one for full-speed and another for high-speed. From 1 (low- and full-speed) or 2 (high-speed) to 254. Default value is 2. USBD_MSC_CFG_MAX_LUN
Configures the maximum number of logical units. From 1 to 255. Default value is 1. USBD_MSC_CFG_DATA_LEN
Configures the read/write data length in octets. Higher than 0. The default value is 2048. USBD_MSC_CFG_FS_REFRESH_TASK_EN
Enables or disables the use of a task in µC/FS storage layer for removable media insertion/removal detection. If only fixed media such as RAM, NAND are used, this constant should be set to DEF_DISABLED
. Otherwise, DEF_ENABLED
should be set.DEF_ENABLED
or DEF_DISABLED
USBD_MSC_CFG_DEV_POLL_DLY_mS
Configures the period of the µC/FS storage layer’s task. It is expressed in milliseconds. If USBD_MSC_CFG_FS_REFRESH_TASK_EN
is set to DEF_DISABLED
, this constant has no effect. A faster period may improve the delay to detect the removable media insertion/removal resulting in a host computer displaying the removable media icon promptly. But the CPU will be interrupted often to check the removable media status. A slower period may result in a certain delay for the host computer to display the removable media icon. But the CPU will spend less time verifying the removable media status.The default value is 100 ms. USBD_MSC_CFG_FS_REFRESH_TASK_EN
is set to DEF_ENABLED
, the µC/FS storage layer task’s priority and stack size need also to be configured. These constants are summarized in Table - MSC OS-Task Handler Configuration Constants.Constant Description Possible Values USBD_MSC_OS_CFG_TASK_PRIO
MSC task handler’s priority level. The priority level must be lower (higher valued) than the start task and core task priorities. From the lowest to the highest priority supported by the OS used. USBD_MSC_OS_CFG_TASK_STK_SIZE
MSC task handler’s stack size. The required size of the stack can greatly vary depending on the OS used, the CPU architecture, the type of application, etc. Refer to the documentation of the OS for more details about tasks and stack size calculation. From the minimal to the maximal stack size supported by the OS used. Default value is set to 256. USBD_MSC_OS_CFG_REFRESH_TASK_PRIO
µC/FS storage layer task’s priority level. The priority level must be lower (higher valued) than the MSC task. From the lowest to the highest priority supported by the OS used. USBD_MSC_OS_CFG_REFRESH_TASK_STK_SIZE
µC/FS storage layer task’s stack size. The required size of the stack can greatly vary depending on the OS used, the CPU architecture, the type of application, etc. Refer to the documentation of the OS for more details about tasks and stack size calculation. From the minimal to the maximal stack size supported by the OS used. Default value is set to 256.
Personal Healthcare Device Class Configuration
Some constants are available to customize the class. These constants are located in the If using µC/OS-II or µC/OS-III RTOS port, enable or disable the scheduler feature. You should set it to If you set QoS based scheduler’s task priority. You must ensure that the scheduler’s task has a lower priority (i.e. higher priority value) than any task writing PHDC data.usbd_cfg.h
file. Table - Configuration Constants Summary shows a description of each of them.Constant Description Possible Values USBD_PHDC_CFG_MAX_NBR_DEV
Configures the maximum number of class instances. Unless you plan on having multiple configuration or interfaces using different class instances, this can be set to 1. From 1 to 254. Default value is 1. USBD_PHDC_CFG_MAX_NBR_CFG
Configures the maximum number of configuration in which PHDC is used. Keep in mind that if you use a high-speed device, two configurations will be built, one for full-speed and another for high-speed. Default value is 2. From 1 (low- and full-speed) or 2 (high-speed) to 254. Default value is 2. USBD_PHDC_CFG_DATA_OPAQUE_MAX_LEN
Maximum length in octets that opaque data can be. Equal or less than MaxPacketSize - 21. Default value is 43. USBD_PHDC_OS_CFG_SCHED_EN
DEF_DISABLED
if the device only uses one QoS level to send data, for instance. (See the PHDC RTOS QoS-based scheduler page). If you set USBD_PHDC_OS_CFG_SCHED_EN
to DEF_ENABLED
and you use a µC/OS-II or µC/OS-III RTOS port, PHDC will need an internal task for the scheduling operations. There are two application specific configurations that must be set in this case. They should be defined in the app_cfg.h
file.DEF_ENABLED
, you must ensure that the scheduler’s task has a lower priority (i.e., higher priority value) than any task that can write PHDC data.
DEF_ENABLED
or DEF_DISABLED
USBD_PHDC_OS_CFG_SCHED_EN
to DEF_ENABLED
and you use a µC/OS-II or µC/OS-III RTOS port, PHDC will need an internal task for the scheduling operations. There are two application specific configurations that must be set in this case. They should be defined in the app_cfg.h
file. Table - Application-Specific Configuration Constants describes these configurations.Constant Description Possible Values USBD_PHDC_OS_CFG_SCHED_TASK_PRIO
From the lowest to the highest priority supported by the OS used. USBD_PHDC_OS_CFG_SCHED_TASK_STK_SIZE
QoS based scheduler’s task stack size. The required size of the stack can greatly vary depending on the OS used, the CPU architecture, the type of application, etc. Refer to the documentation of the OS for more details about tasks and stack size calculation. From the minimal to the maximal stack size supported by the OS used. Default value is 512.
Vendor Class Configuration
Some constants are available to customize the class. These constants are located in the USB device configuration file, Configures the maximum number of Microsoft extended properties that can be defined per Vendor class instance. For more information on Microsoft OS descriptors and extended properties, refer to the Microsoft Hardware Dev Center .usbd_cfg.h
. Table - General Configuration Constants Summary shows their description.Constant Description Possible Values USBD_VENDOR_CFG_MAX_NBR_DEV
Configures the maximum number of class instances. Unless you plan on having multiple configurations or interfaces using different class instances, this can be set to 1. From 1 to 254. Default value is 1. USBD_VENDOR_CFG_MAX_NBR_CFG
Configures the maximum number of configuration in which Vendor class is used. Keep in mind that if you use a high-speed device, two configurations will be built, one for full-speed and another for high-speed. From 1 (low- and full-speed) or 2 (high-speed) to 254. Default value is 2. USBD_VENDOR_CFG_MAX_NBR_MS_EXT_PROPERTY
From 1 to 255. Default value is 1.