USB Component
Version 6.6
MDK-Professional Middleware for USB Device and Host
|
This chapter describes the software structure of the USB Device Component and its use for creating applications. The USB Device Component simplifies the software development of microcontroller systems that interface to a USB Host.
Attributes of the USB Device Component:
For interfacing to an USB Host Computer, additional software may be required. Page Interface to an USB Host Computer shows an example for such a software running on Windows PCs.
The picture shows the relationship between RTE Components and the microcontroller's USB Device peripheral (USB Controller). RTE Components provide configuration files and user code templates. Configuration files configure the RTE Components, hardware interfaces, memory resources and USB Device driver parameters. They can have an impact on multiple RTE Components (for example RTE_Device.h configures the USB Controller 0 and Driver_USBD0). User code templates provide the skeleton for implementing the USB Device functionality.
The grey area around the RTE Components USB Device 1 and Driver_USBD1, as well as USB Controller 1 means that these components are optional and can only be used if a microcontroller device has multiple USB controllers present. If this is the case, an USB Device Class can be connected to any of the USB Device Instances.
USB Device peripherals can have one or more of the following USB Device Classes:
Generic information about USB Device Classes can be found on the USB-IF's Approved Class Specification Documents page.
Multiple RTE Component instances can interface with more than one USB Controller or can implement multiple USB Device Classes. RTE Component instances are numbered. The number is appended to the RTE Component name, related configuration files, and user code templates. Each RTE Component has a separate configuration file. For example, for HID 0 and HID 1 the configuration files have the name USB_Config_HID_0.h and USB_Config_HID_1.h.
The steps to create a microcontroller application that uses USB communication with an USB Device controller are:
For interfacing to an USB Host computer, standard USB Device Classes drivers can be used. This may require additional software development for the USB Host application. An exemplary application for interfacing to an USB HID Device is explained here.
Only a few steps are necessary to complete the RTE Component selection:
The USB Device Driver and the USB Controller of the microcontroller need to be correctly configured. In particular this means:
The USB Device Driver selected under the Drivers Component is typically configured with the RTE_Device.h configuration file. While this file provides multiple options, it is typically sufficient to enable the USB Device peripheral related to this driver. Some microcontrollers may require settings that are related to a physical layer interface (PHY). The picture below shows two possible variants. Either, the USB PHY is integrated into the controller, or an external chip is used for providing the USB signal lines:
The configuration file USBD_Config_n.c is listed in the Project Windows under the Component USB and contains a number of important settings for the specific USB Device.
Refer to USB Core Configuration for more configuration options of the USB Device.
The USB Device Class Parameters and Endpoint Settings are configured in separate files for each USB Device Class and separately for each instance. The configuration files contain Device Class specific Endpoint Settings Numbers and are listed in the Project Window under the Component USB.
Each USB Endpoint can only be used once on the same USB Device. It has to be made sure that the different USB Device Classes or multiple instances of the same USB Device Class use different Endpoints. The default configuration supports applications that use a single USB Device Class. The remaining parameters are specific settings that configure parameters for USB communication speed and the USB Device Class.
For proper operation, the USB Device Component requires some system configuration settings. The requirements are:
Stack_Size
).For more information, check the USB Device component's Resource Requirements section.
User code template files provide function templates used to implement USB Device Class functionality. The available functions are explained in the Reference section of the USB Component. These routines can be adapted to the needs of the microcontroller application, in case different then default functionality is needed.
The following templates are available for the USB Device component:
Template Name | Purpose |
---|---|
USBD_User_ADC_n.c | Required functions to create an ADC device. |
USBD_User_ADC_Headphone_n.c | Implements functions to create an ADC device containing speakers and a microphone. |
USBD_User_CDC_ACM_n.c | Required functions to create a CDC (ACM) device. |
USBD_User_CDC_NCM_n.c | Required functions to create a CDC (NCM) device. |
USBD_User_CDC_NCM_ETH_n.c | Required functions to create a CDC (NCM) device (Ethernet-over-USB). |
USBD_User_CustomClass_n.c | Required functions to create a device supporting a custom USB Device class. |
USBD_User_Device_n.c | Required functions for run-time configuration of the USB Device. |
USBD_User_SerNum_n.c | Example for run-time configuration: Changing the serial number of the USB Device. |
USBD_User_HID_n.c | Required functions to create a HID device. |
USBD_User_HID_Mouse_n.c | Implements functions to create a USB HID device acting as a mouse pointer input device. |
USBD_User_MSC_n.c | Required functions to create a MSC device. |
USBD_MSC_n.c | Shows how to get access to storage media either from the application/File System or from the USB host. |