36.3.8.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. 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 36.3.8.1 Chip Erase. If the part is already unlocked, this point can be skipped.
- Enter the NVMPROG key by using the
KEY
instruction. See Table 36-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 Start NVM Programming (PROGSTART) bit from the ASI System Status (UPDI.ASI_SYS_STATUS) register.
- NVM programming can start when the
PROGSTART bit is ‘
1
’. If the PROGSTART 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.