Write and read data at UICR - cristianoborgescardoso/nrf52 GitHub Wiki

Useful information

UICR — User information configuration registers Reference Manual Reference Manual in PDF

Erase UICR

  • If the area to write is not erased is necessary erase it before writing.
$ nrfjprog -f NRF52 --eraseuicr
Erasing code and UICR flash areas.
Applying system reset.

Writing a UICR register

$  nrfjprog  -f NRF52  --memwr 0x10001014 --val 0xfaceb00c
Parsing parameters.
Writing.

Reading a UICR register

$ nrfjprog -f NRF52 --memrd 0x10001014 --n 4
0x10001014: FACEB00C                              |....|

Reading all UICR registers and storing the output in a file

$ nrfjprog -f NRF52 --readuicr uicr.txt
Reading UICR.
Storing data in uicr.txt.

Reading a UICR register on NRF52 project

//from: https://devzone.nordicsemi.com/f/nordic-q-a/34262/system-reset-after-uicr-erase-and-write-leads-to-system-off/131879#131879  
void readUICR(void)
{       
	//Storage buffers and variables to hold the UICR register content
	printf("Storage buffers and variables to hold the UICR register content\n");
	static uint32_t uicr_buffer[59]    = {0x00000000};
	static uint32_t pselreset_0        = 0x00000000;
	static uint32_t pselreset_1        = 0x00000000;
	static uint32_t approtect          = 0x00000000;
	static uint32_t nfcpins            = 0x00000000;
	

	//CRITICAL_REGION_ENTER();
	//Read and buffer UICR register content prior to erase 
	printf("Read and buffer UICR register content prior to erase\n");
	uint32_t uicr_address = 0x10001014;

	for(int i = 0; i < sizeof(uicr_buffer); i++)
	{
		uicr_buffer[i] = *(uint32_t *)uicr_address; 
		while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
		//Set UICR address to the next register
		uicr_address += 0x04;
	}
  
	pselreset_0 = NRF_UICR->PSELRESET[0];
	pselreset_1 = NRF_UICR->PSELRESET[1];
	approtect   = NRF_UICR->APPROTECT;
	nfcpins     = NRF_UICR->NFCPINS;
	

	uicr_address = 0x10001014;
	for(int j = 0; j<sizeof(uicr_buffer); j++)
	{
		printf("Register: '%x' = '%x'\n",uicr_address, uicr_buffer[j]);nrf_delay_ms(10);//without this delay the serial print will not work properly
		if(uicr_buffer[j] != 0xFFFFFFFF)
		{
			//NOT Erased
		}
		//Set UICR address to the next register
		uicr_address += 0x04;  
	}
   // CRITICAL_REGION_EXIT();
}

UCIR Memory Range

Name Address
CUSTOMER[0] 0x10001180
CUSTOMER[1] 0x10001184
CUSTOMER[2] 0x10001188
CUSTOMER[3] 0x1000118c
CUSTOMER[4] 0x10001190
CUSTOMER[5] 0x10001194
CUSTOMER[6] 0x10001198
CUSTOMER[7] 0x1000119c
CUSTOMER[8] 0x100011a0
CUSTOMER[9] 0x100011a4
CUSTOMER[10] 0x100011a8
CUSTOMER[11] 0x100011ac
CUSTOMER[12] 0x100011b0
CUSTOMER[13] 0x100011b4
CUSTOMER[14] 0x100011b8
CUSTOMER[15] 0x100011bc
CUSTOMER[16] 0x100011c0
CUSTOMER[17] 0x100011c4
CUSTOMER[18] 0x100011c8
CUSTOMER[19] 0x100011cc
CUSTOMER[20] 0x100011d0
CUSTOMER[21] 0x100011d4
CUSTOMER[22] 0x100011d8
CUSTOMER[23] 0x100011dc
CUSTOMER[24] 0x100011e0
CUSTOMER[25] 0x100011e4
CUSTOMER[26] 0x100011e8
CUSTOMER[27] 0x100011ec
CUSTOMER[28] 0x100011f0
CUSTOMER[29] 0x100011f4
CUSTOMER[30] 0x100011f8
CUSTOMER[31] 0x100011fc