Open Source Framework for USB Generic HID devices based on the PIC18F and Windows

Summary of Open Source Framework for USB Generic HID devices based on the PIC18F and Windows


This article describes an open-source framework that simplifies building USB Generic HID devices with PIC18F microcontrollers and Windows host applications. It includes a C# class library, a Windows reference app, PIC18F4550/2550 firmware, and simple reference hardware. Version 3 adds Microchip C18 support, USB stack separation, bootloader support, interrupt/non-interrupt polling, debug enhancements, and host-app fixes. Reference schematics, breadboard layout, and status LEDs are provided to accelerate prototyping and testing.

Parts used in the USB Generic HID PIC18F Framework:

  • PIC18F4550 microcontroller
  • PIC18F2550 microcontroller
  • USB connector and supporting USB hardware
  • Four status LEDs
  • Breadboard or PCB for reference hardware
  • Resistors for LEDs and USB circuitry
  • Oscillator/crystal for PIC USB timing
  • Power supply (Vcc and decoupling capacitors)
  • Microchip USB stack / Application Library (software)
  • Visual Studio C# development environment (software)

Introduction

If you’ve dabbled with PIC18F microcontrollers and the USB Generic HID standard before (perhaps you’ve even tried my Building a PIC18F USB device project) then you will have noticed that there is a lot of complexity in supporting USB on both the PIC18F and the Windows host-side of things.

Getting beyond the basic steps of reading a switch and flashing an LED (how many projects have you built to flash LEDs?!) is actually quite a large task with a steep learning-curve.

To make things easier on the hobbyist who wishes to delve into more exciting projects, I’ve developed a framework for producing USB devices which covers both the Windows host-side application development and the PIC18F firmware itself. The framework consists of a Visual Studio C# class library (which handles all of the intricacy of dealing with the Windows specific SDKs and operating system requirements), a windows reference application (which demonstrates how to use the class library and acts as a testing front-end for the library), a simple USB hardware reference design and (last but not least!) a PIC18F4550 firmware which communicates with the class library.Open Source Framework for USB Generic HID devices based on the PIC18F and Windows

In essence this means that you can rapidly develop and test a USB device and the Windows host-application with a minimum of USB Generic HID protocol knowledge. The class library gives you a very simple interface to the USB device from C# and the firmware serves as an example of how to create the specific software needed on the PIC for your device design.

The framework includes the ability to pass commands and responses to and from the USB device as well as bi-directional bulk-transfer of data allowing you to build more complex data-capture applications which require more information to be passed quickly from host to device and vice-versa.

In this article I will go over each element of the framework and show how you can use it to develop your own creative USB devices.

For the impatient, here is a quick YouTube video of the framework in action. The LCD driver example shown in the video can be downloaded below:

Version 3_0_0_0

Version 3 of the USB library and firmware is now available (2011-10-16). I’ve made several major and minor enhancements to the library as well as some bug fixing. Here is a list of the enhancements and changes:

  • Firmware
    • Firmware is now targeted for the Microchip C18 compiler (and is no longer compatible with Hi-Tech PICC18)
    • Microchip’s Application Library (containing the USB stack) is now separated from the framework code and is installed standalone
    • The firmware now supports version 2.9a of the USB stack
    • Support for USB bootloaders is now included (lightly tested at the moment)
    • Both interrupt driven USB polling and non-interrupt driven USB polling are now supported
    • Debug stream now supports dynamic text so you can place live variables and other information into the in-built debug functions
    • Open-source firmware code now separated correctly from Microchip stack code
    • General code clean-up with better (and more concise) comments and notes
  • Host Reference Application
    • Fixed memory leakage issue in non-Managed code (readRawReportFromDevice method)
    • Changed the method used for registering to receive device event notifications. This is now handled by the library and does not need a WndProc override in the user code
    • General code clean-up

In addition I’ve also updated all of the circuit diagrams and included a new schematic for the PIC18F2550.

Please ensure that you specify which version of the USB framework you are using when asking for help in the forums.

Reference Hardware

The reference hardware is extremely simple and can be built on a breadboard if required. I’ve made the pin-out of the hardware identical to the PIC DEM FS USB board available from Microchip to allow you to buy a reference board (if you want to!), you can also use my clone of the Microchip board – the PIC USB Development Board. If you don’t have the time/money/inclination to make a reference board here is a circuit schematic of the minimum required hardware for the reference board for both the PIC18F4550 and PIC18F2550 microcontrollers:

PIC18F4550 Circuit Schematic

PIC18F2550 Circuit Schematic Open Source Framework for USB Generic HID devices based on the PIC18F and Windows schematic

Breadboard Layout

The next picture shows the reference hardware built on an experimenter’s breadboard (using the PIC18F4550):

The reference hardware provides 4 LEDs which are used to show the status of the USB device as it processes the various requests that can be sent to it from the Windows host-application. The 4 LEDs (from left-to-right) mean:

  1. Power is on – device is ready
  2. USB enumerated – device is ready to communicate
  3. Success indicator (this flashes as commands are correctly processed)
  4. Failure indicator (this flashes if a command was not correctly processed)

The board provides all you need to add in your own devices and circuity as you require, you can even remove the LEDs, the only part the firmware truly requires is the USB port and its associated hardware.

 

 

For more detail: Open Source Framework for USB Generic HID devices based on the PIC18F and Windows

Quick Solutions to Questions related to USB Generic HID PIC18F Framework:

  • What does the framework include?
    The framework includes a Visual Studio C# class library, a Windows reference application, reference hardware schematics, and PIC18F4550 firmware.
  • Which PIC microcontrollers are supported?
    The framework provides reference designs for PIC18F4550 and PIC18F2550 microcontrollers.
  • Which compiler is the firmware targeted for in version 3?
    Firmware is targeted for the Microchip C18 compiler in version 3.
  • Does the framework support USB bootloaders?
    Yes, support for USB bootloaders is included and lightly tested.
  • How are device event notifications handled in the host application?
    The library now handles device event notification registration so user code does not need a WndProc override.
  • What do the four LEDs on the reference hardware indicate?
    From left to right: power on, USB enumerated, success indicator, and failure indicator.
  • Is the Microchip USB stack included with the framework?
    The Microchip Application Library containing the USB stack is separated from the framework code and is installed standalone.
  • Does the firmware support interrupt driven USB polling?
    Yes, both interrupt driven and non-interrupt driven USB polling are supported.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter