Read back protection after DFU

How to enable Read back protection in nrf52832 and in nrf52840 after DFU completed.

i have tried using --rbp all its working but i want to do in code(any register or by setting any flag).

Parents
  • Hi,

    Are you using devices with the improved AP protection mechanism (revision 3), or older devices with the old APPROTECT mechanism?

    If using rev 1 or rev 2 devices read back protection is disabled by default and the only way to control this is via UICR->APPROTECT. That can be written to programmatically, for instance using this code snippet:

    if ((NRF_UICR->APPROTECT & UICR_APPROTECT_PALL_Msk) != UICR_APPROTECT_PALL_Enabled)
    {
        nvmc_config(NVMC_CONFIG_WEN_Wen);
        NRF_UICR->APPROTECT = UICR_APPROTECT_PALL_Enabled;
        nvmc_wait();
        nvmc_config(NVMC_CONFIG_WEN_Ren);
        NVIC_SystemReset();
    }
    

    Here UICR->APPROTECT is checked, and if APPROTECT is not enabled (by the value being 0x00) it is enabled. Note that the soft reset is required as this only take effect on the next reset. This register is in UICR so it is persistent and so this only happens once.

    Revision 3 devices has an improved APPROTECT mechanism which is enabled by default. If it has previously been disabled (by UICR->APPROTECT being set to 0x5A and firmware that writes to NRF_APPROTECT->DISABLE) you can re-enable protection by using the same code snippet as above. You should also build your firmware with ENABLE_APPROTECT defined (assuming you use SDK 17.1.0 which has an updated MDK with support for revision 3 devices) so that it writes to NRF_APPROTECT->FORCEPROTECT.

Reply
  • Hi,

    Are you using devices with the improved AP protection mechanism (revision 3), or older devices with the old APPROTECT mechanism?

    If using rev 1 or rev 2 devices read back protection is disabled by default and the only way to control this is via UICR->APPROTECT. That can be written to programmatically, for instance using this code snippet:

    if ((NRF_UICR->APPROTECT & UICR_APPROTECT_PALL_Msk) != UICR_APPROTECT_PALL_Enabled)
    {
        nvmc_config(NVMC_CONFIG_WEN_Wen);
        NRF_UICR->APPROTECT = UICR_APPROTECT_PALL_Enabled;
        nvmc_wait();
        nvmc_config(NVMC_CONFIG_WEN_Ren);
        NVIC_SystemReset();
    }
    

    Here UICR->APPROTECT is checked, and if APPROTECT is not enabled (by the value being 0x00) it is enabled. Note that the soft reset is required as this only take effect on the next reset. This register is in UICR so it is persistent and so this only happens once.

    Revision 3 devices has an improved APPROTECT mechanism which is enabled by default. If it has previously been disabled (by UICR->APPROTECT being set to 0x5A and firmware that writes to NRF_APPROTECT->DISABLE) you can re-enable protection by using the same code snippet as above. You should also build your firmware with ENABLE_APPROTECT defined (assuming you use SDK 17.1.0 which has an updated MDK with support for revision 3 devices) so that it writes to NRF_APPROTECT->FORCEPROTECT.

Children
No Data
Related