README for PD_FSUSB
27 February 2008
Dave Chambers
dlchambers@aol.com
http://www.dlwrr.com/electronics/picdem
The Project
I bought a PICDEM FS USB kit and learned how to use it.
Problem was, the sample Windows code for controlling it was pretty crappy. In particular, it wasn't at all clear how one drives the bootloader from a Windows app. And Microchip doesn't offer the source to their Demo App.
I searched the Web and found the following link to the FS USB WinApp source:
http://www.picbasic.co.uk/forum/showthread.php?p=50705
That is what the Web is all about - techies sharing nuggets of great info!
It turns out that the Demo App source has several shortcomings:
1) It's written in Borland C++ Builder - WTF??? Useless to any real Windows coder.
2) The guy who wrote it is a HORRIBLE programmer so the code is really hard to use as a tutorial.
So I ported it to C++ under MS Visual Studio 8.
This was more than just an academic exercise: It's the groundwork for my own custom app that will control my own custom PIC18F4550-based USB device. Turns out that porting the app to VC++ paid big dividends - it forced me to learn the PC/PIC bootload interface down to the nitty gritty, something I had just skimmed before.
Ownership
My intent is to help others just as they have helped me.
I therefore offer my parts of this code with no restrictions whatsoever, and no attribution is necessary.
However, this code is based on Microchip's Demo App and a scrounged version of it's code, so you may need to comply with any restrictions imposed by Microchip.
Notes on the contents of PD_FSUSB.zip
When you unzip PD_FSUSB.zip, it creates a few subdirs:
- App - Full source for my VC++ version of the FSUSB app.
- MPUSBAPI - Full source for my VC++ version of the MPUSBAPI dll.
- release
- \DavesBinaries - Pre-built copies of my PD_FSUSB.exe and MPUSBAPI.dll
- \MicrochipBinaries - The stock Microchip versions of the App and DLL. Note that their mpusbapi.dll requires cc3260.dll (the Borland runtime lib) and PICBOOT.dll (their EXE doesn't actually use this dll, but it's linked with the dll's .lib, so the dll's gotta be present. As I mentioned above, amazingly bad coding.)
When you open the PD_FSUSB project (in the \App dir), notice that under "Source Files" 've created several sub-folders. I did this to make the project less monolithic. The sub-folders are:
Comms
Code related to communicating with the board via USB.
DeviceManager.cpp
- Based on the original code, this handles all the Win32-to-PIC interaction.
MpUsbApiWrapper.cpp
- A wrapper class for dynamically loading MPUSBAPI.dll
Dialogs
The various dialog boxes.
PD_FSUSBDlg.cpp
- The main dialog. Hosts a Tab control; the tab ctrl hosts the following dialogs:
TabBootload.cpp
- Manages the Bootload mode UI
TabDemo.cpp
- Manages the Demo mode UI
Misc
ByteBuf.cpp
- A CString-like class for handling buffers of BYTEs
HexFile.cpp
- Class for handling the .HEX file format created by the compiler.
PD_FSUSB.cpp
- The CWinApp boilerplate
stdafx.cpp
- does this need explanation?
UiCtrls
Classes for the custom controls used in the Tabs.
My goal was to make my version's UI look like the original version's UI, and these controls achieve that look.
You don't need to understand any of these in order to understand the interaction with the FSUSB board.
Behavioral differences from the stock FSUSB app
- I have "AutoSelect" and "AutoConnect" checkboxes at the top of the dialog. When both are unchecked, the behavior is the same as the stock App.
- AutoSelect - When checked, the App will automatically show the correct tab based on which mode the Board is in.
- AutoConnect - When checked, the App will automatically connect to the 1st Board listed in the combo box.
- The "Clear Log" button is at the bottom-right of the log.
- The Demo Mode UI includes radio buttons for Celsius and Farenheit. Just because I wanted to.
Debugging tips
If you're wanting to watch the App interact with the board, I'd suggest setting breakpoints in the following locations:
DeviceManager::ReadVersion()
- This is the first, and simplest, interaction between the App and Board.
CTabDemo::OnTimer
- This is where all the Demo mode's work is done.
Step into theApp.m_DeviceMgr.ReadTemperature()
, theApp.m_DeviceMgr.ReadPot()
, and theApp.m_DeviceMgr.UpdateLED()
to see how the WinApp talks to the Board.
- The
ON_BN_CLICKED
handlers in CTabBootload
- These handle the App/Board interaction in Bootload mode.