how to erase UICR on nrf52832 from the code (not from nrfjprog)

I want to update some data stored in UICR CUSTOMER area on an nrf52832.

Code to do this works fine, as long as the areas are already erased (0xFFFFFFFF).

However, if they have already had a value written, and I want to update it, I understand I need to erase the UICR area first as its flash.

My process is

- copy out the non-CUSTOMER registers, to save them

- enable erase in the NVMC CONFIG

- ask the NVMC to erase by writing 1 to ERASEUICR register

- enable writing

- write back the saved registers

- go back to read mode

(and then do my usual writing code)

However, as soon as I start the process the MCU hangs (no logs, no crash, just hung).

Here is my code : I never see any of the logs probably coz the UART doesn't manage to get the bytes out!

Any ideas what I'm doing wrong?

Thanks

Parents
  • You are enabling approtect, enabling read mode and then writing the rest of the registers?  Why write after enabling read mode? 

    I suggest you to start debugger and let this code run and then pause the debugger to see where it is "hung", to understand the context. I am guessing it is looping in fault handler.

  • You are enabling approtect, enabling read mode and then writing the rest of the registers?  Why write after enabling read mode? 

    No, I read out the registers in UICR that will be lost when I do ERASEUICR, then set them back to the saved values afterwards. I just want to preserve them over ERASEUICR!

  • Have you started the debugger and let it run and paused it to see the context? Understanding the context is important like I wrote to have a proper debugging direction.

  • Came back to retry to fix this with the debugger, but the problem has gone...it now correctly manages to erase the UICR customer registers, while (as far as I can see) preserving the others.

    Maybe an interaction with the SoftDevice bluetooth stack running while my code was running...

  • I can confirm the issue is with the SoftDevice ble stack : as this takes offense and reboots if it can't schedule as it needs, this can happen during the UICR erase (as the code has to wait for this to finish), and so can get randomly rebooted....

    My workaround is to only update the UICR ina mode without SD running....

  • You cannot touch UICR registers directly when using the softdevice that is when softdevice is enabled. You need to use softdevice enabled functions like 

    sd_flash_page_erase
    sd_flash_write 
    UICR is a protected peripheral when softdevice is enabled.
  • UICR is a protected peripheral when softdevice is enabled.

    Does this mean there is no way to write to UICR when softdevice is enabled? (no sd_uicr_write or similar?)

    In a related topic, does doing the Nordic DFU operation delete or modify the UICR? (specifically the CUSTOMER[] words) 

Reply
  • UICR is a protected peripheral when softdevice is enabled.

    Does this mean there is no way to write to UICR when softdevice is enabled? (no sd_uicr_write or similar?)

    In a related topic, does doing the Nordic DFU operation delete or modify the UICR? (specifically the CUSTOMER[] words) 

Children