USB stack configuration
Device configuration
A device configuration file is set up for each example, such as:
<install_dir>/boards/twrk22f120m/usb_examples/usb_device_hid_mouse/bm/usb_device_config.h
This file is used to either enable or disable the USB class driver and to configure the interface type (high-speed or full speed). The object number is configurable either to decrease the memory usage or to meet specific requirements.
If the device stack configuration is changed, rebuild the example projects. For each device, follow these steps.
If the board is a Tower or Freedom platform, enable the following macros:
Enable #define USB_DEVICE_CONFIG_KHCI (0U) macro for full speed.
Enable #define USB_DEVICE_CONFIG_EHCI (0U) macro if the board supports high-speed.
Note: Only EHCI support pin detect feature.
If board is part of the LPC series, enable the following macros:
Enable #define USB_DEVICE_CONFIG_LPCIP3511FS (0U) macro for full speed.
Enable #define USB_DEVICE_CONFIG_LPCIP3511HS (0U) macro if the board supports high-speed.
Parent topic:USB stack configuration
Host configuration
A host configuration file is set up for each example, such as:
<install_dir>/boards/twrk22f120m/usb_examples/usb_host_hid_mouse/bm/usb_host_config.h
This file is used to either enable or disable the USB class driver. The object number is configurable either to decrease the memory usage or to meet specific requirements.
If the Host stack configuration is changed, rebuild the example projects.
For each Host, follow these steps.
If the board is a Tower for Freedom platform, enable the following macros:
Enable this macro for full speed.
#define USB_HOST_CONFIG_KHCI (0U)
Enable this macro if the board supports high-speed.
#define USB_HOST_CONFIG_EHCI (0U)
Note: Only EHCI support pin detect feature.
If board is part of the LPC series, enable the following macros:
Enable this macro for full speed.
#define USB_HOST_CONFIG_OHCI (0U)
Enable this macro if the board supports high-speed.
#define USB_HOST_CONFIG_IP3516HS (0U)
Parent topic:USB stack configuration
USB cache-related MACROs definitions
There are few MACROs in the USB stack to define USB data attributes.
USB_STACK_USE_DEDICATED_RAM
The following values are used to configure the USB stack to use dedicated RAM or not.
USB_STACK_DEDICATED_RAM_TYPE_BDT_GLOBAL - The USB device global variables (controller data and device stack data) are put into the USB-dedicated RAM.
USB_STACK_DEDICATED_RAM_TYPE_BDT - The USB device controller global variables (BDT data) are put into the USB-dedicated RAM.
0 - There is no USB-dedicated RAM.
This macro is set 1 now. It is used to indicate if the USB dedicated RAM is present. This macro is enabled on evkmimxrt595, evkmimxrt685, mimxrt685audevk, frdmk32l2a4s, lpcxpresso54628, lpcxpresso54s018, lpcxpresso54s018m, lpcxpresso55s16, lpcxpresso55s28, lpcxpresso55s69.
DATA_SECTION_IS_CACHEABLE
The following values are used to indicate that the currently used memory is cacheable or not.
0: non-cacheable
1: cacheable
This macro is set 0 by default now. This macro indicates whether the memory is cacheable or not. When set to 1, it indicates the current memory is cacheable. When set to 0, it indicates non-cacheable memory. When memory is cacheable, USB stack uses non-cacheable region to locate USB-transfer buffers and controller data to prevent cache coherency issues. When memory is on-cacheable, no special memory handling is required.
Please note that this macro is used in combination with USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE/USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE. If you still want to locate USB transfer buffers and controller data in cacheable memory, you should use cache maintenance operations and disable the DATA_SECTION_IS_CACHEABLE macro, then enable USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE/USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE accordingly. Please refer to the detailed introduction of these two macros below.
USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE
The following values are used to configure the device stack cache to be enabled or not.
0: disabled
1: enable
This macro is set 1 by default now. It is used to enable cache maintenance for cacheable target (data region is cacheable) on RT4 digits platform and mimxrt700evk. The RT4 digits boards include evkmimxrt1010, evkmimxrt1015, evkmimxrt1020, evkmimxrt1024, evkmimxrt1040, evkbimxrt1050, evkbmimxrt1060, evkcmimxrt1060, evkmimxrt1064, evkmimxrt1160, etc.
Please note that this macro controls the USB stack’s cache behavior and should be configured based on the specific target platform’s memory configuration. When memory is cacheable, this macro should be enabled. When memory is non-cacheable, this macro should be disabled. Also note that please keep DATA_SECTION_IS_CACHEABLE disabled when this DUSB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE is enabled, which means that these two macros have opposite settings - when one is enabled, the other should be disabled.
USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE
The following values are used to configure host stack cache to be enabled or not.
0: disable
1: enable
This macro is set 1 by default now. It is used to enable cache maintainance for cacheable target (data region is cacheable) on RT4 digits platform and mimxrt700evk. The RT4 digits boards include evkmimxrt1010, evkmimxrt1015, evkmimxrt1020, evkmimxrt1024, evkmimxrt1040, evkbimxrt1050, evkbmimxrt1060, evkcmimxrt1060, evkmimxrt1064, evkmimxrt1160, etc.
Please note that this macro controls the USB stack’s cache behavior and should be configured based on the specific target platform’s memory configuration. When memory is cacheable, this macro should be enabled. When memory is non-cacheable, this macro should be disabled. Also note that please keep DATA_SECTION_IS_CACHEABLE disabled when this DUSB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE is enabled, which means that these two macros have opposite settings - when one is enabled, the other should be disabled.
Based on the above MACROs, the following cache-related MACROs are defined in the USB stack.
||USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE ||
USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE is true
|USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE ||
USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE is false
|
|USB_STACK_USE_DEDICATED_RAM’s Value| |DATA_SECTION_IS_CACHEABLE is true|DATA_SECTION_IS_CACHEABLE is false|
|USB_STACK_DEDICATED_RAM_TYPE_BDT_GLOBAL||USB_GLOBAL|dedicated ram, stack use only|
|USB_BDT|dedicated ram, stack use only|
|USB_CONTROLLER_DATA|NonCachable, stack use only|
|USB_DMA_NONINIT_DATA_ALIGN(n)|cachable ram and alignment|
|USB_DMA_INIT_DATA_ALIGN(n)|cachable ram and alignment|
||USB_GLOBAL|dedicated ram, stack use only|
|USB_BDT|dedicated ram, stack use only|
|USB_CONTROLLER_DATA|NonCachable, stack use only|
|USB_DMA_NONINIT_DATA_ALIGN(n)|noncachable ram and alignment|
|USB_DMA_INIT_DATA_ALIGN(n)|noncachable ram and alignment|
||USB_GLOBAL|dedicated ram, stack use only|
|USB_BDT|dedicated ram, stack use only|
|USB_CONTROLLER_DATA|dedicated ram, stack use only|
|USB_DMA_NONINIT_DATA_ALIGN(n)|alignment|
|USB_DMA_INIT_DATA_ALIGN(n)|alignment|
|
|USB_STACK_DEDICATED_RAM_TYPE_BDT||USB_GLOBAL|cachable ram and alignment, stack use only|
|USB_BDT|dedicated ram, stack use only|
|USB_CONTROLLER_DATA|NonCachable, stack use only|
|USB_DMA_NONINIT_DATA_ALIGN(n)|cachable ram and alignment|
|USB_DMA_INIT_DATA_ALIGN(n)|cachable ram and alignment|
||USB_GLOBAL|NonCachable, stack use only|
|USB_BDT|dedicated ram, stack use only|
|USB_CONTROLLER_DATA|NonCachable, stack use only|
|USB_DMA_NONINIT_DATA_ALIGN(n)|NonCachable and alignment|
|USB_DMA_INIT_DATA_ALIGN(n)|NonCachable and alignment|
||USB_GLOBAL|NULL, stack use only|
|USB_BDT|dedicated ram, stack use only|
|USB_CONTROLLER_DATA|NULL, stack use only|
|USB_DMA_NONINIT_DATA_ALIGN(n)|alignment|
|USB_DMA_INIT_DATA_ALIGN(n)|alignment|
|
|0||USB_GLOBAL|cachable ram and alignment, stack use only|
|USB_BDT|NonCachable, stack use only|
|USB_CONTROLLER_DATA|NonCachable, stack use only|
|USB_DMA_NONINIT_DATA_ALIGN(n)|cachable ram and alignment|
|USB_DMA_INIT_DATA_ALIGN(n)|cachable ram and alignment|
||USB_GLOBAL|NonCachable, stack use only|
|USB_BDT|NonCachable, stack use only|
|USB_CONTROLLER_DATA|NonCachable, stack use only|
|USB_DMA_NONINIT_DATA_ALIGN(n)|NonCachable and alignment|
|USB_DMA_INIT_DATA_ALIGN(n)|NonCachable and alignment|
||USB_GLOBAL|NULL, stack use only|
|USB_BDT|NULL, stack use only|
|USB_CONTROLLER_DATA|NULL, stack use only|
|USB_DMA_NONINIT_DATA_ALIGN(n)|alignment|
|USB_DMA_INIT_DATA_ALIGN(n)|alignment|
|
Note: “NULL” means that the MACRO is empty and has no influence.
There are four assistant MACROs:
|USB_DATA_ALIGN_SIZE|Used in USB stack and application, defines the default align size for USB data.|
|USB_DATA_ALIGN_SIZE_MULTIPLE(n)|Used in USB stack and application, calculates the value that is multiple of the data align size.|
|USB_DMA_DATA_NONCACHEABLE|Used in USB stack and application, puts data in the noncacheable region if the cache is enabled.|
|USB_GLOBAL_DEDICATED_RAM|Used in USB stack and application, puts data in the dedicated RAM if dedicated RAM is enabled.|
Parent topic:USB stack configuration
Parent topic:Build the USB examples in MCUXpresso SDK