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

how to program the code in software to enable flash read protection

config flash read  protection in code 

Parents
  • 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 

Reply Children
No Data
Related