6.7.1 Chip Erase
Erase the entire Flash (PFM and BFM memory regions) except the OTA BFM page using a DSU command.
When the device is protected, the debugger must reset the device to be detected. This ensures that internal registers are reset after the protected state is removed. The chip erase operation is triggered by writing a 1
to the Chip Erase bit in the Control register (DSUEXT.CTRL.CE). This command will be discarded if the DSU is protected by the Peripheral Access Controller (PAC).
The chip erase operation depends on clocks and power management features that can be altered by the CPU. For that reason, it is recommended that a chip erase be issued after a cold-plugging procedure to ensure that the device is in a known and safe state.
- Perform the cold plugging procedure (refer to the Cold Plugging from DSU section in the PIC32CX-BZ3/PIC32CX-BZ36 and WBZ35x
Module Family Data Sheet (DS70005541)). The device, then:
- Detects the debugger probe
- Holds the CPU in Reset
- Perform the chip erase command by writing a
1
to DSUEXT.CTRL.CE at (0x41000100 address). The device, then:- Clears the system volatile memories
- Erases the whole Flash array (excluding OTP page)
- Erases the code protection row, removing the code protection security bit protection
- Check for completion by polling DSUEXT.STATUSA.DONE at (0x41000101 address) (read as
1
when completed). - Reset the device.
Steps | Commands |
---|---|
Clear flags in STATUSA | WriteD8(@DSUEXT.STATUSA.DSU_STATUSA_DONE_MASK) |
Issue chip erase | WriteD8(@DSUEXT.CTRL, DSU_CTRL_CE) |
Wait until erase is done | ReadD8(@DSUEXT.STATUSA,StatusValue) While ( (StatusValue& DSU_STATUSA_DONE) == 0) { ReadD8(@DSUEXT.STATUSA,StatusValue) } |
- DSU_CTRL_CE = 0x10
- DSU_STATUSA_MASK = 0x1F
- DSU_STATUSA_DONE = 0x1