30.2.12 SFR Write Protect Features

A number of mechanisms exist within the device to ensure that inadvertent writes to program Flash do not occur. They are :

  1. PAC write protection.
  2. An unlock value (KEY) to allowing writing critical registers.
  3. Local SFR bits that provide write locks for other SFR bits.
  4. SFR bits that provide write/erase protection of Flash memory regions.

PAC SFR Write Protection

Registers with write access can be optionally write-protected by the Peripheral Access Controller (PAC). Write protection does not extend to external debugger accesses. Note that PAC write protection is not applied during debug. The register descriptions below will show “PAC Write Protection” under “Properties:” for those registers that can be write protected using the PAC module.

SFR Write Unlock Values

The KEY register provides write protection to critical NVM registers. KEY uses multiple KEY Values to unlock access to classes of registers. Writing the specific KEY Value to the KEY register unlocks access to the defined set of registers. When the KEY Value protects a multitude of registers the unlock remains in effect until SW clears it. When the KEY Value protects a single register KEY clears after a successful write.

KEY is always cleared by a write to a protected register. This causes the INTFLAG.KEYERR bit to be set. SW can clear the unlock state by writing any invalid key to it (recommend all 0’s). The INTFLAG.KEYERR is not set by this case.

Setting KEY.KEY = <CFGKEY> unlocks CTRLB, PWPx (x = 0,1,…,7), LBWP, UBWP, UOWP, and CWP. Setting KEY.KEY = <WRKEY> unlocks CTRLA. Setting KEY.KEY = <SWAPKEY> unlocks SWAP.

Local Lock Bits

Some SFR bits have associated local lock bits. These bits lock updates of the associated feature until the next reset. Lock bits are found in SWAP, PWPx, LBWP, UBWP, UOWP, and CWP.