How to disable APPROTECT permanently? DFU is needed

Hi,

I have been using nrf52840 chip for a while and now the new revision of the chip has APPROTECT feature that locks the writing until nrfjprog --recover is run and the whole chip is erased. This is my chip revision

I am using S340 (ANT_s340_nrf52840_6.1.1.hex)

I followed the instruction to disable APPROTECT using this code and called it in main function

void approtect_hw_disable(void)
{
    if ((NRF_UICR->APPROTECT & UICR_APPROTECT_PALL_Msk) 
       == (UICR_APPROTECT_PALL_Msk))
    {
        NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos;
        while (NRF_NVMC->READY == NVMC_READY_READY_Busy) {}
        NRF_UICR->APPROTECT = (UICR_APPROTECT_PALL_HwDisabled << UICR_APPROTECT_PALL_Pos);
        while (NRF_NVMC->READY == NVMC_READY_READY_Busy) {}
        NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos;
        while (NRF_NVMC->READY == NVMC_READY_READY_Busy) {}
        NVIC_SystemReset();
    }  
}

The chip is unlock but if I do a reset or power cycle, the chip will be locked again. 

I want to ask if there is a way to permanently disable APPROTECT feature,, which mean it will work as old revision chips.

Edit:

Problem solved! I must use the latest MDK (8.44.1) and recompile everything. I hope this will help others who looking for a solution!

Thank you so much!

Related