11 Downloading the Programming Executive (PE)
The Programming Executive (PE) resides in RAM memory, and is executed by the CPU to program
the device. The PE provides the mechanism for the programmer to program and verify the PIC32
devices using a simple command set and communication protocol. The PE provides several basic
functions, such as:
- Read memory
- Erase memory
- Program memory
- Blank check
- Read executive firmware revision
- Get the Cyclic Redundancy Check (CRC) of Flash memory locations
The PE uses the device’s data RAM for variable storage and program execution. After running the PE, do not make any assumptions about the contents of data RAM.
After the PE is loaded into the data RAM, the PIC32 family can be programmed using the command set shown in Table 17-1.
Loading the PE in the memory is a two step process:
-
Load the PE loader in the data RAM. (The PE loader loads the PE binary file in the proper location of the data RAM, and when done, jumps to the programming exec and starts executing it.)
- Feed the PE binary to the PE loader.
Table 11-1 lists the steps that are required to download the PE.
Step Number | Operation | Operand |
---|---|---|
Step 1 | PIC32MX devices only: Initialize BMXCON to
0x1F0040. The instruction sequence executed by the PIC32 core
is:
| |
XferInstruction | 0x3c04bf88 | |
XferInstruction | 0x34842000 | |
XferInstruction | 0x3c05001f | |
XferInstruction | 0x34a50040 | |
XferInstruction | 0xac850000 | |
Step 2 | PIC32MX devices only: Initialize BMXDKPBA to
0x800. The instruction sequence executed by the PIC32 core
is:
| |
XferInstruction | 0x34050800 | |
XferInstruction | 0x34050800 | |
Step 3 | PIC32MX devices only: Initialize BMXDUDBA and
BMXDUPBA to the value of the BMXDRMSZ. The instruction sequence executed by the PIC32
core is:
| |
XferInstruction | 0x8C850040 | |
XferInstruction | 0xac850020 | |
XferInstruction | 0xac850030 | |
Step 4 | Set up PIC32 RAM address for PE. The instruction
sequence executed by the PIC32 core is:
| |
XferInstruction | 0x3c04a000 | |
XferInstruction | 0x34840800 | |
Step 5 | Load the PE_Loader. Repeat this step (step 5) until the
entire PE_Loader is loaded in the PIC32 memory. In the operands field,
<PE_loader hi++> represents the MSbs 31 through 16 of the PE
loader op codes shown in Table 11-2.
Likewise, <PE_loader lo++> represents the LSbs 15 through 0 of
the PE loader op codes shown in Table 11-2. The ++ sign
indicates that when these operations are performed in succession, the new word is to
be transferred from the list of op codes of the LPE loader shown in Table 11-2. The instruction sequence
executed by the PIC32 core is:
| |
XferInstruction | (0x3c06 <PE_loader hi++> ) | |
XferInstruction | (0x34c6 <PE_loader lo++> ) | |
XferInstruction | 0xac860000 | |
XferInstruction | 0x24840004 | |
Step 6 | Jump to the PE_Loader. The instruction sequence executed
by the PIC32 core is:
| |
XferInstruction | 0x3c19a000 | |
XferInstruction | 0x37390800 | |
XferInstruction | 0x03200008 | |
XferInstruction | 0x00000000 | |
Step 7 | Load the PE using the PE_Loader. Repeat the last instruction of this step (step 7) until the entire PE is loaded into the PIC32 memory. In this step, the user is given an Intel® Hex format file of the PE that the user will parse and transfer a number of 32-bit words at a time to the PIC32 memory (refer to the Appendix B: HEX File Format). The instruction sequence executed by the PIC32 is shown in Table 11-2. | |
SendCommand | ETAP_FASTDATA | |
XferFastData | PE_ADDRESS (Address of PE program block from PE Hex
file) | |
XferFastData | PE_SIZE (Number of 32-bit words of the program block from PE Hex
file) | |
XferFastData | PE software op code from PE Hex file (PE Instructions) | |
Step 8 | Jump to the PE. The magic number
(0xDEAD0000 ) instructs the PE_Loader that the PE is completely
loaded into the memory. When the PE_Loader sees the magic number, it jumps to the
PE. | |
XferFastData | 0x00000000 | |
XferFastData | 0xDEAD0000 |
Op Code | Instruction |
---|---|
0x3c07dead | lui a3, 0xdead |
0x3c06ff20 | lui a2, 0xff20 |
0x3c05ff20 | lui a1, 0xff20 |
— | herel: |
0x8cc40000 | lw a0, 0 (a2) |
0x8cc30000 | lw v1, 0 (a2) |
0x1067000b | beg v1, a3 <here3> |
0x00000000 | nop |
0x1060fffb | begz v1, <here3> |
0x00000000 | nop |
— | here2: |
0x8ca20000 | lw v0, 0 (a1) |
0x2463ffff | addiu v1, v1, -1 |
0xac820000 | SW v0, 0, (a0) |
0x24840004 | addiu a0, a0, 4 |
0x1460fffb | bnez v1, <here2> |
0x00000000 | nop |
0x1000fff3 | b <here1> |
0x00000000 | nop |
— | here3: |
0x3c02a000 | lui v0, 0xa000 |
0x34420900 | ori v0, v0, 0x900 |
0x00400008 | jr v0 |
0x00000000 | nop |