USB Component  Version 6.17.0
MDK Middleware for USB Device and Host Communication
USB Composite Device

An USB Composite Device is a peripheral device that supports more than one device class. Many different devices are implemented as composite devices. For example they consist of a certain device class, but also an USB disk that has all the necessary drivers stored so that the device can be installed automatically, without the need to have access to a certain driver software.
In this example, we will implement a composite device that is made up of two devices that have been used in the previous tutorials. We will have access to the development board's buttons (from the HID example) and the SC card (from the MSC example).

Build the "USB Composite" Project

Open the MSC example project in MDK. From the HID example project, copy HID.c and USBD_User_HID.c and add them to the project. Open the Manage Run-Time Environment window. Add one USB:Device:HID component to the project. After clicking OK, you will see that the USB Component in the Project window will have an additional entry: USBD_Config_HID_0.h. As the HID example uses LEDs and push-buttons, you might need to add these Board Support related items as well. Check the RTE Component selection of the HID example for further detail. In total, it should display now a similar project structure:

USB Composite Device Project Structure

Source Files

Now we have two main functions in the project. We need to delete one of them. Open the MassStorage.c file. Copy the lines

finit ("M0:"); /* Initialize SD Card 0 */
fmount("M0:"); /* Mount SD Card 0 */

to the HID.c file right before the lines

Insert

#include "rl_fs.h"

to the #includes at the beginning of the HID.c file. Afterwards, remove the MassStorage.c from your project. Now you have only one main function left.

USB Device Configuration

Before running the program on the target hardware, you need to edit the USBD_Config_HID_0.h file. Open the file, switch to the Configuration Wizard and go to the Bulk Endpoint Settings. As the file is generic and has no information about other classes available in the project, the Endpoint 1 is configured for IN and OUT. This endpoint is already used in the USBD_Config_MSC_0.h file. So change the number for IN and for OUT to '2'. This will make the HID Component use the Endpoint 2 for data exchange with the USB Host and no conflicts will occur with the MSC class.

If you are using RTOS other than CMSIS-RTOS2 RTX5 for your project please make sure to satisfy USB Device Resource Requirements.

You may now build and download the example project to the evaluation board using the µVision commands:

  • Project --> Build target (F7)
  • Flash   --> Download (F8)

After these steps, the project should start executing on your evaluation kit. In case of errors, refer to the Evaluation Board User's Guide for configuration information.

Using the "USB Composite" Project

Hardware Setup

The setup of the Evaluation Board hardware is described in the Abstract.txt file.

  • Verify all jumper settings on the target hardware.
  • Insert a SD card into the socket.
  • Use an USB cable to connect your development board to the Host PC and power up your board.
  • Wait for the driver installation on the PC to complete. First you will see "Installing device driver software" and after a successful installation "USB Input Device" and "Keil Disk 0 USB Device".
Note
If devices do not install correctly then probably device is using same Vendor ID and Product ID as some device that was previously already installed. There are two possible solutions: either change Product ID in USBD_Config_0.c file or uninstall previously installed device that uses same Vendor ID and Product ID.

PC Software

The HID part of this example can be tested on a Windows PC using the HIDClient.exe utility (located in "C:\Keil\ARM\Utilities\HID_Client\Release"). The program runs stand-alone without installation.
Steps to check the USB communication using the client utility:

  • Run "C:\Keil\ARM\Utilities\HID_Client\Release\HIDClient.exe".
  • Select the Keil USB Device to establish the communication channel.
  • Press buttons on the target hardware and/or use the check boxes in the HID Client to interact with the application. The Mass Storage part of this example can be tested on a Windows PC using the Windows Explorer.
  • After a successful driver installation, the AutoPlay window appears.
  • If you click on Open folder to view files Windows Explorer automatically starts with the drive opened.