This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Erase UICR and merge Bootloader problem

Hello,

I am using NRF52832 with soft device 13.0.0 and Nordic's bootloader from the examples.

What I do is develop an application which stores some values in uicr registers 0-7 (no soft device enabled yet). Before storing the values I erase the uicr registers at device startup, using the following code. (Then the rest of the application executes)

	 SEGGER_RTT_WriteString(0, "Deleting uicr \r\n");
	 NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Een << NVMC_CONFIG_WEN_Pos;
	 while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
	 NRF_NVMC->ERASEUICR = 1;
	 while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
	 
	SEGGER_RTT_WriteString(0, "Update  Version \r\n");

	NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;
	while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
	NRF_UICR->CUSTOMER[0] = hardware_version_reg;  // a uint32 value
	NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
    while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}	

Everything works fine when I test the application without a bootloader.

In the next step I use the following commands to create a hex file which includes the soft device, the bootloader (DFU) and the application:

nrfutil settings generate --family NRF52 --application testing_firmware_v01.04.hex --application-version 0x0104 --bootloader-version 0x0103 --bl-settings-version 1 bootloader_setting.hex
mergehex --merge feel_bootloader_v1.3.hex bootloader_setting.hex --output Bootldr_Settings.hex
mergehex --merge Bootldr_Settings.hex s132_nrf52_4.0.2_softdevice.hex --output SoftAndBoot.hex
mergehex --merge SoftAndBoot.hex feel_testing_firmware_v01.04.hex --output FW_merged.hex

This last hex file (FW_merged) is what i use to program the device with nRFgo Studio. Up to now, during the development, everything worked fine with this procedure.

When I added the code to erase and write the uicr as mentioned above a strange problem occurred.
When I used the FW_merged file to program the device in nRFgo Studio the bootloader would not be programmed in the device. Only the softdevice and the application would be programmed. The verification also failed. If I program the bootloader separately after that, the verification succeeds and the device works ok.

After some experimentation I saw that the command  NRF_NVMC->ERASEUICR = 1; alone would cause that problem. If I comment this line then everything runs smoothly again and the bootloader is programmed properly with the hex file.

Any ideas why this might happen? 

Thank you in advance

Related