Friday, 05 December 2008
 
  Home arrow PIC arrow USB arrow PIC USB Bootloader using Microchip firmware and C#  
Main Menu
Home
Car PC
PIC
Electronics
Brewing
Links
Contact Me
FAQs
Forums
eXtplorer
PayPal Donation

Enter Amount:

PIC USB Bootloader using Microchip firmware and C# PDF Print E-mail
Written by Evan   
Wednesday, 23 August 2006
Article Index
PIC USB Bootloader using Microchip firmware and C#
Page 2 - Monitoring Communication
Page 3 - Dealing with HEX files
Page 4 - Bootloader Interface Class

 Note: This article is kind of a mess at present, as I just recently did a significant overhaul of my PIC USB interfacing code, including the bootloader, so I need to update the article more to reflect the new code, when I have time.  Presently, things that are crossed out are outdated info that I haven't yet updated or removed.  Bear with me!

 At the time I started this project, I was unable to find any decent information whatsoever about the PC side of bootloading.   Over at piccoder.co.uk, there is a nice tutorial that gets you started with bootloading, with the microchip firmware on the PIC side, and an example C# GUI application that demonstrates the use of his custom bootloader DLL, which makes it incredibly easy.  Mat has provided his bootloader DLL freely for non-commercial use, with a small nag screen popup.

 However, I still wanted to do it myself, for two main reasons: First, I am very interested in knowing how it is done, and since there is nearly no information on the PC side of things, it seems the best way is to dive in and try to figure it out myself.  Second, I would like to have working PC-side bootloader code to use in my own projects (personal or commercial), but with full access to (and understanding of) the source code so I could adapt it as I needed.  And, of course, if I succeed I'd like to make the information available for others who are interested, to help combat some of the lack of information on the subject that has frustrated me so much.

Mat at piccoder said he basically reverse-engineered the necessary PC-side interface by starting with a look at the PIC firmware. 

Download the software package for the PICDEM Full Speed USB evaluation kit . Install, and in the folder C:\MCHPFSUSB\fw\Boot\ will be the relevant source code of the PIC-side firmware.  Now in the course of trying to get what I need from the firmware, I am focusing on only the things that are related to the PC interface; there are a bunch of functions that the PIC is doing for initializing and managing the USB connection, but the only things I need to know about for this are the things pertaining to the actual commands the PC software can send to the PIC.

 In main.c, you will see that when the PIC is in bootload mode, it sits in this while loop after initialization:

 while(1)
    {
        USBDriverService();     // See usbdrv.c
        BootService();          // See boot.c
    }//end while

 The function USBDriverService() seems to be related to the general USB operation of the PIC, not to the bootloading functionality.  So, the function of interest is BootService, which is (as indicated) found in \system\usb\class\boot\boot.c
Of interest in that function is the switch statement that processes the possible commands.  The options call the appropriate functions, which are seen in the same file, and all seem pretty simple and self-explanatory.  The cases (seen in the switch statement, or as given here, from the enum that shows their numerical values as transmitted as well):

READ_VERSION    = 0x00,
READ_FLASH      = 0x01,
WRITE_FLASH     = 0x02,
ERASE_FLASH     = 0x03,
READ_EEDATA     = 0x04,
WRITE_EEDATA    = 0x05,
READ_CONFIG     = 0x06,
WRITE_CONFIG    = 0x07,
UPDATE_LED      = 0x32,
RESET           = 0xFF

Since that is all of the possible commands the PC can issue to the bootloader firmware, it seems as though it should be a pretty simple process, besides sorting out just how to format the data packets.  Reading and writing the HEX files on the PC could prove to be similarly challenging.

Just a note, in the "C:\MCHPFSUSB\fw\Boot\_output" folder you will find the HEX file for the bootloader, which is used with the rest of this article.

Next up: Monitoring PC-PIC communication using an existing bootloader application to figure out the protocol. 

{mos_sb_discuss:8}  



Last Updated ( Sunday, 29 June 2008 )
 
< 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.

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

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