9 Erasing the Device

Before a device can be programmed, it must be erased. The erase operation writes all ‘1s’ to the Flash memory and prepares it to program a new set of data. Once a device is erased, it can be verified by performing a “Blank Check” operation. See Blank Check for more information.

The procedure for erasing program memory (program, boot, and configuration memory) consists of selecting the MTAP and sending the MCHP_ERASE command. The programmer must wait for the erase operation to complete by reading and verifying bits in the MCHP_STATUS value. Figure 9-1 illustrates the process for performing a chip erase operation.
Note: The device ID memory locations are read-only and cannot be erased. Therefore, the chip erase operation has no effect on these memory locations.
The following steps are required to erase a target device:
  1. SendCommand (MTAP_SW_MTAP).
  2. SetMode (6’b011111).
  3. SendCommand (MTAP_COMMAND).
  4. XferData (MCHP_ERASE).
  5. XferData (MCHP_DE_ASSERT_RST).
    Note: This step is not required for the PIC32MX devices.
  6. Delay 10 ms.
  7. statusVal = XferData (MCHP_STATUS).
  8. If CFGRDY (statusVal[3]) is not ‘1’ and FCBUSY (statusVal[2]) is not ‘0’, go to step 5.note
    Note: The Chip Erase operation is a self-timed operation. If the FCBUSY and CFGRD bits do not set properly within the specified Chip Erase time, the sequence may have been executed incorrectly or the device is damaged.
Figure 9-1. Erase Device