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 performs the low-level tasks required for programming and verifying a device. This allows the programmer to program the device by issuing the appropriate commands and data. A detailed description on each command is provided in The PE Command Set.

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.

Figure 11-1. Downloading the PE
Loading the PE in the memory is a two step process:
  1. 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.)

  2. Feed the PE binary to the PE loader.

Table 11-1 lists the steps that are required to download the PE.

Table 11-1. Download the PE OP Codes
Step NumberOperationOperand
Step 1PIC32MX devices only: Initialize BMXCON to 0x1F0040. The instruction sequence executed by the PIC32 core is:
lui a0,0xbf88
ori a0,a0,0x2000 /* address of BMXCON */
lui a1,0x1f
ori a1,a1,0x40   /* a1 has 0x1f0040 */
sw a1,0(a0)      /* BMXCON initialized */
XferInstruction0x3c04bf88
XferInstruction0x34842000
XferInstruction0x3c05001f
XferInstruction0x34a50040
XferInstruction0xac850000
Step 2PIC32MX devices only: Initialize BMXDKPBA to 0x800. The instruction sequence executed by the PIC32 core is:
li a1,0x800
sw a1,16(a0)
XferInstruction0x34050800
XferInstruction0x34050800
Step 3PIC32MX devices only: Initialize BMXDUDBA and BMXDUPBA to the value of the BMXDRMSZ. The instruction sequence executed by the PIC32 core is:
lw a1,64(a0)       /* load BMXDMSZ */
sw a1,32(a0)
sw a1,48(a0)
XferInstruction0x8C850040
XferInstruction0xac850020
XferInstruction0xac850030
Step 4Set up PIC32 RAM address for PE. The instruction sequence executed by the PIC32 core is:
lui a0,0xa000
ori a0,a0,0x800
XferInstruction0x3c04a000
XferInstruction0x34840800
Step 5Load 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:
lui     a2, <PE_loader hi++>
ori     a2,a2, <PE_loader lo++>
sw      a2,0(a0)
addiu   a0,a0,4
XferInstruction(0x3c06 <PE_loader hi++> )
XferInstruction(0x34c6 <PE_loader lo++> )
XferInstruction0xac860000
XferInstruction0x24840004
Step 6Jump to the PE_Loader. The instruction sequence executed by the PIC32 core is:
lui   t9,0xa000
ori   t9,t9,0x800
jr    t9
nop
XferInstruction0x3c19a000
XferInstruction0x37390800
XferInstruction0x03200008
XferInstruction0x00000000
Step 7Load 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.
SendCommandETAP_FASTDATA
XferFastDataPE_ADDRESS (Address of PE program block from PE Hex file)
XferFastDataPE_SIZE (Number of 32-bit words of the program block from PE Hex file)
XferFastDataPE software op code from PE Hex file (PE Instructions)
Step 8Jump 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.
XferFastData0x00000000
XferFastData0xDEAD0000
Table 11-2. PE Loader OP Codes
Op CodeInstruction
0x3c07deadlui a3, 0xdead
0x3c06ff20lui a2, 0xff20
0x3c05ff20lui a1, 0xff20
herel:
0x8cc40000lw a0, 0 (a2)
0x8cc30000lw v1, 0 (a2)
0x1067000bbeg v1, a3 <here3>
0x00000000nop
0x1060fffbbegz v1, <here3>
0x00000000nop
here2:
0x8ca20000lw v0, 0 (a1)
0x2463ffffaddiu v1, v1, -1
0xac820000SW v0, 0, (a0)
0x24840004addiu a0, a0, 4
0x1460fffbbnez v1, <here2>
0x00000000nop
0x1000fff3b <here1>
0x00000000nop
here3:
0x3c02a000lui v0, 0xa000
0x34420900ori v0, v0, 0x900
0x00400008jr v0
0x00000000nop