PICkit3 Command Line

There is a script called mdb.sh (and presumably mdb.bat on Windows) which allows you to drive the various PIC hardware interfaces from the command line. It’s a script that calls a Java application to do the heavy lifting. By creating a command script and presenting it to this mdb script you can drive things without having to pull up the heavy, bloated IDE.

The commands are all described in the PICkit3 Programmer/Debugger User’s Guide. (That link will probably disappear over time, Microchip doesn’t have a habit of keeping documentation or URLs link-friendly.)

Basically you do create a text file and put something like this in it:

device PIC24FV32KA304
hwtool PICkit3 -p
program "dist/default/production/sw.production.hex" 
quit

This script just contains the commands you want it to run through, in sequence. Then you call mdb.sh as you would any other command line program and provide your command script as teh first argument:

/Applications/microchip/mplabx/mplab_ide.app/Contents/Resources/mplab_ide/bin/mdb.sh prog.cmd

This can be simplified by modifying the Makefile that MPLABX uses. I just add this to the Makefile (above the two include statements at the bottom of the file):

program:
        /Applications/microchip/mplabx/mplab_ide.app/Contents/Resources/mplab_ide/bin/mdb.sh prog.cmd 

Note that that’s a TAB before /Applications/... and not spaces. Makefiles are very specific in that regard.

Notes

The -p used with the hwtool command forces the programmer into “programmer” mode instead of “debugger” mode. This prevents certain behaviours from occuring which may bugger up your programming (overriding fuses I suppose). See the manual for details.

With the PICkit3 the application has the disgusting habit of warning you about voltages each and every time you select it:

CAUTION: Check that the device selected in MPLAB IDE (PIC24FV32KA304) is the same one that is physically attached to the debug tool. Selecting a 5V device when a 3.3V device is connected can result in damage to the device when the debugger checks the device ID. Do you wish to continue?

>

To get around this, you can add

set system.disableerrormsg true

Before the “hwtool” command in your command script. It’s unfortunate that this command disables all error/warning messages but then again, it’s also unfortunately that we have to run Java to use the PICkit3 and are forced to use goofy debuggers instead of having a nice thin wrapper and then using the standard gdb and its tools.

Add picture from clipboard (Maximum size: 1 GB)