USB Component
Version 6.6
MDK-Professional Middleware for USB Device and Host
|
This section describes the resource requirements of the USB component.
The following section documents the requirements for the USB Device component. The actual requirements depend on the components used in the application and the configuration of these components.
The USB Device Core receives events sent from the interrupt service routine (ISR) of the USB Device Driver. The stack requirements for the ISR are typically less than 512 Bytes. The total stack space required for ISR depends on the interrupt nesting and therefore on the priority settings of these ISR. The stack requirements for ISR are configured in the startup_device.s file located under the Device component class.
Option (under section Stack Configuration) | Increase Value by |
---|---|
Stack Size (in Bytes) | + 512 for USB Device Driver |
User code that calls API functions of the USB Device Component should have a minimum of 512 Bytes of stack space available. Since API functions are frequently called from threads, the thread stack size should be at least 512 Bytes (see below).
The USB Device component uses CMSIS-RTOS threads. Each instance of a component starts its own threads, for example two HID instances start two threads with the name: USBD_HID0_Thread, USBD_HID1_Thread. The thread execution starts with USBD_Initialize. All threads execute with priority osPriorityAboveNormal on an user-provided stack.
The following table lists the components, number of threads executed along with thread name, the default stack size, and the configuration file with OS Resource Settings for stack size adjustments.
Component | Threads / Thread Name | Default Stack Size | Configuration File |
---|---|---|---|
::USB:Device | 1 / USBDn_Core_Thread | 512 Bytes | USBD_Config_n.c |
::USB:Device:ADC | 1 / USBD_ADCn_Thread | 512 Bytes | USBD_Config_ADC_n.c |
::USB:Device:CDC | 2 / USBD_CDCn_Bulk_Thread, USBD_CDCn_Int_Thread | 512 Bytes | USBD_Config_CDC_n.c |
::USB:Device:Custom Class | 1...15 / USBD_CustomClassn_EPm_Thread | 512 Bytes | USBD_Config_CustomClass_n.c |
::USB:Device:HID | 1 / USBD_HIDn_Thread | 512 Bytes | USBD_Config_HID_n.c |
::USB:Device:MSC | 1 / USBD_MSCn_Thread | 512 Bytes | USBD_Config_MSC_n.c |
n is instance number, m is Endpoint number 1...15
For the USB Device component, the number of threads and thread stack size requirements are calculated as follows:
With default stack size of 512 Bytes, the Total stack size is Number of Threads * 512 Bytes. When the default OS Resource Settings are modified, the changes need to be considered for the calculation of the Total stack size.
Examples (with default stack size 512 Bytes):
The thread requirements need to be reflected in the CMSIS-RTOS configuration. Refer to the CMSIS-RTOS Reference for further details.
For CMSIS-RTOS RTX, the threads requirements are configured in the RTX_Conf_CM.c file located under the CMSIS component class.
Option (under section Thread Configuration) | Increase Value by |
---|---|
Number of concurrent running threads | + Number of Threads |
Number of threads with user-provided stack size | + Number of Threads |
Total stack size [bytes] for threads with user-provided stack size | + Total stack size |
System Configuration
The ::USB:Device:HID component requires User Timers to be selected. The Timer Thread Stack is commonly used by all threads working with User Timers. Depending on the application and the further usage of the timers, the Timer Thread stack size needs to be increased accordingly.
The following table shows the memory requirements for read-only (Flash) and read-write (RAM) memory. These numbers may be used to estimate the total size requirements of the application, but the actual numbers depend on compiler optimizations and target processor and may be therefore slightly different.
Component | RO Memory [Bytes] | RW Memory (Data) [Bytes] |
---|---|---|
::USB:Core (Device) | 5.0 k | < 200 |
::USB:Device:ADC | 1.2 k | < 40 + Subframe Size (configured in USBD_Config_ADC_n.h) |
::USB:Device:HID | 2.6 k | < 70 + Report Sizes (configured in USBD_Config_HID_n.h) |
::USB:Device:MSC | 4.0 k | < 100 + Bulk Buffer Size (configured in the USBD_Config_MSC_n.h) |
::USB:Device:CDC | 2.1 k | < 40 + Send/Receive Buffer Size (configured in the USBD_Config_CDC_n.h) |
::USB:Device:Custom Class | 2.4 k | < 30 |
USB Device Driver | 1 .. 4 k | 0.5 .. 4 k |
The following section documents the requirements for the USB Host component. The actual requirements depend on the components used in the application and the configuration of these components.
The USB Host Core receives events sent from the interrupt service routine (ISR) of the USB Host Driver. The stack requirements for the ISR are typically less than 512 Bytes. The total stack space required for ISR depends on the interrupt nesting and therefore on the priority settings of these ISR. The stack requirements for ISR is configured in the startup_device.s file located in the Device components.
Option (under section Stack Configuration) | Increase Value by |
---|---|
Stack Size (in Bytes) | + 512 for USB Host Driver |
User code that calls API functions of the USB Host Component should have a minimum of 512 Bytes of stack space available. Since API functions are frequently called from threads, the thread stack size should be at least 512 Bytes.
The USB Host component uses CMSIS-RTOS threads. Each USB Host instance starts its own thread (USBHn_Core_Thread). The thread execution starts with USBH_Initialize. Additionally each instance of HID and CDC class also start their own thread (USBH_HID_IntIn_Thread or USBH_CDC_IntIn_Thread) when HID or CDC device is connected. All threads execute with priority osPriorityAboveNormal on an user-provided stack.
The following table lists the components, number of threads executed along with thread name, the default stack size, and the configuration file with OS Resource Settings for stack size adjustments.
Component | Threads / Thread Name | Default Stack Size | Configuration File |
---|---|---|---|
::USB:Host | 1 / USBHn_Core_Thread | 640 Bytes | USBH_Config_n.c |
::USB:Host:CDC | 1 / USBH_CDC_IntIn_Thread | 384 Bytes | USBH_Config_CDC.h |
::USB:Host:HID | 1 / USBH_HID_IntIn_Thread | 384 Bytes | USBH_Config_HID.h |
n is instance number
For the USB Host component, the number of threads and thread stack size requirements are calculated as follows:
With default stack sizes as defined above the Total stack size is sum of Default Stack Sizes. When the default OS Resource Settings are modified, the changes need to be considered for the calculation of the Total stack size.
Examples (with default stack sizes):
The thread requirements need to be reflected in the CMSIS-RTOS configuration. Refer to the CMSIS-RTOS Reference for further details.
For CMSIS-RTOS RTX, the threads requirements are configured in the RTX_Conf_CM.c
file located in the CMSIS components.
Option (under section Thread Configuration) | Increase Value by |
---|---|
Number of concurrent running threads | + Number of Threads |
Number of threads with user-provided stack size | + Number of Threads |
Total stack size [bytes] for threads with user-provided stack size | + Total stack size |
System Configuration
The ::USB:Host component requires User Timers to be selected. The Timer Thread Stack is commonly used by all threads working with User Timers. Depending on the application and the further usage of the timers, the Timer Thread stack size needs to be increased accordingly.
Signals
Using the USB Host Mass Storage class together with the File System provides the user access to the files on an attached USB memory stick through the File System API (fopen, fread, fwrite, etc.). Any user thread calling those functions is blocked internally in the library by waiting for the lower eight signals (0x00XX). Those signals are reserved for the USB Host communication and must not be used by the user application in that thread.
The following table shows the memory requirements for read-only (Flash) and read-write (RAM) memory. These numbers may be used to estimate the total size requirements of the application, but the actual numbers depend on compiler optimizations and target processor and may be therefore slightly different.
Component | RO Memory [Bytes] | RW Memory (Data) [Bytes] |
---|---|---|
::USB:Core (Host) | < 9.0 k | < 120 + Memory Pool Size (configured in USBH_Config_n.c) |
::USB:Host:HID | < 3.0 k | < 80 |
::USB:Host:MSC | < 4.5 k | < 50 |
USB Host OHCI support | < 3.5 k | < 0.5 k |
USB Host EHCI support | < 5.0 k | < 4.5 k |