[<<][staapl][>>][..]
Thu Sep 4 13:12:03 CEST 2008
pk2cmd
Simplified entry trace in pseudo-C:
main()
pk2app.PK2_CMD_Entry(argc, argv);
checkHelp(argc, argv);
PicFuncs.ReadDeviceFile(tempString);
Pk2OperationCheck(argc, argv); // check if conn is necessary
findPICkit2(pk2UnitIndex); // find pk2 and init comm
processArgs(argc, argv); // execute commands
PicFuncs.ReadPkStatus(); // only if it did comm
the beef is in processArgs()
PicFuncs.VddOff(); // make sure VDD is off
// look for part name first
PicFuncs.FindDevice(tempString); // look for the device in the device file
// from then on, process args according to 4 priorities
// these are in cmd_app.cpp and take you directly to the action
priority1Args(argc, argv);
checkArgsForBlankCheck(argc, argv);
priority2Args(argc, argv);
priority3Args(argc, argv);
priority4Args(argc, argv);
delayArg(argc, argv);
Examples:
program a .hex file:
tom@zzz:/tmp$ pk2cmd -pPIC18F1220 -fsynth.hex -m
PICkit 2 Program Report
4-9-2008, 13:32:55
Device Type: PIC18F1220
Program Succeeded.
Operation Succeeded
this contains options:
-p device
-f hex file selection:
// in cmd_app.cpp
bool Ccmd_app::priority1Args(int argc, _TCHAR* argv[])
case 'f':
ret = ImportExportFuncs.ImportHexFile(tempString, &PicFuncs);
-m program memory
// in cmd_app.cpp
bool Ccmd_app::priority2Args(int argc, _TCHAR* argv[])
// -M Program
if ((checkSwitch(argv[i])) && ((argv[i][1] == 'M') || (argv[i][1] == 'm')) && ret){
if (hexLoaded) {
if (argv[i][2] == 0)
{ // no specified region - erase then program all
if (PicFuncs.FamilyIsEEPROM()) {} // ignoring eeprom programming
else {
bool rewriteEE = PicFuncs.EraseDevice(true, !preserveEEPROM, &usingLowVoltageErase);
if (PicFuncs.FamilyIsPIC32()) {} // ignore PIC32 programming
else {
// program all but configs and verify, as configs may contain code protect
// code here mainly calls PicFuncs.WriteDevice
}
}
}
}
}
// finally, in PICkitFunctions.cpp
bool CPICkitFunctions::WriteDevice(bool progmem, bool eemem, bool uidmem, bool cfgmem, bool useLowVoltageRowErase)
// this function contains the main programming flow:
// compute configration information.
int configLocation = (int)DevFile.PartsList[ActivePart].ConfigAddr /
DevFile.Families[ActiveFamily].ProgMemHexBytes;
int configWords = DevFile.PartsList[ActivePart].ConfigWords;
int endOfBuffer = DevFile.PartsList[ActivePart].ProgramMem;
SetMCLR(true); // assert /MCLR to prevent code execution before programming mode entered.
VddOn();
// ignoring some device specific things (OSCCAL/Keeloq/PIC24/
RunScript(SCR_PROG_ENTRY, 1);
if () {
DownloadAddress3(0);
RunScript(SCR_PROGMEM_WR_PREP, 1);
}
while data {
DataClrAndDownload(downloadBuffer, DOWNLOAD_BUFFER_SIZE, 0);
RunScript(SCR_PROGMEM_WR, scriptRunsToUseDownload);
}
// The functions called here are very simple wrappers around
// writeUSB() that build a command packet.
// programming EEPROM DEVID and CONFIG is similar
[Reply][About]
[<<][staapl][>>][..]