Hello,
Not sure which example is this, so I can hardly comment.
But to guide you trough erase process, you can follow manual: 32.4.1.3 Erase
You can check which part of the erase execution failed.
The erase sequence is fully automated within the flash memory. Blocks to be erased must be
selected prior to initiating the erase sequence. Locked/disabled blocks cannot be erased.
If multiple blocks are selected for erase during an erase sequence, the blocks are erased
sequentially starting with the lowest numbered block and terminating with the highest
(low first, mid second, high last, 16 KB first, 32 KB second, 64 KB third, last blocks are
256 KB). The erase sequence consists of the following events:
1. Change the value in the MCR[ERS] bit from 0 to 1.
2. Select the block or blocks to be erased by writing ones to the appropriate registers in
SEL0, SEL1, SEL2, or SEL3 registers.
NOTE
Lock and Select are independent. If a block is selected and
locked, no erase occurs.
3. Write to any address in flash memory. This is referred to as an erase interlock write.
An erase interlock write to UTest NVM space is not allowed.
4. Write a logic 1 to the MCR[EHV] bit to start an internal erase sequence or skip to
step 9 to terminate.
5. Wait until the MCR[DONE] bit goes high.
NOTE
Since MCR[DONE] clears with MCR[EHV] being set, it
may not be possible for software to read MCR[DONE] as a
0 prior to this step, depending on the operation selected.
6. Confirm MCR[PEG] = 1.
7. Write a logic 0 to the MCR[EHV] bit.
8. If more blocks are to be erased, return to step 2.
9. Write a logic 0 to the MCR[ERS] bit to terminate the erase.
and I have to reset the debugger and everything else
Is the device erased after the erase sequence? Maybe you also erase part of the code from which you are executing.
Best regards,
Peter