USB Component  
MDK Middleware for USB Device and Host Communication
 
Loading...
Searching...
No Matches
USB Device HID

This example implements a USB Device that exchanges data with a USB Host using HID: Human Interface Device Class.

A graphical HID Client program is available for the USB Host Computer (Windows only) to interface with the LEDs and buttons on the target USB Device.

The following picture shows an exemplary connection of the development board and the USB Host Computer.

USB Device HID example hardware setup

Project Organization

The USB Device HID project is available as part of the USB Device Reference examples.

Application Source Files

Following files implement application-specific logic in the example:

  • HID.c: contains the application main thread which initializes the USB Device Component. It also sends the current input status (typically buttons state) via USBD_HID_GetReportTrigger to the USB Host.
  • USBD_User_HID_0.c: adapted code template that implements necessary functions for I/O communication. Refer to HID: Human Interface Class for details.

Software Components Configuration Files

Configuration files for the software components used in the project are available in the ./RTE/ directory and can be modified by users to adjust the operation of related components. Section RTE Components gives an overview about the components and their dependencies.

Following configuration files are provided with this example:

When a board layer is added to the project, corresponding configuration files for the board and device components will become available in the local ./Board/ directory.

Board Layer

In order to build the project it shall be extended with a compatible board layer that provides following interfaces as connections:

  • CMSIS_USB_Device: CMSIS-Driver for USB Device interface.
  • CMSIS_VIO: CMSIS-Driver for Virtual I/O interface.

Build the Project

Working with MDK-Middleware Examples explains the workflow for accessing, configuring and building an MDK-Middleware example project for your target hardware.

  1. Open the USB_Device MDK-Middleware reference example.
  2. Make sure the compatible board layer is configured.
  3. Select HID as an active project for the build process.
  4. Build the project and observe that no errors are reported.

Run the Example

Setup

Board-specific hardware setup such as jumpers, USB ports, power supply, etc. is documented in the board layer description (README.md) of your selected target.

  1. Load the executable image to the target development board.
  2. Connect a USB Device port on the development board with the USB port on a PC.
  3. The device should appear as Human Interface Device - USB Input Device.

Example execution

The USB Device HID example can be tested against a HID Client utility that is available for Windows PCs only. The program runs stand-alone without installation.

Steps to check the USB communication using the client utility:

  1. Start the HIDClient.exe utility.
  2. Select the Keil USB Device 0 to establish the communication channel.
  3. Press buttons on the target hardware and observe the checkmarks appear in corresponding check boxes in the HID Client utility.
  4. Use the LEDs check boxes in the HID Client and observe LED status changes on the board.
Testing the connection with the HID Client app