Sunday, November 8, 2009

Problems compiling Uspicprog firmware, or not?

As I have said before, my interest in Usbpicprog is not in it as Pic programmer as such, but to learn how to communicate using Usb. What I left unsaid was that I also see the self-programming capability of the Pic in this setting as a development environment.

For me to start replacing the Usbpicprog firmware with my own, the logical step is first to learn how to compile the given firmware myself. I have written before how I tried to do this using Piklab in Linux, but that proves difficult and for reasons beyond my control, I am bound to Windows at the moment.

So I tried to rebuild the project in MPLAB IDE. The ideal was to be able to compile it so that the hex file I get and the one downloaded from Sourceforge are identical when I compare them. I could not achieve that, although I'd say they are more than 90% identical. I use open source Notepad++ and the Compare plug-in, works like a charm!

I can think of a the following reasons why they are not the same:
  • Possibly different versions of C18 used by myself and the project admins?
  • In Piklab it seems you can put the C files in the order that you want and I suppose the linker will use them in that order. MPLAB IDE arranges them alphabetically and they get linked in that order.
  • At the moment my free version of MPLAB C18 is still within the 60-day trial period, after that optimization will not work any more.
Anyway, it seems that the code I am compiling is also working. At first I had my doubts - did I really program the pic with the file that I compiled etc? Then I changed the SVN_REVISION in in svnrevision.h from "0.3.0" to "0.3.1". The Usbpicprog still connected to the Windows software, but reporting that the firmware is too new.

I will try to remember all the steps I took to set up the project, here goes:
  • Create a folder for the project, e.g. c:\MCC18\Projects\usbpicprogfw and copy all .c, .h and the .lkr file from the downloaded Usbpicprog firmware into this folder.
  • In MPLAB IDE, from the Project menu, use Project Wizard to create a new project, save the project e.g. as usbpicprog (it will do the extension automatically.) Do not create any .c files at this point.
  • Add all the .c, .h and the .lkr file to the project.
  • In Directories, add the Library Search Path c:\mcc18\lib
  • In MPLAB C18 Memory Model, make sure you have: Code Model = Small, Data Model = Large and Stack Model = single bank.
  • Change the Build Configuration from Debug to Release.
  • Set the MPLAB C18 Optimization to Enable All.
I hope I didn't miss anything, if you are still having problems compiling, leave a comment with your e-mail address (it will not be disclosed) and I can zip up the project and send it to you.

A handy feature in MPLAB IDE is View Disassembly Listing (and also View Program Memory). Use the after you have built the project successfully. Note that 0 - 0x7ff is reserved for the Boot Loader and the firmware starts at 0x800. In this project you will notice that code is generated for address 0 etc, but I think somewhere in Usbpicprog it will ignore code for that area. However, if you plug in the Usbpicprog with both jumpers on, the boot loader will when it senses the 2nd jumper, transfer execution to whatever code you have programmed at 0x800.

No comments:

Post a Comment