Hello,
I am using anrf9160 chip. I have a question about the ERASEPROTECT register. I would like to write it using the firmware to disable the ERASEALL functionality.
I am not sure to understand how to recover the device when this flag is set. https://infocenter.nordicsemi.com/topic/ps_nrf9160/chapters/dif/ctrl-ap.html?cp=2_0_0_8_1_3#ctrlap_unlocking.
Can I simply rewrite into this register?
Here is the code I use to block the SWD port and access to registers.
NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos);
while (NRF_NVMC->READY == NVMC_READY_READY_Busy) {}
NRF_UICR->APPROTECT = 0x00000000;
NRF_UICR->SECUREAPPROTECT = 0x00000000;
while (NRF_NVMC->READY == NVMC_READY_READY_Busy) {}
/* Restore read access */
NRF_NVMC->CONFIG = (NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos);
while (NRF_NVMC->READY == NVMC_READY_READY_Busy){}
return NRF_UICR->APPROTECT | NRF_UICR->SECUREAPPROTECT;
And I would like to add:
NRF_UICR->ERASEPROTECT = 0x00000000;
However, I want to be sure that I can recover my device in this case. I was planning to add a function that reset the ERASEPROTECT register to 0xffffffff and that can be set through an UART command.
- Would that work?
The second question I have is on the CTRL_AP_PERI_S.LOCK register. If I write it in the firmware, the only way to recover the device is by doing an erase ALL. But in this case the debugger and the firmware must have the same key in the ERASEALL.DISABLE.KEY field. I was planning to use the JLink commander and use the following:
SWDSelect
SWDWriteDP 1 0x50000000
SWDWriteDP 2 0x04000000
SWDWriteDP 2 0x04000000 // Bank 0
SWDReadAP 7 // register offset 7 (7*4 = 0x1C for ERASEPROTECT.DISABLE)
SWDReadAP 7
SWDWriteAP 7 0xDEADBEEF
Assuming that 0xDEADBEEF is also in the CTRL_AP_PERI_S.DISABLE (NRF_CTRL_AP_PERI_S->ERASEPROTECT.DISABLE in the code) register of the device.
With that procedure, will the device be erased? I want to be sure that the SWD command will still work as APPROTECT is on..
Thanks