33.3.7.2 NVM Programming

If the device is unlocked, it is possible to write directly to the NVM Controller using the UPDI. This will lead to unpredictable code execution if the CPU is active during the NVM programming. To avoid this, the following NVM Programming sequence should be executed.

  1. Follow the Chip Erase procedure as described in Chip Erase. If the part is already unlocked, this point can be skipped.
  2. Enter the NVMPROG KEY by using the KEY instruction. See Table 33-6 for the NVMPROG signature.
  3. Optional: Read the NVMPROG field in the KEY_STATUS register to see that the KEY has been activated.
  4. Write the Reset signature into the ASI_RESET_REQ register. This will issue a System Reset.
  5. Write 0x00 to the Reset signature in the ASI_RESET_REQ register to clear the System Reset.
  6. Read NVMPROG in ASI_SYS_STATUS.
  7. NVM Programming can start when NVMPROG == 1 in the ASI_SYS_STATUS register. If NVMPROG == 0, go to point 6 again.
  8. Write data to NVM through the UPDI.
  9. Write the Reset signature into the ASI_RESET_REQ register. This will issue a System Reset.
  10. Write 0x00 to the Reset signature in the ASI_RESET_REQ register to clear the System Reset.
  11. Programming is complete.