/* Use SWD */

SWDSelect

/* Power on debug interface by setting CSYSPWRUPREQ bits */ 
/* https://developer.arm.com/documentation/ihi0031/a/Debug-Port-Registers/Debug-Port--DP--register-descriptions/The-Control-Status-Register--CTRL-STAT */

SWDWriteDP 1 0x50000000

/* Select CTRL-AP (APSEL = 2) */
/* https://developer.arm.com/documentation/ihi0031/a/Debug-Port-Registers/Debug-Port--DP--register-descriptions/The-AP-Select-Register--SELECT
/* https://docs.nordicsemi.com/bundle/nan_047/page/APP/nan_production_programming/nRF54L/nrf54l_select_access_port.html */

SWDWriteDP 2 0x2000000 

/* Write 1 (Erase) to the CTRLAP.ERASEALL register (0x004). */
/* https://docs.nordicsemi.com/bundle/ps_nrf54L15/page/ctrl-ap.html#ariaid-title8 */ 

SWDWriteAP 1 0x00000001

/* Wait for ERASEALL to complete */
/* CTRLAP.ERASEALLSTATUS */

sleep 1000
SWDReadAP 2
sleep 1000
SWDReadAP 2
sleep 1000
SWDReadAP 2

/* HardReset */

SWDWriteAP 0 0x2

/* Release the RESET register value */ 

SWDWriteAP 0 0x0