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

Writing to UICR_Customer from operating SD system is failing.

Using SD 6.2 and sDK 15 I need to write to the UICR_Customer space while the BLE system is operating.

I tried pulling example code from https://devzone.nordicsemi.com/f/nordic-q-a/11781/writing-to-uicr-from-application-code and https://devzone.nordicsemi.com/f/nordic-q-a/13742/is-there-sample-code-for-writing-to-an-uicr-register but neither gets the value written to UICR, even after a reboot. 

When running the write routine, I just get a reboot, Trying to isolate it, I get a reboot when I just call nrf_sdh_disable_request() followed by nrf_sdh_enable_request() with no intervening code.

My full routine as of now is:

bool FLSH_WriteData(uint32_t start_addr, const uint8_t *src, size_t len)
{
    uint32_t *src32 = (uint32_t *)src;
    uint8_t addr = (start_addr - (uint32_t )(&NRF_UICR->CUSTOMER[0])) / sizeof(uint32_t);

    addr = 0;
    nrf_sdh_disable_request();
    /* MWU Disable -- This is workaround suggested by Aryan on the Nordic Developer Zone */

    /* Turn on flash write enable and wait until the NVMC is ready: */
    NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos);
    while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}

//    while(len > 0)
    {
        /* write to the register */
        NRF_UICR->CUSTOMER[addr] = 0x12345678; //*src32;
        while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}

        len -= 4;
        addr += 1;
        src32 += 1;
    }

    /* Turn off flash write enable and wait until the NVMC is ready: */
    NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos);
    while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}

    nrf_sdh_enable_request();
    return true;
}   

I know about maybe needing to use the MWU enable as well, but that does not help at the moment and still just causes a reboot without writing to the flash.

I have verified that the UICR space I am writing it erased (all 0xFF).

Parents Reply
  • Hi,

    It's not necessary to disable MWU, nrf_sdh_disable_request() should do that for you. I think the reboot must be caused by something else in your application. You can place a breakpoint in the app_error_handler to see if there any asserts. In any case, I would suggest that you keep Manufacturing data in a RAM buffer while it's connected, then once disconnected, copy the RAM to UICR.

    Something like this:  

    1. wait for the disconnect event

    2. Stop timer any instances you may have running.

    3. Call  FLSH_WriteData()

    4. Call NVIC_SystemReset() to reboot your app. 

Children
No Data
Related