31.1.8 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 :
- Module write protection.
- An unlock value (KEY) to allowing writing critical registers.
- Local SFR bits that provide write locks for other SFR bits.
- SFR bits that provide write/erase protection of Flash memory regions.
Only items 1, 2, and 3 will be discussed here.
SFR Write Protection
Registers with write access can be optionally write-protected by the Peripheral Access Controller (PAC) or the WPCTRL. Write protection does not extend to HSM if present or external debugger accesses. HSM SFRs are protected with HSMWPCTRL and are only accessible by an external debugger connected to the HSM CPU.
See the Control Operation (CTRLOP) register.
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, the KEY clears after a successful write.
KEY is always cleared by a write to a KEY protected register that is currently locked. 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.
See the Control Operation (CTRLOP) register for a summary of registers and which ones require a KEY Value to unlock them.
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, PWP, LBWP, UBWP, UOWP, CWP.