30.3.8.2 NVM Programming
If the device is unlocked, it is possible to write directly to the NVM Controller or to the Flash memory 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 has to be executed.
- Follow the chip erase procedure, as described in Chip Erase. If the part is already unlocked, this point can be skipped.
- Enter the NVMPROG key by using the
KEY
instruction. See Table 30-5 for the NVMPROG signature. - Optional: Read the NVM Programming Key Status (NVMPROG) bit from the ASI Key Status (UPDI.KEY_STATUS) register to see if the key has been activated.
- Write the signature to the Reset Request (RSTREQ) bit in the ASI Reset Request (UPDI.ASI_RESET_REQ) register. This will issue a System Reset.
- Write
0x00
to the ASI Reset Request (UPDI.ASI_RESET_REQ) register to clear the System Reset. - Read the NVM Programming Key Status (NVMPROG) bit from the ASI System Status (UPDI.ASI_SYS_STATUS) register.
- NVM Programming can start when the
NVMPROG bit is ‘
1
’. If the NVMPROG bit is ‘0
’, return to step 6. - Write data to NVM through the UPDI.
- Write the signature to the Reset Request (RSTREQ) bit in the ASI Reset Request (UPDI.ASI_RESET_REQ) register. This will issue a System Reset.
- Write
0x00
to the ASI Reset Request (UPDI.ASI_RESET_REQ) register to clear the System Reset. - Programming is complete.