37.3.7.2 NVM Programming
If the device is unlocked, it is possible to write directly to the NVM Controller or the Flash memory using the UPDI, which will lead to unpredictable code execution if the CPU is active during the NVM programming. To avoid this, execute the following NVM programming sequence:
- Follow the chip erase procedure, as described in the Chip Erase section. Skip this point if the part is already unlocked.
- Enter the NVMPROG key by using the
KEY
instruction. See Table 37-6 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.