USB Component  Version 6.12.4
MDK Middleware for USB Device and Host Communication
 All Data Structures Functions Variables Enumerations Enumerator Groups Pages
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 "Keil\ARM\PACK\Keil\MDK-Middleware\x.y.z\Utilities\WinUSB_Test\Release\" folder, where x >= 7, y >= 5, z >= 0), you can initiate Bulk/Interrupt/Control Transfers.

cc_dev_example_setup.png
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:

usb_cc_example_proj_window.png
Typical project structure of WinUSB_Test example

Source Files

  • WinUSB_Echo.c contains the main C function that initializes the board hardware and the 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.

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 "Keil\ARM\PACK\Keil\MDK-Middleware\x.y.z\Utilities\WinUSB_Test\Release\WinUSB_Test.exe" application (where x >= 7, y >= 5, z >= 0):

WinUSB_Test_application.png


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:

WinUSB_Test_control_transfer.png

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:

WinUSB_Test_bulk_transfer.png