hanging at NRF_UICR->CUSTOMER reading at startup in release build


I have this very strange issue where my code is hanging at startup while reading NRF_UICR->CUSTOMER register when build release code. system doesn't hang in debug build.

what am I doing wrong?

  • Hi,

    Reading from the UICR is not different from reading from other parts of the flash, so I suspect the issue is not related to the UICR itself. Can you say a bit more about the issue? And what are you able to find out when debugging? Most importantly, when you write "hanging", what state is the system really in? Is it in an error handler,  did a fault occur, or is it just stuck in a waiting loop, is the device in a reset loop, or something else?

  • Hi Einar,

    I reckon I haven't provide enough info, my apologies.

    I have this code:

    static void get_device_identity(void)
        char buffer[4], buffer2[4]="0000", dn[12] = "CCTM2480";
      uint8_t id[4];
      int no_chars=0, indx;
      NRF_NVMC->CONFIG = 0;
      while (NRF_UICR->CUSTOMER[0]==0xFFFFFFFF);
       // Wait until device identity has been set to non-zero value
      id[0] = NRF_UICR->CUSTOMER[0];
      no_chars = sprintf(buffer, "%x", id[0]);
      indx = no_chars - 1;
      strcpy(&buffer2[4-indx-1], buffer);
      strcat(dn, buffer2);
      strcpy(device_name, dn);

    release build is stuck in the while loop, but the debug build can read the register immediately

  • Hi,

    What I see in this code snippet is that you configures the NVMC for read only on line 7 and wait for it to be something else than 0xFFFFFFFF. I must admitt that does not make full sense to me. Clearly this should have been written to somewhere else, butthat must happen before line 7 is executed as that disables writing.

    Where is the code that enables writing and actually writes? And how is this called in relationship to this code? And why do you disable writing here (in the function that just reads), instead of right after writing?

    To be clear, for writing to the UICR, you can look at for instance gpio_output_voltage_setup() from <nRF5 SDK 17.1.0>/components/boards/boards.c. For reading, just read the address just like any other memory. There is no need to write to NRF_NVMC->CONFIG before reading.