Pirate PIC Programmer

From DP

Jump to: navigation , search

Pirate PIC Prog is a programmer application for the Bus Pirate, and several future Dangerous Prototypes projects.

Contents

Downloads

During development the latest download is in the forum.

Eventually we'll have a package on the downloads page at Google Code.

Supported PICs

Pirate PIC Prog is in the initial testing phase. It currently supports a limited number of PICs while other features are stabilized. Some PICs require a 6-13volt to enter programming mode, these will require an adapter. You can submit settings for new PICs and get a free programming adapter.

Supported PICs
PIC family PICs Adapter ID Erase Write Read
18Fxx5x 18F2550 (USB IR Toy, Flash Destroyer) Yes (13V) X X  ??  ??
18F2/4xJxx 18F24J50 (Logic Sniffer) No X X X X
24FJXXGAXXX 24FJ64GA002 (Bus Pirate) No X X X NO*
  • Read is correct, but verification fails because the current HEX parser doesn't understand the PIC24F firmware format.

Connections

Bus Pirate --> PIC
MOSI --> PGD
CLK --> PGC
CS --> VPP/MCLR
GND --> GND
3.3v/5v->power (optional)

Connect the Bus Pirate to the PIC or the ICSP header of the target as shown.

Programming a 18F24J50

E:\picprog>picprog -p buspirate -u COM12 -s 115200 -c 18F24J50 -t HEX -w OLSv1-bootloader-v1-20MHz.hex -E -V
(Bus) Pirate PIC Programer v0.1

buspirate
Initializing interface
115200
Entering binary mode
BP: Setup mode...
Setup peripherals...
(OK)
Found '18F24J50' in programming database :) index = 1
Checking for 18F24J50 attached to programmer...
Found 18F24J50 (0X4C02, ID: 0X260 REV: 0X2)
Reading HEX file 'OLSv1-bootloader-v1-20MHz.hex' ... Read binary size = 16384
Erasing chip... OK :)
Writing page 0, 0000...
Writing page 1, 0100...
...
Writing page 7, 0700...
Writing page 8, 0800...
Skipping page 9 [ 0x000900 ], not used
...
Writing page 63, 3f00...
Reading page 0, 0000...
Reading page 1, 0100...

Programming a 24FJ64GA002

E:\picprog>picprog -p buspirate -u COM12 -s 115200 -c 24FJ64GA002 -t HEX -w BPv3
-Bootloader-v4.4.hex -E -V
(Bus) Pirate PIC Programer v0.1

buspirate
Initializing interface
115200
Entering binary mode
BP: Setup mode...
Setup peripherals...
(OK)
Found '24FJ64GA002' in programming database :) index = 2
Checking for 24FJ64GA002 attached to programmer...
Found 24FJ64GA002 (0X447, ID: 0X447 REV: 0X3043)
Reading HEX file 'BPv3-Bootloader-v4.4.hex' ... Read binary size = 88064
Erasing chip... OK :)
Writing page 0, 0000...
Writing page 1, 0020...
Writing page 2, 0040...

Programming a 18F2550

E:\picprog>picprog -p buspirate -u COM12 -s 115200 -c 18F2550 -E
(Bus) Pirate PIC Programer v0.1

buspirate
Initializing interface
115200
Entering binary mode
BP: Setup mode...
Setup peripherals...
(OK)
Found '18F2550' in programming database :) index = 0
Checking for 18F2550 attached to programmer...
Found 18F2550 (0X1247, ID: 0X92 REV: 0X7)
Erasing chip... OK :)

E:\picprog>

This demo requires the Bus Pirate high-voltage programming adapter or a similar 13volt power supply and control circuit. 18F2550 programming is not yet complete.

Command line options

E:\picprog>picprog
(Bus) Pirate PIC Programer v0.1

ERROR: Invalid argument(s).

Help Menu
Pirate Pic Programmer
USAGE:
picprog -p PROG -u PORT -s SPEED -c CHIP -t TYPE -w | -r FILE -E | -W | -R | -V picprog -h

-p PROG - name of interface
-u PORT - interface port
-s SPEED - interface speed
-c CHIP - chip type

-t TYPE - input/output file type HEX, BIN
-w FILE - file to be uploaded to PIC
-r FILE - file to be downloaded from PIC
commands:
-E - erases Flash
-W - writes data to Flash
-R - reads data from Flash
-V - verifies content of flash
-I - get the chip ID
-h - this help usage


Example usage: picprog -p buspirate -u COM12 -s 115200 -c 18F2550 -t HEX -r test.hex -E
picprog -p buspirate -u COM12 -s 115200 -c 18F2550 -i
picprog -h

E:\picprog>

Adding new PICs

PiratePICprog is fairly feature complete, we just need to add settings for a bunch of PIC chips. We really need a tutorial that shows how to do this, but for now you can refer to the existing chips. Just send us your settings and we'll compile a new release.

Source

Get it from SVN.

Compiling

Pirate PIC Prog is designed to be cross-platform. We're developing it on Windows with the open source Codeblocks IDE and MinGW compiler. It should compile on GNU/Linux with GCC, but may need a little care and feeding first. Here's some helpful links:


Adding Specific PICs on the pic.c file

The PICs will be added on a pic_chip[] array of struct pic_chip_t datatype.

   struct pic_chip_t {
       const char *name;
       uint16_t ID;
       uint32_t flash;
       uint32_t eeprom;
       uint16_t family;
       uint32_t boot_block_start;
       uint32_t boot_block_end;
       uint32_t code_memory_start;
       uint32_t code_memory_end;
       uint32_t flash_config_start;
       uint32_t flash_config_end;
   };

For 18F24J50, it will be added like this:

   {
       .name = "18F24J50",
       .ID = 0x260,
       .flash = 16*1024,
       .eeprom = 0,
       .family = FAMILY_18F2xJxx,
       .code_memory_start = 0x000000,
       .code_memory_end =   0x007FFF,
       .flash_config_start = 0x3FF8,
       .flash_config_end= 0x3FFF,
   }


The explanation of every parts of the struct pic_chip_t datatype for 18F24J50:

.name

   -  This is the name of the device. This is important and should have a descriptive name because
   this is being referred for finding the reference for function interfaces to be used.

.ID

   -  Device ID.
   Devid.png
   Convert 0x4C to binary (0b1001100) then append the 3 zeros (from 000x xxxx). 
   DevID=0b1001100 then append 0b000
   DevID=0b1001100000 = 0x260


.flash

   -  Flash Size.  16*1024 = 16,384 (from 0x0000 to 0x3FFF)
   Memorymap.PNG

.eeprom

   - EEPROM Size. (Currently not used in the programming)


.family

   -  This is defined in an enum (located also in pic.c)
   enum {
   FAMILY_18F2xJxx, 
   FAMILY_24FJxxGAxxx,
   FAMILY_18Fx5xx,
   };


.code_memory_start

   (THIS IS NOT USED IN THE CODE)
   -  From the previous picture, the Code Memory starts at 0x0000.


.code_memory_end

   (THIS IS NOT USED IN THE CODE)
   -  This is the end of the code memory.  This is obtained by: Config_Word Start_Address – 2 = 0x3FF8 – 2 = 0x3FF6
   Configword.PNG

Verifying it with MPLAB:

   Programmemory.PNG

The 0x3FF8 to 0x3FFF is for Config Words:


.flash_config_start

   (THIS IS NOT USED IN THE CODE)
   -  Specified above: 0x3FF8


.flash_config_end

   (THIS IS NOT USED IN THE CODE)
   -  Specified above: 0x3FFF


Adding Specific PIC Family on the pic.c file

The PIC Families will be added on the pic_family[] array of struct pic_family_t datatype.

       struct pic_family_t {
               uint32_t family;
               enum proto_t proto;
               uint32_t ID_addr;
               uint8_t word_size;
               uint16_t page_size;
               enum icsp_t icsp_type;
               uint32_t icsp_key;
               uint16_t erase_key[4];
               uint32_t write_delay;
               uint32_t erase_delay;
               uint32_t config_addr;
       };

For Family of PIC_18F2xJxx, it will be added like this:

   {
       .family = FAMILY_18F2xJxx,
       .proto = PROTO_PIC18,
       .ID_addr = 0x3ffffe,
       .word_size = 2, //bytes
       .page_size = 64, //bytes (32 words)
       .icsp_type = ICSP_LVPP,
       .icsp_key = 0x4d434850,
       .erase_key = { 0x0101, 0x8080 },
       .write_delay = 1,
       .erase_delay = 524,
       .config_addr =0x300000,   
   }


The explanation of every parts of the struct pic_family_t datatype for PIC_18F2xJxx:


.family

   -  This is defined in the enum:
   enum {
       FAMILY_18F2xJxx, // also 18F4xJxx
       FAMILY_24FJxxGAxxx,
       FAMILY_18Fx5xx,
   };


.proto

   -  This is defined in the enum:
   enum proto_t {
       PROTO_PIC12,
       PROTO_PIC16,
       PROTO_PIC18,
       PROTO_PIC24
   };


.ID_addr

   Devidlocation.PNG
   -  This is the location of the device ID word.

.word_size

   -  Word size.  Table write command, is followed by two bytes (16-bit payload). (NOT USED IN THE CODE)

.page_size

   Buffersize.PNG
   -  The write buffer page size.

.icsp_type

   -  This is specified on the enum (HVP – High Voltage Programming, LVP – Low Voltage Programming)
   enum icsp_t {
       ICSP_LVPP,
       ICSP_HVPP
   };
 

.icsp_key

   Icspkey.PNG
   -  This is the key to enter ICSP mode.

.erase_key

   Bulkerasekey.PNG
   - This is the key used for erase.

.write_delay

   - NOT USED


.erase_delay

   - Passed in the function usleep  [ usleep(1000 * f->erase_delay);  ]


.config_addr

   - NOT USED

Programming adapter

Bp-hvp-beta.jpg

Only needed for older 8bit PICs (12F/14F/16F/18F). Provides a 13volt supply and transistors to control it. Now available to developers for $7. Read more.