Saturday, 13 March 2010
 
  Home arrow PIC arrow USB arrow Understanding the Microchip USB Firmware  
Main Menu
Home
Car PC
PIC
Electronics
Brewing
Links
FAQs
Forums
eXtplorer
Understanding the Microchip USB Firmware PDF Print E-mail
Written by Evan   
Saturday, 23 September 2006
Article Index
Understanding the Microchip USB Firmware
Page 2 - Descriptors and Endpoints

(in progress)

As a precursor for understanding the workings of the Microchip USB firmware, it's a good idea to have a basic grasp of the USB protocol itself.  Jan Axelson's book USB Complete is a good resource, and the web article "USB in a Nutshell " is a good free resource. 

 The Microchip USB firmware (for the PICDEM full-speed USB demo board, but used frequently for DIY projects as well) is written and organized in a manner that it is not very easy to just take a quick look and see exactly what's going on.  Everything is arranged across 9 source files, and 15 header files.  There are enough subroutines to make your head spin.  Things are broken down into pretty logical chunks, with an ample amount of commenting accompanying each subroutine, however it's still hard to pick out what is being run, and when.  First off, you need to get an idea of the "core" execution path during normal operation, with the device already enumerated and configured and sitting there running user code and servicing requests.  This description is assuming that the device is running the 'generic' class firmware, as in the Microchip firmware I started from.

Image

That simple flowchart shows the basic operation, where the black loop is the top level (in main.c), and blue and red are 2 levels of subroutines executed from within the functions in the top loop.  First I'll mention that the standard firmware is using the "generic" device class, which includes a set of functions for formatting/interpreting the generic command+data packets used for communication.

The function blocks shown can be described as follows: (Note: a lot of this is just the function overviews from the comments in the code)

USBTasks (main.c)

Executes USBCheckBusStatus and USBDriverService.  (Service loop for USB Tasks)

USBCheckBusStatus (usbdrv.c)

This routine enables/disables the USB module by monitoring the USB power signal.

USBDriverService (usbdrv.c)

This routine is the heart of this firmware. It manages all USB interrupts.  Determines the state of the device.

Device state transitions through the following stages:
DETACHED -> ATTACHED -> POWERED -> DEFAULT ->
ADDRESS_PENDING -> ADDRESSED -> CONFIGURED -> READY

ProcessIO (user.c)

This is the entry point into user routines

BlinkUSBStatus (user.c)

This is responsible for flashing the USB status LEDs, to indicate the current state of the device.

ServiceRequests (user.c)

This is where any incoming commands/data are handled, and returned data (if any) prepared and sent.  This function (and the corresponding enum defining all the possible commands, found in user.h) need to be edited if you add or modify any commands.

USBGenRead (defined in usbgen.c)

This performs a USB packet read; as evidenced by the "Gen" in the name, this is part of the "generic" device class code.

(handle command)

Not a subroutine per se, but if a packet is received with USBGenRead, this is where it is handled, with a switch statement with a case for each defined command from the enum in user.h.

USBGenWrite (defined in usbgen.c)

After a read and handling the command, if anything needs to be sent back to the host, that happens here, transmitting the data loaded into the buffer in the previous step.



Last Updated ( Tuesday, 30 January 2007 )
 
< Prev   Next >
Partner Site
Visit my friends over at Dream-Technology, producing radio controlled and switch adapted toys for children with physical disabilities.
Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License.
For usage outside the terms of this license, contact me by email to discuss.

© 2010 eegeek.net
Joomla! is Free Software released under the GNU/GPL License.

Get The Best Free Joomla Templates at www.joomla-templates.com