Example code to store a 9 digits serial number in UICR

Hello,

I would like to use the UICR customer registers to store our devices serial numbers. 

Can you please point me to some example code for nRF52833 SoC.

I am using nRF Connect SDK v1.7.0.

Thank you for your help.

Kind regards
Mohamed

Parents Reply Children
  • Thank you Haakonsh.

    I currently include the following header files

    #include <zephyr.h>
    #include <power/reboot.h>
    #include <device.h>
    #include <string.h>
    #include <drivers/flash.h>
    #include <storage/flash_map.h>
    #include <fs/nvs.h>

    Will the above suck  in the files I need to write to and read from UICR?

    Or do I need to add this #include <nrfx_nvmc.h> as well?

    Kind regards

    Mohamed

  • I believe you will need the nvmc headers as well. 

  • Good morning Haakonsh,

    Thank you. I will let you know how I got on once I've tried it. 

    Kind regards

    Mohamed

  • Good Morning Haakonsh,

    I am now back working on the write and read of the UICR register.

    I am finding I can write to and read from it but the problem each time I flash the firmware in the device I lose the content of the UICR. The next read is 0xffffffff. I expected the UICR content will remain protected until it is written to again. I am inserting snippets of the code below.

    If I flash the debug build (CONFIG_DEBUG_PORT_ACCESS=y) of the firmware from SES Nordic Edition v5.60 then the UICR content is preserved. However, if I use nRF Programmer v2.3.3 then the content of the UICR being erased.

    Note, when using nRF Programmer only the 'Erase & write' option is available. The 'Write' only option is disabled, see attached screen shot below.

    void system_write_dev_id( uint32_t hb_id )
    {
        /* Allow UICR access */
        NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen;
        while (NRF_NVMC->READY == NVMC_READY_READY_Busy) { }
    
        /* Set new value for the id */
        NRF_UICR->CUSTOMER[0] = hb_id;
    
        /* Disallow UICR access */
        NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
        while (NRF_NVMC->READY == NVMC_READY_READY_Busy) { }
    }
    
    /* Read the programmed UICR device id */
    memcpy( &dev_id, (uint32_t*)0x10001080, 4 );
    
    

    Can you spot anything I am doing missing or doing wrong?

    PS Case ID: 280741 deals with the same problem but I could not find  a solution there. 

    I think the problem is in the way I am flashing the target but I am not sure how to configure nRF Programmer in order NOT to erase the UICR register.

    Thank you.

    Kind regards
    Mohamed
  • Hello Mohamed,

    What is the current state on this issue?

    Best regards,

    Simon

Related