Definition
UICR (User Information Configuration Registers) is a region of non-volatile memory, meaning memory that keeps its content without power, in the nRF52 family of chips from Nordic Semiconductor. It holds settings that a product maker chooses, such as which pin resets the chip and whether an external debugger may read memory, plus 128 bytes of free space for the maker’s data. The hardware reads its settings from UICR at every reset. UICR is flash memory §6.6: only the chip’s flash controller changes it, and no reset does.
The idea
Some settings must be in force before any program runs. Take the setting that decides whether a debugger may read the chip’s memory. If the firmware applied it with an instruction at start-up, memory would be open while the first instructions run, and a chip with no firmware, or with broken firmware, would never be closed. The setting that decides which pin resets the chip has the same problem: the hardware needs the answer while it is still coming out of reset. The chip therefore keeps such settings in a fixed place in non-volatile memory, and its reset logic reads them before the processor starts.
UICR is also kept apart from the flash pages that hold the program. Replacing the program erases and rewrites program pages; UICR has its own erase commands, so an ordinary program update leaves it alone. A settings card kept in a separate drawer of a filing cabinet is a fair picture: rewriting the files in the other drawers does not touch the card, and emptying the whole cabinet does. The picture stops in two places. Anyone who can run code on the chip can read the card, so UICR is no hiding place for secrets. And the card cannot be corrected with an eraser: a bit that has become 0 returns to 1 only when all of UICR is erased.
How it works
On the nRF52840 §6.4, a chip of the nRF52 family, UICR starts at address 0x10001000 and consists of 32-bit words. Software reads them through memory-mapped input/output §4.35: the hardware answers reads at fixed addresses, as for ordinary memory. The main registers are:
NRFFW[0]toNRFFW[12]: 13 words reserved for Nordic’s firmware, for example to record where a boot loader §6.30, the program that starts first and loads the main firmware, begins.NRFHW[0]toNRFHW[11]: 12 words reserved for Nordic’s hardware design.CUSTOMER[0]toCUSTOMER[31]: 32 words, which is bytes, free for the product maker.PSELRESET[0]andPSELRESET[1]: which pin, if any, acts as the reset pin.APPROTECT: whether access port protection §16.4 shuts an external debugger out of memory.NFCPINS: whether two pins serve an NFC (near-field communication) antenna or ordinary use.DEBUGCTRL: which processor debug features are enabled.REGOUT0: the output voltage of one stage of the chip’s voltage regulator.
An erased word reads 0xFFFFFFFF, all 32 bits 1. For every hardware setting, this erased value selects the factory default.
Four operations act on UICR.
Read. Any code running on the processor reads UICR at any time. A debugger reads it too, unless access port protection blocks the debugger.
Write. Firmware, or a debugger while it has access, switches the NVMC (Non-Volatile Memory Controller) §16.3, the circuit that writes and erases flash, into write mode, stores a full 32-bit word at a UICR address, waits until the controller reports ready, and switches it back to read-only mode. As in all flash memory, a write can change bits from 1 to 0 only.
Take effect. The chip copies its hardware settings from UICR during reset. A newly written setting therefore takes effect at the next reset, not at the moment of the write.
Erase. An erase sets every bit back to 1. No operation erases a single UICR word: each of the three operations that erase UICR erases all of it.
ERASEUICR, a controller command, erases UICR alone.ERASEALL, another controller command, erases all flash and UICR. The erase-all command that a debugger sends through Nordic’s control access port, a debug entry point that protection never closes, used for destructive debug recovery §16.6, erases all flash, UICR and RAM. The controller’s page-erase command,ERASEPAGE, works only on the program area and cannot reach UICR.
Worked example
This example uses the reset-pin setting of the nRF52840, whose reset function goes to pin 18 of port 0, written P0.18. Each PSELRESET register has three fields: PIN in bits 4 to 0, PORT in bit 5, and CONNECT in bit 31, where 0 means connected and 1 means disconnected. Nordic’s start-up code that enables the reset pin writes 18, which is 0x00000012, to both registers. Decode the value with a bit mask §4.50, a value with 1 bits in exactly the positions of one field, and the bitwise AND, which keeps a bit only where both values have a 1:
PIN:0x00000012AND0x0000001F=0x12= 18.PORT:0x12is 0001 0010 in binary; counting from bit 0 at the right, bit 5 is 0, so port 0.CONNECT: bit 31 is 0, so connected.
The reset pin is P0.18. The erased value 0xFFFFFFFF has bit 31 equal to 1, so on a chip with an erased UICR, P0.18 is an ordinary pin.
Going from the erased value to 0x00000012 needs no erase: every bit that changes goes from 1 to 0, which a write can do.
Now the product needs P0.18 back as an ordinary pin, which means CONNECT = 1. Bit 31 would have to go from 0 to 1, and no write can do that. A write leaves the AND of the old and the new value: writing 0xFFFFFFFF leaves 0x00000012 AND 0xFFFFFFFF = 0x00000012, unchanged. The only way is an erase, and the smallest erase is ERASEUICR, which also erases the 32 CUSTOMER words, APPROTECT and every other setting. Firmware that wants to keep them copies all of UICR to RAM, erases, and writes back every other word; the two PSELRESET words stay erased, which means disconnected. If power fails between the erase and the last write-back, the words not yet written back stay erased: their settings fall back to the defaults, and the maker’s data in them is lost.
Stated precisely
Let be the 32-bit value that a UICR word holds and the value written to it. After the write the word holds , where is the bitwise AND. The word holds exactly when , that is, when has no 1 where has a 0. Otherwise UICR must be erased first.
For operations that run to completion, the nRF52840 treats UICR as follows.
Preserved: every kind of reset (power-on, brownout, meaning a dip in supply voltage, reset pin, watchdog §6.16, software-requested reset, and waking from the deepest sleep mode); loss of power; erasing or writing any page of the program area; writes to other UICR words.
Changed: a write to the word, which leaves .
Destroyed, meaning every UICR word becomes
0xFFFFFFFF:ERASEUICR, the controller’sERASEALL, and the debugger’s erase-all command.
A setting written to UICR reaches the hardware at the next reset.
The contract assumes that each operation completes. An erase or write cut short by a power failure leaves the words it was changing with unknown content. The register list, the reset behavior and the erase commands above are those of the nRF52840. Other Nordic chips, such as the nRF5340, hold different registers in their UICR and erase it under different rules.
Limits and common mistakes
UICR is not secret storage. Every program on the chip can read it, and a debugger can read it whenever access port protection is off. A key kept in the CUSTOMER words is exactly as safe as the chip’s readout protection §16.5.
A setting is not in force when it is written. Code that writes a UICR setting and relies on it before the next reset relies on a setting the hardware has not yet read.
A single word cannot be returned to its erased value. Turning one bit from 0 to 1 erases all of UICR, the access protection setting and the maker’s words included. Plan UICR contents so that they are written once, in production.
The name of a programming tool’s option does not say which regions it erases. A chip-erase option erases UICR together with all flash. A file to be programmed that holds data at UICR addresses can be written only where the target bits are still 1, so a tool may erase all of UICR to write it. Check in the tool’s documentation which regions each option erases, and read UICR back after programming.
UICR is flash memory and wears out. Firmware that rewrites it often, for example to store a counter, uses up its limited number of erase cycles.
Register offsets, values and protection rules differ between Nordic chip families and between revisions of one chip. Do not carry them from one to another.
Questions answered
Which erase and programming operations preserve or destroy these settings?
On the nRF52840, a Nordic Semiconductor chip, the UICR (User Information Configuration Registers) settings are destroyed only by the three erase operations that cover UICR, and each of them erases all of UICR at once: ERASEUICR, which erases UICR alone; ERASEALL, started through the flash controller, which erases all flash and UICR; and the erase-all command that a debugger sends through the control access port to recover a protected chip, which erases flash, UICR and RAM. Everything else preserves them: every kind of reset, loss of power, erasing and writing pages of the program area, and writes to other UICR words.
A write can change a UICR word only by turning 1 bits into 0 bits. Any change of a bit from 0 to 1 needs a full UICR erase, after which every other word must be written back. A programming tool therefore preserves UICR only if it erases nothing but program pages and writes nothing to UICR; a chip-erase option destroys it. Two further rules complete the answer. A new setting takes effect at the next reset, not when it is written. And an operation cut short by a power failure leaves the words it was changing undefined, so firmware that erases UICR to change one setting loses every word it has not yet written back if power fails.
Related entries: Flash memory (§6.6), NVMC (Non-Volatile Memory Controller) (§16.3), Readout protection (§16.5), Credential-preserving programming (§16.7), FICR (Factory Information Configuration Registers) (§16.2), APPROTECT and debug access protection (§16.4), ERASEALL and destructive debug recovery (§16.6), Bit operations: truth tables, masks, shifts, and rotations (§4.50). Further reading: [55, 56].