USB Component  Version 5.1
MDK-Professional Middleware for USB Device and Host
 All Data Structures Functions Variables Enumerations Enumerator Groups Pages
USB Host Keyboard Example

The following example application enables you to connect an USB keyboard to the development board. To keep it simple, the Debug (printf) Viewer in MDK is used to show the keyboard inputs. The online help explains how to connect your stdio to the Debug (printf) Viewer window.

usbh_hid_setup.png

The Abstract.txt file contained in the Documentation group of the Project window gives you more information on the general setup and the available I/O of the development board.

Build the "USB Host Keyboard" Project

Open the example project in MDK (the Pack Installer's web page explains how to do this). The µVision Project window should display a similar project structure:

usbh_hid_proj_structure.png
USB Host Keyboard Project Structure

Source Files

  • Keyboard.c contains the main C function that initializes the board hardware and the USB Host Component. Also, an exemplary remote measurement recorder application is part of this file.
  • Mcommand.c defines the time set commands for the remote measurement recorder.
  • The Getline.c file contains the function for getting formatted input from stdio.
  • In Retarget.c the fgetc function is retargetted to the USBH_HID_GetKeyboardKey function.

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

  • Project –> Build target (F7)
  • Flash –> Download
  • Debug –> Start/Stop Debug Session (Ctrl + F5)
  • Debug –> Run (F5)

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 Host Keyboard" 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.
  • Simply connect an USB keyboard to one of the development board's USB connectors.
  • You need to have an ULINK connection to the development board as the command line is sent to the Debug (printf) Viewer window of an active Debug session.

PC Software

After building the program, download the code into Flash and start a Debug session. Open the Debug (printf) Viewer window and start the code execution by either pressing F5 or using the Run button. You should now see something similar like this:

usbh_hid_printf.png