nrf53 network core remains secured

Hi all, 

II'm attempting to get the nRF5340 working with my firmware, but I'm encountering a problem that I can't understand. I can program and boot the app core without any issue.
The app firmware is calling nrf53_handle_approtect with ENABLE_APPROTECT_USER_HANDLING and ENABLE_SECURE_APPROTECT_USER_HANDLING defined. The code then looks like this:

static inline void nrf53_handle_approtect(void)
{
    #if defined(NRF_APPLICATION)
        #if defined (ENABLE_APPROTECT)
            /* Prevent processor from unlocking APPROTECT soft branch after this point. */
            NRF_CTRLAP_S->APPROTECT.LOCK = CTRLAPPERI_APPROTECT_LOCK_LOCK_Locked;

        #elif  defined (ENABLE_APPROTECT_USER_HANDLING)
                /* Do nothing, allow user code to handle APPROTECT. Use this if you want to enable authenticated debug. */
            NRF_CTRLAP_S->APPROTECT.DISABLE = 0x50FA50FA;
        #else
            /* Load APPROTECT soft branch from UICR.
               If UICR->APPROTECT is disabled, CTRLAP->APPROTECT will be disabled. */
            NRF_CTRLAP_S->APPROTECT.DISABLE = NRF_UICR_S->APPROTECT;
        #endif

        /* Secure APPROTECT is only available for Application core. */
        #if defined (ENABLE_SECURE_APPROTECT)
            /* Prevent processor from unlocking SECURE APPROTECT soft branch after this point. */
            NRF_CTRLAP_S->SECUREAPPROTECT.LOCK = CTRLAPPERI_SECUREAPPROTECT_LOCK_LOCK_Locked;

        #elif  defined (ENABLE_SECURE_APPROTECT_USER_HANDLING)
            /* Do nothing, allow user code to handle SECURE APPROTECT. Use this if you want to enable authenticated debug. */
            NRF_CTRLAP_S->SECUREAPPROTECT.DISABLE = 0x50FA50FA;
        #else
            /* Load SECURE APPROTECT soft branch from UICR.
               If UICR->SECUREAPPROTECT is disabled, CTRLAP->SECUREAPPROTECT will be disabled. */
            NRF_CTRLAP_S->SECUREAPPROTECT.DISABLE = NRF_UICR_S->SECUREAPPROTECT;
        #endif
    #endif
    #if defined(NRF_NETWORK)
        #if defined (ENABLE_APPROTECT)
            /* Prevent processor from unlocking APPROTECT soft branch after this point. */
            NRF_CTRLAP_NS->APPROTECT.LOCK = CTRLAPPERI_APPROTECT_LOCK_LOCK_Locked;

        #elif  defined (ENABLE_APPROTECT_USER_HANDLING)
                /* Do nothing, allow user code to handle APPROTECT. Use this if you want to enable authenticated debug. */
            NRF_CTRLAP_NS->APPROTECT.DISABLE = 0x50FA50FA;
        #else
            /* Load APPROTECT soft branch from UICR.
               If UICR->APPROTECT is disabled, CTRLAP->APPROTECT will be disabled. */
            NRF_CTRLAP_NS->APPROTECT.DISABLE = NRF_UICR_NS->APPROTECT;
        #endif
    #endif
}

Then when I flash the network core with custom firmware, JLink prompts this message:

Device "NRF5340_XXAA_NET" selected.


Connecting to target via SWD
ConfigTargetSettings() start
ConfigTargetSettings() end - Took 5us
InitTarget() start
CTRL-AP indicates that the device is secured.
For debugger connection the device needs to be unsecured.
Note: Unsecuring will trigger a mass erase of the internal flash, SRAM and UICR of both the application and the network core.

Executing default behavior previously saved in the registry.
Device will be unsecured now.
InitTarget() end - Took 762ms
Found SW-DP with ID 0x6BA02477

The firmware running on the network core is also calling nrf53_handle_approtect. However every time I want to flash a new network core image Jlink erase the full flash. I don't get what I'm missing,  is there anything else I'd need to do to disable appprotect?

Thanks for your help,
Jocelyn

Related