6.7 Flash Memory Programming

The Flash Controller (FC) works with a single panel made from 4 KB pages, with each page containing four rows of Flash data. A row is the largest selectable region for contiguous programming of write words.

The FC state machine accepts commands from the NVMCON register NVMOP commands (NVMCON.NVMOP).

A page of Flash is the smallest unit of memory that can be erased in a single operation. The whole Program Flash Memory (PFM) region can be erased in a single operation.

The FC supports the following functions:
  • Row Programming - Word-by-word programming until the whole row is programmed. The FC reads the data from the system SRAM
  • Quad Word Programming - The FC performs four writes of data from holding registers
  • Single Word Programming - The FC performs one write of data from holding registers
  • Page Erase
Figure 6-1. 128-Bit-Wide Flash Module Application View

The following procedures must be used to program the device Flash using DSU. Programming the Flash is only possible when the device is not code protected. If the device is already code protected, issue the chip erase procedure to make the device unprotected and programming ready.

Programming Whole Flash (PFM and BFM Regions or Only PFM Regions)
  1. Issue the cold plugging procedure to enter into the DAP mode.
  2. Issue a chip erase procedure (only if device is code protected as described in Chip Erase).
  3. This step is needed only if programming the BFM memory region.
    1. Perform the system unlock sequence and write to the NVMLBWP register (0x440006F0)= 0x80000000.
    2. Clear LBWPn bits of NVMLBWP to remove the write protect on the corresponding page.
      Note: At Reset, all LBWPn bits of NVMLBWP are set to logic 1, write protecting all user accessible NVR pages (BFM).
    3. Set DSUEXT.TESTMODE (@0x410001FC) bit 3 to 1.
  4. Perform the procedures mentioned in Row Programming Sequence.

Programming BCFG Single Boot Page for Configurations

One page of the BFM boot region, called BCFG, is where the configuration bits are stored. These bits are set with #pragma directives embedded in the source file(s) and can be programmed as mentioned above in programming the whole Flash procedure. It can also be programmed with external IDEs like Microchip's MPLAB® X, using the configuration bits window by writing to a single BCFG page alone as mentioned below.
  1. Issue the cold plugging procedure to enter into the DAP mode.
  2. Perform the below steps to disable write protection.
    1. Perform the system unlock sequence and write to the NVMLBWP register (0x440006F0)= 0x80000000.
    2. Clear the LBWP5 bit (page 5) of NVMLBWP to remove the write protect on the corresponding page.
    3. Set DSUEXT.TESTMODE (@0x410001FC) bit 3 to 1.
  3. Issue a page erase procedure.
  4. Perform the procedures mentioned in Row Programming Sequence.