This is an automated email from Gerrit. "Tomas Vanek <van...@fbl.cz>" just uploaded a new patch set to Gerrit, which you can find at https://review.openocd.org/c/openocd/+/8113
-- gerrit commit 63ff7d49e8311e371e8e4d959734e91dcb9cf0ff Author: Tomas Vanek <van...@fbl.cz> Date: Mon Jan 22 15:33:47 2024 +0100 tcl/target: add nRF53 config file TODO: dbg attach event to switch on and examine network core Change-Id: I08f88ff48ff7ac592e9214b89ca8e5e9428573a5 Signed-off-by: Tomas Vanek <van...@fbl.cz> diff --git a/tcl/target/nrf53.cfg b/tcl/target/nrf53.cfg new file mode 100644 index 0000000000..35785aa619 --- /dev/null +++ b/tcl/target/nrf53.cfg @@ -0,0 +1,150 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +# +# Nordic nRF53 series: dual ARM Cortex-M33 +# + +source [find target/swj-dp.tcl] +source [find mem_helper.tcl] + +if { [info exists CHIPNAME] } { + set _CHIPNAME $CHIPNAME +} else { + set _CHIPNAME nrf53 +} + +# Work-area is a space in RAM used for flash programming +# By default use 16kB +if { [info exists WORKAREASIZE] } { + set _WORKAREASIZE $WORKAREASIZE +} else { + set _WORKAREASIZE 0x4000 +} + +if { [info exists CPUTAPID] } { + set _CPUTAPID $CPUTAPID +} else { + set _CPUTAPID 0x6ba02477 +} + +swj_newdap $_CHIPNAME cpu -expected-id $_CPUTAPID +dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu + +set _TARGETNAME_APP $_CHIPNAME.appcore +set _TARGETNAME_NET $_CHIPNAME.netcore +target create $_TARGETNAME_APP cortex_m -dap $_CHIPNAME.dap +target create $_TARGETNAME_NET cortex_m -dap $_CHIPNAME.dap -ap-num 1 -defer-examine + +targets $_TARGETNAME_APP + +adapter speed 1000 + +$_TARGETNAME_APP configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0 +$_TARGETNAME_NET configure -work-area-phys 0x21000000 -work-area-size $_WORKAREASIZE -work-area-backup 0 + +# System reset sets NETWORK.FORCEOFF which keeps the network core in reset +# Don't touch network core during reset +$_TARGETNAME_NET configure -event reset-assert {} +$_TARGETNAME_APP configure -event reset-init "nrf53_netcore_release $_CHIPNAME" + +if { [using_hla] } { + echo "" + echo "nRF53 device has a CTRL-AP dedicated to recover the device from AP lock." + echo "A high level adapter (like a ST-Link) you are currently using cannot access" + echo "the CTRL-AP so 'nrf53_recover' command will not work." + echo "Do not enable UICR APPROTECT." + echo "" +} else { + $_TARGETNAME_APP cortex_m reset_config sysresetreq + $_TARGETNAME_NET cortex_m reset_config sysresetreq + + $_TARGETNAME_APP configure -event examine-fail "nrf53_check_ap_lock 2" + $_TARGETNAME_NET configure -event examine-fail "nrf53_check_ap_lock 3" +} + +flash bank $_CHIPNAME.app.flash nrf5 0x00000000 0 0 0 $_TARGETNAME_APP +flash bank $_CHIPNAME.net.flash nrf5 0x01000000 0 0 0 $_TARGETNAME_NET +flash bank $_CHIPNAME.app.uicr nrf5 0x00FF8000 0 0 0 $_TARGETNAME_APP +flash bank $_CHIPNAME.net.uicr nrf5 0x01FF8000 0 0 0 $_TARGETNAME_NET + +# Release the network core +proc nrf53_netcore_release { _CHIPNAME } { + set _TARGETNAME_APP $_CHIPNAME.appcore + set _TARGETNAME_NET $_CHIPNAME.netcore + set RESET_NETWORK_FORCEOFF 0x50005614 + set RESET_NETWORK_WORKAROUND 0x50005618 + set CORTEX_M_DCB_DEMCR 0xE000EDFC + $_TARGETNAME_APP mww $RESET_NETWORK_WORKAROUND 1 + $_TARGETNAME_APP mww $RESET_NETWORK_FORCEOFF 0 + $_TARGETNAME_APP mww $RESET_NETWORK_FORCEOFF 1 + $_TARGETNAME_NET arp_examine + # set TRCENA | VC_HARDERR | VC_BUSERR | VC_CORERESET + $_TARGETNAME_NET mww $CORTEX_M_DCB_DEMCR 0x01000501 + # Write DEMCR directly intead of permanetly setting by cortex_m vector_catch reset + # following cortex_m_endreset_event() restores the original DEMCR value + $_TARGETNAME_APP mww $RESET_NETWORK_FORCEOFF 0 + $_TARGETNAME_APP mww $RESET_NETWORK_WORKAROUND 0 +} + +# Test if MEM-AP is locked by UICR APPROTECT +proc nrf53_check_ap_lock { apnum } { + set dap [[target current] cget -dap] + set err [catch {set APPROTECTSTATUS [$dap apreg $apnum 0xc]}] + if {$err == 0 && $APPROTECTSTATUS != 1} { + echo "****** WARNING ******" + echo "nRF53 device has AP lock engaged (see UICR APPROTECT register)." + echo "Debug access is denied." + echo "Use 'nrf53_recover' to erase and unlock the device." + echo "" + poll off + } +} + +# Mass erase and unlock the device using proprietary nRF CTRL-AP (AP #2 or #3) +proc nrf53_recover { apnum } { + set target [target current] + set dap [$target cget -dap] + + set IDR [$dap apreg $apnum 0xfc] + if {$IDR != 0x12880000} { + echo "Error: Cannot access nRF53 CTRL-AP!" + return + } + + poll off + + # Reset and trigger ERASEALL task + $dap apreg $apnum 4 0 + $dap apreg $apnum 4 1 + + for {set i 0} {1} {incr i} { + set ERASEALLSTATUS [$dap apreg $apnum 8] + if {$ERASEALLSTATUS == 0} { + echo "$target device has been successfully erased and unlocked." + break + } + if {$i == 0} { + echo "Waiting for chip erase..." + } + if {$i >= 150} { + echo "Error: $target recovery failed." + break + } + sleep 100 + } + + # Assert reset + $dap apreg $apnum 0 1 + + # Deassert reset + $dap apreg $apnum 0 0 + + # Reset ERASEALL task + $dap apreg $apnum 4 0 + + sleep 100 + $target arp_examine + poll on +} + +add_help_text nrf53_recover "Mass erase and unlock nRF53 device" --