6 Programming

This section describes the MEM-AP sequences required to program the areas of memory using the development tool.

Use the following procedure to program a device Flash using the DSU. Programming the Flash is only possible when the device is not code protected. If the device is already code protected, perform the chip erase procedure to make the device unprotected and programming ready.
  1. Perform the cold plugging procedure to enter into the Debug Access Port (DAP) mode.
  2. Perform a chip erase procedure (only if device is code protected).
  3. Perform the system unlock sequence and write to the NVMLBWP register (0x440006F0) = 0x80000000. This turns off write protect to the boot flash.
    Note: At reset, all LBWPn and UBWPn bits are set to logic ‘1’, write protecting all user accessible NVR pages. Clearing a boot page bit within its register removes write protect from the corresponding page.
  4. Perform the procedures described in Programming Sequences.

    If an attempt is made to program or erase a protected page or region, the FSM executes the sequence but it has no effect. Then, reset the write protection bits for the NVR flash by writing 0x80FFFFFF to the NVMLBWP register. Bulk or chip erase commands override the effect of the NVM*WP registers.

    Note: The PIC32CX-BZ2 devices have a single panel of Flash, therefore, the UBWPUNLK register has no functionality.