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

nRF52832 UICR serial number programming

In firmware I can read the programmed UICR serial number as follows: -

uint32_t serial;

memcpy(&serial, (uint32_t*)0x10001080, 4);

Is it possible to program the UICR from within the firmware during runtime?

Using the reverse  - memcpy( (uint32_t*)0x10001080, 4) doesn't work.

I would like to send a command to the nRF52 containing the serial number and write it to the UICR register.

  • Hi,

    Yes, you can program the UICR from firmware. However, this is flash and not RAM, so you need to do it in a different way. If you do it without/before the SoftDevice is enabled, you can do it in the same way as shown in this code snippet from boards.c (just replace the destination address with another part of the UICR):

            NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen;
            while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
    
            NRF_UICR->REGOUT0 = (NRF_UICR->REGOUT0 & ~((uint32_t)UICR_REGOUT0_VOUT_Msk)) |
                                (UICR_REGOUT0_VOUT_3V0 << UICR_REGOUT0_VOUT_Pos);
    
            NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
            while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}

    If you need to do this while the SoftDevice is enabled you should use sd_flash_write() instead.

  • Thanks for your reply.

    Just to clarify, during initialisation the firmware retrieves the serial number from address 0x10001080. Then during normal runtime, the new serial is sent over BLE and I need to write that to the same location, so after a reboot the serial is updated. If I understand correctly, then the softdevice is already running so I need to use the sd_flash_write() method?

  • Yes, that is correct. You need to use sd_flash_write() in this case.

  • Am I also correct in thinking that the soft device needs to be disabled first using sd_softdevice_disable()?

    If so, is that the correct function? I keep getting an 'undefined reference to sd_softdevice_disable()' error.

  • Hi,

    I thought I would put together an example that demonstrated this, but unfortunately it turns out that writing to the UICR with the SoftDevice enabled is not allowed, which I had forgotten. This has been requested before but it does not look like it will be implemented. So then your only option is to write to UICR with the SoftDevice disabled, or to store your serial number elsewhere in flash. I am sorry for the confusion.

    You use sd_softdevice_disable() to do that, but then you need to include nrf_sdm.h where it is declared. Note that wile disabling the SoftDEvice itself is no problem, most SDK libraries that interface the SoftDevice are not designed to handle the SoftDevice being disabled, so it is not as straight forward as you would think.

Related