Read/write UICR CUSTOMER register under Zephyr

This topic has a lot of info but most is outdated and confusing

For the latest SDK 2.2.0 under Zephyr

-Does the Soft Device have to be disabled before NRF_UICR->CUSTOMER area can  be written?

If yes:

What API should be used?

-Is a reboot required?

-Should the UICR be erased first ? (some posts say it should) 

If so - please provide a sample how

Thanks

Parents
  • Hi,

    -Does the Soft Device have to be disabled before NRF_UICR->CUSTOMER area can  be written?

    The UICR is written using the NVMC. In the nRF5 SDK, the Soft Device prevented the application from using the NVMC.
    However, I do not think the SoftDevice Controller in the nRF Connect SDK prevents this.

    So I think it should work fine.

    What API should be used?

    The NVMC and UICR are simple enough not to need an API.
    See my unofficial sample for an example of how to write to the UICR: https://github.com/hellesvik-nordic/samples_for_nrf_connect_sdk/blob/main/ctrl-ap/eraseprotect/src/main.c#L10-L15.

    EDIT: See new comment on API

    (This code/configuration is not thoroughly tested or qualified and should be considered provided "as-is". Please test it with your application and let me know if you find any issues.)

    -Is a reboot required?

    Yes. From Writing to user information configuration registers (UICR):

    "User information configuration registers (UICR) are written in the same way as flash. After UICR has been written, the new UICR configuration will take effect after a reset."

    -Should the UICR be erased first ? (some posts say it should) 

    Short answer: Yes

    Long answer:

    When erased, all flash bits are set to "1". The NVMC can only change 1->0. So if you can change 0b11110000 -> 0b01110000, but not 0b11110000 -> 0b11110001.
    From Writing to flash:

    "The NVMC is only able to write 0 to bits in the flash that are erased (set to 1). It cannot rewrite a bit back to 1. Only full 32-bit words can be written to flash using the NVMC interface. [...]"

    Regards,
    Sigurd Hellesvik

Reply
  • Hi,

    -Does the Soft Device have to be disabled before NRF_UICR->CUSTOMER area can  be written?

    The UICR is written using the NVMC. In the nRF5 SDK, the Soft Device prevented the application from using the NVMC.
    However, I do not think the SoftDevice Controller in the nRF Connect SDK prevents this.

    So I think it should work fine.

    What API should be used?

    The NVMC and UICR are simple enough not to need an API.
    See my unofficial sample for an example of how to write to the UICR: https://github.com/hellesvik-nordic/samples_for_nrf_connect_sdk/blob/main/ctrl-ap/eraseprotect/src/main.c#L10-L15.

    EDIT: See new comment on API

    (This code/configuration is not thoroughly tested or qualified and should be considered provided "as-is". Please test it with your application and let me know if you find any issues.)

    -Is a reboot required?

    Yes. From Writing to user information configuration registers (UICR):

    "User information configuration registers (UICR) are written in the same way as flash. After UICR has been written, the new UICR configuration will take effect after a reset."

    -Should the UICR be erased first ? (some posts say it should) 

    Short answer: Yes

    Long answer:

    When erased, all flash bits are set to "1". The NVMC can only change 1->0. So if you can change 0b11110000 -> 0b01110000, but not 0b11110000 -> 0b11110001.
    From Writing to flash:

    "The NVMC is only able to write 0 to bits in the flash that are erased (set to 1). It cannot rewrite a bit back to 1. Only full 32-bit words can be written to flash using the NVMC interface. [...]"

    Regards,
    Sigurd Hellesvik

Children
Related