NVMC — Non-volatile memory controller

The non-volatile memory controller (NVMC) is used for writing and erasing of the internal flash memory and the UICR (user information configuration registers).

The CONFIG is used to enable the NVMC for writing (CONFIG.WEN = Wen) and erasing (CONFIG.WEN = Een).

The CPU must be halted before initiating a NVMC operation from the debug system.

Writing to flash

When write is enabled, full 32-bit words can be written to word-aligned addresses in flash memory.

As illustrated in Memory, the flash is divided into multiple pages. The same 32-bit word in flash memory can only be written n WRITE number of times before a page erase must be performed.

The NVMC is only able to write 0 to bits in flash memory that are erased (set to 1). It cannot rewrite a bit back to 1. Only full 32-bit words can be written to flash memory using the NVMC interface. To write less than 32 bits, write the data as a full 32-bit word and set all the bits that should remain unchanged in the word to 1. The restriction on the number of writes (nWRITE) still applies in this case.

Only word-aligned writes are allowed. Byte or half-word-aligned writes will result in a hard fault.

The time it takes to write a word to flash is specified by tWRITE. The CPU is halted if the CPU executes code from the flash while the NVMC is writing to the flash.

NVM writing time can be reduced by using READYNEXT. If this status bit is set to 1, code can perform the next data write to the flash. This write will be buffered and will be taken into account as soon as the ongoing write operation is completed.

Erasing a page in flash

When erase is enabled, the flash memory can be erased page by page using the ERASEPAGE.

After erasing a flash page, all bits in the page are set to 1. The time it takes to erase a page is specified by tERASEPAGE. The CPU is halted if the CPU executes code from the flash while the NVMC is writing to the flash.

See Partial erase of a page in flash for information on dividing the page erase time into shorter chunks.

Writing to user information configuration registers (UICR)

User information configuration registers (UICR) are written in the same way as flash. After UICR has been written, the new UICR configuration will only take effect after a reset.

UICR can only be written nWRITE number of times before an erase must be performed using ERASEUICR or ERASEALL. The time it takes to write a word to UICR is specified by tWRITE. The CPU is halted if the CPU executes code from the flash while the NVMC is writing to the UICR.

Erasing user information configuration registers (UICR)

When erase is enabled, UICR can be erased using the ERASEUICR.

After erasing UICR, all bits in UICR are set to 1. The time it takes to erase UICR is specified by tERASEPAGE. The CPU is halted if the CPU executes code from the flash while the NVMC performs the erase operation.

Erase all

When erase is enabled, flash and UICR can be erased completely in one operation by using the ERASEALL. This operation will not erase the factory information configuration registers (FICR).

The time it takes to perform an ERASEALL command is specified by tERASEALL. The CPU is halted if the CPU executes code from the flash while the NVMC performs the erase operation.

Access port protection behavior

When access port protection is enabled, parts of the NVMC functionality will be blocked in order to prevent intentional or unintentional erase of UICR.

Table 1. NVMC Protection
CTRL-AP ERASEALLNVMC ERASEPAGENVMC ERASEPAGE PARTIALNVMC ERASEALLNVMC ERASEUICR
APPROTECT
DisabledAllowedAllowedAllowedAllowedAllowed
EnabledAllowedAllowedAllowedAllowedBlocked

NVMC power failure protection

NVMC power failure protection is possible through use of power-fail comparator that is monitoring power supply.

If the power-fail comparator is enabled, and the power supply voltage is below VPOF threshold, the power-fail comparator will prevent the NVMC from performing erase or write operations in non-volatile memory (NVM).

If a power failure warning is present at the start of an NVM erase operation, the NVMC operation will be ignored.

If a power failure warning is present at the start of an NVM write operation, the CPU will hardfault.

Partial erase of a page in flash

Partial erase is a feature in the NVMC to split a page erase time into shorter chunks to prevent longer CPU stalls in time-critical applications. Partial erase is only applicable to the code area in flash memory and does not work with UICR.

When erase is enabled, the partial erase of a flash page can be started by writing to ERASEPAGEPARTIAL. The duration of a partial erase can be configured in ERASEPAGEPARTIALCFG. A flash page is erased when its erase time reaches tERASEPAGE. Use ERASEPAGEPARTIAL N number of times so that N * ERASEPAGEPARTIALCFG ≥ tERASEPAGE, where N * ERASEPAGEPARTIALCFG gives the cumulative (total) erase time. Every time the cumulative erase time reaches tERASEPAGE, it counts as one erase cycle.

After the erase is complete, all bits in the page are set to 1. The CPU is halted if the CPU executes code from the flash while the NVMC performs the partial erase operation.

The bits in the page are undefined if the flash page erase is incomplete, i.e. if a partial erase has started but the total erase time is less than tERASEPAGE.

Registers

Instances

InstanceBase addressDescription
NVMC0x4001E000Non-volatile memory controller

Register overview

RegisterOffsetDescription
READY0x400Ready flag
READYNEXT0x408Ready flag
CONFIG0x504Configuration register
ERASEPAGE0x508Register for erasing a page in code area
ERASEALL0x50CRegister for erasing all non-volatile user memory
ERASEUICR0x514Register for erasing user information configuration registers
ERASEPAGEPARTIAL0x518Register for partial erase of a page in code area
ERASEPAGEPARTIALCFG0x51CRegister for partial erase configuration

READY

Address offset: 0x400

Ready flag

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000100000000000000000000000000000001
IDR/WFieldValue IDValueDescription
ARREADYNVMC is ready or busy
Busy0NVMC is busy (on-going write or erase operation)
Ready1NVMC is ready

READYNEXT

Address offset: 0x408

Ready flag

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000100000000000000000000000000000001
IDR/WFieldValue IDValueDescription
ARREADYNEXTNVMC can accept a new write operation
Busy0NVMC cannot accept any write operation
Ready1NVMC is ready

CONFIG

Address offset: 0x504

Configuration register

Bit number313029282726252423222120191817161514131211109876543210
IDAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
ARWWENProgram memory access mode. It is strongly recommended to only activate erase and write modes when they are actively used.
Ren0Read only access
Wen1Write enabled
Een2Erase enabled

ERASEPAGE

Address offset: 0x508

Register for erasing a page in code area

Bit number313029282726252423222120191817161514131211109876543210
IDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
AWERASEPAGE

Register for starting erase of a page in code area

The value is the address to the page to be erased. (Addresses of first word in page). The erase must be enabled using CONFIG.WEN before the page can be erased. Attempts to erase pages that are outside the code area may result in undesirable behavior, e.g. the wrong page may be erased.

ERASEALL

Address offset: 0x50C

Register for erasing all non-volatile user memory

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
AWERASEALLErase all non-volatile memory including UICR registers. The erase must be enabled using CONFIG.WEN before the non-volatile memory can be erased.
NoOperation0No operation
Erase1Start chip erase

ERASEUICR

Address offset: 0x514

Register for erasing user information configuration registers

Bit number313029282726252423222120191817161514131211109876543210
IDA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
AWERASEUICRRegister starting erase of all user information configuration registers. The erase must be enabled using CONFIG.WEN before the UICR can be erased.
NoOperation0No operation
Erase1Start erase of UICR

ERASEPAGEPARTIAL

Address offset: 0x518

Register for partial erase of a page in code area

Bit number313029282726252423222120191817161514131211109876543210
IDAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Reset 0x0000000000000000000000000000000000000000
IDR/WFieldValue IDValueDescription
AWERASEPAGEPARTIAL

Register for starting partial erase of a page in code area

The value is the address to the page to be partially erased (address of the first word in page). The erase must be enabled using CONFIG.WEN before every erase page partial and disabled using CONFIG.WEN after every erase page partial. Attempts to erase pages that are outside the code area may result in undesirable behavior, e.g. the wrong page may be erased.

ERASEPAGEPARTIALCFG

Address offset: 0x51C

Register for partial erase configuration

Bit number313029282726252423222120191817161514131211109876543210
IDAAAAAAA
Reset 0x0000000A00000000000000000000000000001010
IDR/WFieldValue IDValueDescription
ARWDURATION

Duration of the partial erase in milliseconds

The user must ensure that the total erase time is long enough for a complete erase of the flash page.

Electrical specification

Flash programming

SymbolDescriptionMin.Typ.Max.Units
nWRITENumber of times a 32-bit word can be written before erase2
nENDURANCEErase cycles per page10000
tWRITETime to write one 32-bit word42.51µs
tERASEPAGETime to erase one page87.51ms
tERASEALLTime to erase all flash1731ms
tERASEPAGEPARTIAL,accAccuracy of the partial page erase duration. Total execution time for one partial page erase is defined as ERASEPAGEPARTIALCFG * tERASEPAGEPARTIAL,acc.1.091
1 Applies when HFXO is used. Timing varies according to HFINT accuracy when HFINT is used.