USB Libraries Help > USB Device Libraries > USB Device Library - Getting Started > Creating Your Own USB Device
MPLAB Harmony USB Stack
Creating Your Own USB Device

The first step in creating a USB device is identifying whether the desired device function fits into any of the standard USB device class functions. Using standard USB classes may be advantageous as major operating systems feature Host driver support for standard USB devices. However, the application may not want to tolerate the overhead associated with standard USB device class protocols, in which case, a Vendor USB device can be implemented. A Vendor USB device can be implemented by using the USB Device Layer Endpoint functions; however, these devices will require custom USB host drivers for their operation. Having identified the device class to be used, the recommended approach is to use the available demonstration applications as a starting point for the application.

Use the Available Library Demonstration Applications

The USB Device Library release package contains a set of demonstration applications that are representative of common USB devices. These can be modified easily to include application specific initialization and application logic. The application logic must be non-blocking and could be implemented as a state machine. Note that the function names and file names referred to in the following section are the those used in the USB Device Library demonstration applications.

  • The application specific initialization can be called in the APP_Initialize function (in the app.c file). The APP_Initialize function is called from the SYS_Initialize function, which in turn is called when the device comes out of Power-on Reset (POR).
  • The application logic is implemented as a state machine in the APP_Tasks function (in the app.c file). The application logic can interact with the function driver and the Device_layer by using available API calls.
  • The application logic can track device events by processing the events in the application USB device event handler function (APP_USBDeviceEventHandler function in app.c).