USB Component  Version 6.17.0
MDK Middleware for USB Device and Host Communication
Custom USB Device (WinUSB_Echo)

Using the custom USB class, you can implement any USB device that is not covered by the other classes available in the MDK Middleware. An example is available for various development boards that is implementing a custom class to work with the Windows USB (WinUSB), a generic driver for USB devices for Microsoft Windows. The example demonstrates a WinUSB device that contains Bulk IN and Bulk OUT endpoints. All data that the device receives on the Bulk OUT endpoint is echoed back on the Bulk IN endpoint.

The following picture shows an exemplary connection of the development board and the Windows USB host computer. Using the USB connection and WinUSB_Test.exe (available in "install_dir\ARM\PACK\Keil\MDK-Middleware\x.y.z\Utilities\WinUSB_Test\Release\" folder, where "install_dir" refers to the installation directory of Arm Keil MDK, usually "C:\Keil_v5" and x >= 7, y >= 5, z >= 0), you can initiate Bulk/Interrupt/Control Transfers. For more information, refer to WinUSB Test.

Hardware setup for WinUSB Custom Class example

The Abstract.txt file contained in the Documentation group of the Project window gives you more information on the general setup.

Build the "WinUSB_Echo" Project

Open the example project in MDK. The µVision Project window should display a similar project structure:

Typical project structure of WinUSB_Test example

Source Files

  • main.c contains the main C function that initializes the hardware.
  • WinUSB_Echo.c contains the app_main C function that initializes USB Device Component.
  • The files USBD_User_CustomClass_0.c/USBD_User_CustomClass_1.c are adapted code templates that implement all necessary functions. Refer to Custom Class for details about these template functions.

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 "WinUSB_Echo" 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.
  • Use a USB cable to connect your development board to the host PC and power up your board.
  • If you connect the device to a PC running Windows 8 or later, the device driver will be installed automatically. On Windows 7, you need to select a driver file that can be found in the project folder. For more information, refer to the Abstract.txt file in the µVision project.

PC Software

The example can be tested on a Windows PC using the WinUSB_Test.exe utility provided with MDK Middleware. The program runs stand-alone without installation. Simply run "install_dir\ARM\PACK\Keil\MDK-Middleware\x.y.z\Utilities\WinUSB_Test\Release\WinUSB_Test.exe" application (where x >= 7, y >= 5, z >= 0):


Device Selection

Configuration Option Selection
GIUD The GUID that is used in Windows to access the device. For this example, the GIUD is fixed. To create your own GIUD, refer to the Abstract.txt file.
Device Select the device that you have attached to the PC (VID should be C251).

Control Transfer

Configuration Option Selection
Setup Packet Normally, leave open. Will be filled automatically from the next options.
Direction Specify the communication direction. If you want to read for example the device descriptor from the device, use Device-to-Host.
Type Type of the control request (standard/class/vendor).
Recipient Recipient of the control transfer message (device/interface/endpoint/other).
bRequest Specify the setup packet request being made.
wValue Specify the wValue of the request.
wIndex Specify the wIndex of the request.
wLength Specify the wLength of the request.

Data Phase

Configuration Option Selection
Data (aa bb cc ..) Shows the transmitted data
Transfer button Start the data transfer
File Select a file for transfer or for saving transferred data
Transfer to/from File button Start the data transfer to/from file

Bulk/Interrupt Transfer

Configuration Option Selection
Interface Select USB interface number
IN Transfer Endpoint Select IN endpoint to be used for bulk/interrupt transfer
Number of bytes to receive Specify the number of bytes to be received
Data (aa bb cc ..) Shows the received data
Start Reception button Start listening on the specified endpoint
File Select a file for saving received data
Start Reception to File button Start listening on the specified endpoint and save data to file
OUT Transfer Endpoint Select OUT endpoint to be used for bulk/interrupt transfer
Data (aa bb cc ..) Enter the data to be transmitted
Start Transmission button Start sending data on the specified endpoint
File Select a file for data to be transmitted
Start Transmission from File button Start sending data from the specified file on the OUT endpoint

Examples

Control Transfer

To setup the control endpoint and to read out the device descriptor of the device, enter the following:

  • Direction: Device-to-Host
  • bRequest: 06
  • wValue: 0100
  • wIndex 0000
  • wLength: 0012

After pressing the Transfer button, you see the response in the Data window:

Bulk Transfer

To loop data from the device to the PC and back, enter the following:

  • Interface: 0
  • IN Transfer Endpoint: 1
  • Press Start Reception to Buffer
  • OUT Transfer Endpoint: 1
  • Enter some data in the right-hand Data window, for example AA BB CC
  • Press Start Transmission from Buffer

You now see the same data in the left-hand Data window:

About Host PC driver for Microsoft Windows

The example folder contains two files relevant for driver installation on the Microsoft Windows:

  • Driver setup information file (xxx-winusb_echo.inf) which is used to create a digitally signed driver catalog file (xxx-winusb_echo.cat)
  • Digitally signed driver catalog file (xxx-winusb_echo.cat)

The driver files are provided as an example, the driver setup information file should be adapted and digitally signed driver catalog file should be created from adapted driver setup information file.

Driver setup information file should be adapted in the following way:

  • c251 in Vendor ID VID_c251 entries should be changed to the vendor ID number assigned to your company by the USB organization (c251 Vendor ID is reserved for Keil Software and should not be used)
  • xxxx in Product ID PID_xxxx entries should be changed to the product ID as assigned by your company
  • [DeviceList.xxx] sections should be changed if device is a composite device in the following way:
    instead of entries like:
    %DeviceName0% = USB_Install, USB\VID_xxxx&PID_yyyy
    entries describing each custom class instance should be added like:
    %DeviceName0% = USB_Install, USB\VID_xxxx&PID_yyyy&MI_00
    where two digit number after MI_ describes the starting interface of a custom class instance
  • [Strings] section should be changed as desired
Note
Vendor ID and Product ID are configured in the USBD_Config_n.c configuration file of the embedded application.
For producing digitally signed driver catalog file please refer to Microsoft Windows documentation.