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

Writing to UICR from application code

Hello,

I am truing to store data in the UICR register "customer area" from application code. The procedure is invoked only once when the registers are still empty. The code is as follows:

void write_to_uicr()
{
        uint32_t data_to_write;

        uint32_t err_code = sd_softdevice_disable();
        APP_ERROR_CHECK(err_code);

        interrupts_disable();
        //...

        data_to_write = get_data();

        NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;	
        while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
        *(uint32_t *)0x10001080 = data_to_write ;
        NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;	
        while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}

}

Unfortunately the only data written to the registers is 0x00000000 even though I can verify with the debugger that the value of the "data_to_write" variable is different than zero and it is as expected. Optimizations are switched off. I would be more than glad to get any input on this problem. Thank you in advance!

Parents
  • What's the value in 0x10001080 before you do the write? UICR is like flash, it's non-volatile memory, which means you can only change bits from 1 to 0 in it. Then you have to erase it which sets it all back to 1s again before you can clear the bits again.

    So if it has 0x00000000 in it before you start, that's all you're going to get, you can't set bits back to '1', nor, I believe can you erase the UICR from within program code.

Reply
  • What's the value in 0x10001080 before you do the write? UICR is like flash, it's non-volatile memory, which means you can only change bits from 1 to 0 in it. Then you have to erase it which sets it all back to 1s again before you can clear the bits again.

    So if it has 0x00000000 in it before you start, that's all you're going to get, you can't set bits back to '1', nor, I believe can you erase the UICR from within program code.

Children
No Data
Related