config flash read protection in code
config flash read protection in code
Hi
There are two rather simple ways to enable readback protection using the APPROTECT register. Either, you can set it in your application code like my colleague explains in this thread. Or, you can download nrfjprog on your computer and enable APPROTECT by calling the command nrfjprog --rbp all in a command window when your device is connected. In both cases, you will have to recover the chip/ do a full chip erase in order to access the memory of the chip.
When you set the APPROTECT register, JTAG will keep working until you reset the device, at which point the readback protection will kick in, and your JTAG and SWD will be disabled, and you won't be able to use the RTT viewer.
Best regards,
Simon
can you give me the sample code use APPROTECT register to do readback protection ,thanks
NRF_UICR->APPROTECT=0xffffff00; run the code , but still can readback FLASH DATA through J-FLASH , why?
I think this is because you need a system reset in order to "activate" the readback protection. Either, set the following const in outside any function in your main file (this won't require a system reset for the readback protection to turn on:
const uint32_t approtect_set __attribute__((used,at(0x10001208))) = 0xFFFFFF00;
Or, you can add this snippet at I.E. the start of your main() loop, which will set readback protection and trigger a system reset to enable the readback protection.
void nrf_nvmc_write_word(uint32_t address, uint32_t value) { // Enable write. NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen; __ISB(); __DSB(); *(uint32_t*)address = value; while (NRF_NVMC->READY == NVMC_READY_READY_Busy) {;} NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren; __ISB(); __DSB(); } int main(void) { nrf_delay_ms(1000); if (NRF_UICR->APPROTECT == 0xFFFFFFFF) { nrf_nvmc_write_word((uint32_t)&(NRF_UICR->APPROTECT), 0xFFFFFF00); NVIC_SystemReset(); }
Best regards,
Simon
thanks! const uint32_t approtect_set __attribute__((used,at(0x10001208))) = 0xFFFFFF00; the code is OK, it means that my code is save , can not be readback anyway