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

Writing into UICR register by disabling SoftDevice

Hello,

 

I am using nRF52840, SDK_16.0.0, SoftDevice S140 V7.0.1 and Segger for flashing the image. I am using ‘ble_app_blinky’.

 

1) I want to write Serial number into UICR register. Since SoftDevice is enabled, I am not able to update UICR register. If we can update UICR even with SoftDevice, please let me know the procedure.

 

2) I follower below approach. Write UICR register with 5 bytes of Serial number and then reset the chip. Is this approach fine.

a) Is waiting for busy state of NVMC is correct ?

         

void writeSerialNumber(uint8_t* p8SeralNumber)
{
    // Disable Soft Device
    sd_softdevice_disable();
    
    // Write Serial Number into UICR register
    nrf_nvmc_write_bytes((uint32_t)0x1000108C,  (const uint8_t *) p8SeralNumber, 5);

    while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
    NVIC_SystemReset();
}

 

3) Whether NVIC_SystemReset() do a complete reset. To my understanding it’s a Soft reset. Correct me if I am working.

a) How about RAM during Soft reset. Will it be erased ?

 

4) Using nrfjprog, if I try to re-write I will get error. But I dont see such mechanism when I use nrf_nvmc_write_byte(). It is a void function. In this case, do I need check before writing.

 Thanks & Regards

Vishnu Beema

  • Hi,

    1. You wont be able to write to UICR while softdevice is enabled and we do not have any API exposed by softdevice to allow writing to UICR while SD is enabled.
    2. nrf_nvmc_write_bytes already waits for flash ready, so you do not need to wait again for it.'
    3. NVIC_SystemReset is a soft reset. You need to do a pin reset if you want a hard reset.
      1. It is not clear what you are trying to ask here. Softreset will NOT reset RAM
    4. You cannot write to already wriiten UICR address. You need to erase the UICR page (and this you can only do by erasing the whole chip). nrfjprog will not write to any address that has already some value in it.
  • Hi Susheel,

    Thank you for your inputs.

    1) You mean nrf_nvmc_write_bytes() will wait for flash ready before writing into flash. I kept even after writing and before soft reset. Whether even this is taken care. My intention is not to do soft reset before writing into UICR. 

    2) Good to know Soft reset will not reset RAM. In other chips, usually Soft reset will also reset RAM. After writing UICR, its mentioned to reset chip. So in this case Soft reset is good enough or do I need to do hard reset after writing UICR register to take effect.

    3) Yes, that's what I am mentioned. nrfjprog will not allow (This is fine). But when I call nrf_nvmc_write_byte() and try to write same location with different values, in this case, I am not getting any error and able to write.

    Thanks & Regards

    Vishnu Beema

  • beemavishnu said:
    You mean nrf_nvmc_write_bytes() will wait for flash ready before writing into flash.

     No, I mean that it will wait that the flash write has been successful by checking that NRF_NVMC->READY state is NOT busy.

     

    beemavishnu said:
    But when I call nrf_nvmc_write_byte() and try to write same location with different values, in this case, I am not getting any error and able to write.

     But you should not write to an already written flash address with another value unless you just want to toggle few bits with value '1' to bits with value '0'. NVMC only can toggle bits from 1's to 0's and cannot toggle bits from 0's to 1's unless you do a full page erase.

Related