26.4.2.3.4 Command and Data Interface
Reading from the Flash is handled with AHB read transfers. Writing and erasing is performed by writing a command to the Command bit field in the Control B register (CTRLB.CMD), and then writing the desired word data to the desired address in the memory array.
To issue a command, the CTRLB.CMD bits must be written along with the Command Execution bit field in the Control B register (CTRLB.CMDEX). When a command is issued, the Ready flag in the Interrupt Flag Status and Clear register (INTFLAG.READY) will be cleared until the command has completed. Any commands written while INTFLAG.READY is low will be ignored, and the Programming Error Status bit in the Status register (STATUS.PROGE) will be set. If Self-Programming is used, before entering any sleep mode, ensure that any commands written to the NVM controller have completed by confirming that INTFLAG.READY is '1'.
Erasing the entire Flash (i.e. Chip Erase) cannot be done by the application when Debug Access Level (DAL) is 0, it can only be performed through the boot ROM interface from an external debugger or programmer.
- Confirm that any previous operation is completed by reading the INTFLAG.READY flag.
- Unprotect the NVMCTRL registers by clearing the Write Protection Enable bit in the Write Protection Control register (WPCTRL.WPEN).
- Write the desired command value to the CTRLB.CMD bit field.
- Write to the correct address in the array to start the operation.
- Wait for INTFLAG.READY to be set to confirm that the operation is done
- Write the NOOP or NOCMD command to the CTRLB.CMD bit field to clear the current command.
- Protect the NVMCTRL registers by setting the WPCTRL.WPEN bit.
- Confirm that any previous operation is completed by reading the INTFLAG.READY flag.
- Unprotect the NVMCTRL registers by clearing the WPCTRL.WPEN bit.
- Write the desired command value to the CTRLB.CMD bit field.
