USB Component  Version 6.13.6
MDK Middleware for USB Device and Host Communication
 All Data Structures Functions Variables Enumerations Enumerator Groups Pages
USB Host Computer Applications

Most of the available USB Device Classes are directly supported in operating systems. There is no need to install a particular driver on the USB Host Computer to connect to the USB Device peripheral.

Some software needs to be written for the USB Host Computer when USB Driver classes are used to provide application specific functionality. For example, the USB HID Device Class may be used for generic data exchange. Therefore the data exchange interface needs to be developed at the USB Host Computer.

Refer to the following web pages for more information on USB Host software development:

Software Utilities

The USB Component comes with a set of software utilities that you can use as templates to create your own programs for the USB Host computer. The utilities are specific for the different USB Device Classes. These are the available utilities:

  • The HID Client can be used to interact with an USB HID Device. You can toggle LEDs on the development board and check the state of the on-board push-buttons.
  • The WinUSB Test can be used to test the connection between the USB Host PC and the client device. This application uses WinUSB driver on the USB Host PC and demonstrates the basics of using the Microsoft Foundation Classes and can be used as a starting point for writing your application.

HID Client

If you are using the USB Device HID code, there's a way to test the functionality of that code together with a Windows PC. The HIDClient.exe utility is located in "install_dir\ARM\Utilities\HID_Client\Release" folder (where "install_dir" refers to the installation directory of Arm Keil MDK, default "C:\Keil_v5") and can run stand-alone without the need to install the software. To check the client utility with your board, do the following:

  1. Download the USB Device HID application to your board.
  2. Verify all jumper settings on the board.
  3. Connect the board to a Windows PC. The PC should recognize the HID device and install the correct driver automatically.
  4. Run HIDClient.exe.
  5. Select the Device to establish the communication channel.
  6. Test the application by pressing the correct buttons (refer to the application's Abstract.txt file) on your development board and/or check the right boxes in the client application to see the LEDs flashing.
hid_client_test.png

HID Client Source Code

The source code of the HID Client application is available in "install_dir\ARM\Utilities\HID_Client". Visual Studio 2005 and 2010 based projects are available (HIDClient.vproj). The structure of the project is as follows:

HIDClientSolutionExplorer.png

Header Files

  • HID.h includes the function declarations of the functions that are defined in HID.cpp.
  • HIDClient.h is the main header file for the application. It includes other project specific headers (including Resource.h) and declares the CHIDClientApp application class.
  • HIDClientDlg.h defines the behavior of the application's main dialog.

Resource Files

  • HIDClient.ico is an icon file, which is used as the application's icon. This icon is included by the main resource file HIDClient.rc.
  • HIDClient.rc2 contains resources that are not edited by Microsoft Visual C++. You should place all resources not editable by the resource editor in this file.

Source Files

  • HID.cpp contains the necessary functions that are used in this example application to communicate with an USB HID device. All available functions in Windows for HID interaction are explained here: Introduction to HID Concepts. The function:
    • HID_Init initializes the HID class to be used with the USB Host.
    • HID_UnInit de-initializes the HID class from the USB Host.
    • HID_FindDevices scans the USB Bus and lists all available HID devices for connection to the application. This information is obtained from the Device Descriptor that is generated by the USB Component using the configuration files.
    • HID_GetName evaluates the Product String of the device to be shown in the drop down box of the application.
    • HID_GetInputReportSize extracts the value of USBD_HIDn_IN_REPORT_MAX_SZ as specified in the USBD_Config_HID_n.h file.
    • HID_GetOutputReportSize extracts the value of USBD_HIDn_OUT_REPORT_MAX_SZ as specified in the USBD_Config_HID_n.h file.
    • HID_GetFeatureReportSize extracts the value of USBD_HIDn_FEAT_REPORT_MAX_SZ as specified in the USBD_Config_HID_n.h file.
    • HID_Open opens the device.
    • HID_GetSelectedDevice returns the selected device.
    • HID_Close closes the device.
    • HID_Read initiates a USBD_HIDn_GetReport within the device to send data to the USB Host.
    • HID_Write triggers a USBD_HIDn_SetReport within the device to read data sent from the USB Host.
    • HID_GetFeature and HID_SetFeature work on the USB HID Device's feature report (which is optional).
  • HIDClient.cpp is the main application source file that contains the application class CHIDClientApp.
  • HIDClient.rc is a listing of all of the Microsoft Windows resources that the program uses (located in the res subdirectory).
  • HIDClientDlg.cpp implements the code of the client's dialog and calls the functions specified in HID.cpp. This is the actual place where the interaction between the USB Host and the USB Device is defined.

WinUSB Test

If you are following the Custom USB Device (WinUSB_Echo) tutorial, you can test the connection between your custom class USB device and a Microsoft Windows PC with this application. The binary WinUSB_Test.exe (which does not require installation) is available in the "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, default "C:\Keil_v5" and x >= 7, y >= 5, z >= 0).

To check the WinUSB utility with your board, do the following:

  1. Download the USB Device WinUSB_Echo application to your board.
  2. Verify all jumper settings on the board.
  3. Connect the board to a Windows PC. The PC should recognize the WinUSB device and install the correct driver automatically.
  4. Run WinUSB_Test.exe.
  5. Select the Device to establish the communication channel.
  6. For further settings and tests refer to Custom USB Device (WinUSB_Echo)
WinUSB_Test_application.png


WinUSB application source code

The WinUSB source code can be found in "install_dir\ARM\PACK\Keil\MDK-Middleware\x.y.z\Utilities\WinUSB_Test". A Visual Studio 2010 (or later) based solution named WinUSB_Test.sln is available. The following is a summary of what you will find in each of the files that make up your WinUSB_Test application.

WinUSB_test_sln.png

Header Files

  • .\USB\WinUsbIF.h includes the function declarations of the functions that are defined in .\USB\WinUsbIF.cpp.
  • .\WinUSB_Test\WinUSB_Test.h is the main header file for the application. It includes other project specific headers (including resource.h) and declares the CWinUSB_TestApp application class.
  • .\WinUSB_Test\WinUSB_TestDlg.h defines the behavior of the application's main dialog.

Resource Files

  • .\WinUSB_Test\res\WinUSB_Test.ico is an icon file, which is used as the application's icon. This icon is included by the main resource file .\WinUSB_Test\WinUSB_Test.rc.
  • .\WinUSB_Test\res\Refresh_grey.ico is an icon file, which is used for the refresh button in the application.
  • .\WinUSB_Test\res\WinUSB_Test.rc2 contains resources that are not edited by Microsoft Visual C++. You should place all resources not editable by the resource editor in this file.

Source Files

  • .\USB\WinUsbIF.cpp contains the necessary functions that are used in this example application to communicate with a USB device via the WinUSB interface. Refer to the WinUSB Functions documentation for an overview of the available functions. The function:
    • WinUsbIF_Initialize initializes the WinUSB interface to be used with the USB Host.
    • WinUsbIF_Uninitialize de-initializes the WinUSB interface from the USB Host.
    • WinUsbIF_SetGUID sets the USB interface Globally Unique Identifier (GUID).
    • WinUsbIF_GetGUID retrieves the USB interface Globally Unique Identifier (GUID).
    • WinUsbIF_FindDevices scans the USB Bus and lists all available devices, containing interface with set GUID, for connection to the application.
    • WinUsbIF_GetNumOfInterfaces retrieves the number of interfaces available for a device.
    • WinUsbIF_GetEndpointsMask retrieves the endpoint mask of the selected device.
    • WinUsbIF_GetName evaluates the VID + PID + Serial Number or Unique ID of the device to be shown in the drop down box of the application.
    • WinUsbIF_GetManufacturerString retrieves the device's manufacturer string.
    • WinUsbIF_GetProductString retrieves the device's product string.
    • WinUsbIF_GetSerialNumberString retrieves the device's serial number string.
    • WinUsbIF_GetInterfaceString retrieves the device's interface string.
    • WinUsbIF_GetVID retrieves the device's vendor ID.
    • WinUsbIF_GetPID retrieves the device's product ID.
    • WinUsbIF_OpenDevice opens the device for USB communication.
    • WinUsbIF_CloseDevice closes the device from USB communication.
    • WinUsbIF_ControlTransfer executes a control transfer on the USB Bus.
    • WinUsbIF_WritePipe executes an USB OUT transfer on a selected pipe to a bulk or interrupt endpoint of the device.
    • WinUsbIF_ReadPipe executes an USB IN transfer on a selected pipe to a bulk or interrupt endpoint of the device.
    • WinUsbIF_AbortPipe aborts pending pipe transfers.
    • WinUsbIF_FlushPipe flushes the cached data of a pipe.
    • WinUsbIF_ResetPipe resets a pipe.
    • WinUsbIF_GetOverlappedResult retrieves the overlapped result.
  • .\WinUSB_Test\WinUSB_Test.cpp is the main application source file that contains the application class CWinUSB_TestApp.
  • .\WinUSB_Test\WinUSB_Test.rc is a listing of all of the Microsoft Windows resources that the program uses (located in the .\WinUSB_Test\res subdirectory).
  • .\WinUSB_Test\WinUSB_TestDlg.cpp implements the code of the client's dialog and calls the functions specified in .\USB\WinUsbIF.cpp. This is the actual place where the interaction between the USB Host and the USB Device is defined.