11.3.2.3 Command Modes
Reading of the memory arrays is handled using the LD*/LPM(1) instructions.
The erase of the whole Flash (CHER) or the
EEPROM (EECHER) is started by writing commands to the
NVMCTRL.CTRLA register. The other write/erase operations are just enabled by writing
commands to the NVMCTRL.CTRLA register and must be followed by writes using ST*/SPM(1) instructions to the memory
arrays.
Note:
- LPM/SPM cannot be used for EEPROM.
To write a command in the NVMCTRL.CTRLA register, the following sequence needs to be
executed:
- Confirm that any previous operation is completed by reading the Busy (EEBUSY and FBUSY) flags in the NVMCTRL.STATUS register.
- Write the appropriate key to the Configuration Change Protection (CPU.CCP) register to unlock the NVM Control A (NVMCTRL.CTRLA) register.
- Write the desired command value to the CMD bit field in the Control A (NVMCTRL.CTRLA) register within the next four instructions.
To perform a write/erase operation in the NVM, the following steps are
required:
- Confirm that any previous operation is completed by reading the Busy (EEBUSY and FBUSY) flags in the NVMCTRL.STATUS register.
- Optional: If the Flash is accessed in the CPU data space, map the corresponding 32 KB Flash section into the data space by writing the FLMAP bit field in the NVMCTRL.CTRLB register.
- Write the desired command value to the NVMCTRL.CTRLA register as described before.
- Write to the correct address in the data space/code space using the ST*/SPM instructions.
- Optional: If multiple write operations are required, go to step 4.
- Write a NOOP or NOCMD command to the NVMCTRL.CTRLA register to clear the current command.