tcl/target/nrf52: fix nrf52_recover
nrf52_recover was merged in pre "Handle Tcl return values consistently" state - remove ocd_ prefixes. Erase and unlock sequence was changed to comply Nordic semiconductor recommendation: https://infocenter.nordicsemi.com/index.jsp?topic=%2Fnwp_027%2FWP%2Fnwp_027%2FnWP_027_erasing.html Change-Id: Ic54236c27cf25ad8091e9e572ba1ef846f0d47c2 Signed-off-by: Tomas Vanek <vanekt@fbl.cz> Reported-by: Pieter De Gendt <pieter.degendt@gmail.com> Reviewed-on: http://openocd.zylin.com/5845 Tested-by: jenkins Reviewed-by: Pieter De Gendt <pieter.degendt@gmail.com>
This commit is contained in:
parent
5e61d59c90
commit
6436f1919c
|
@ -53,7 +53,7 @@ flash bank $_CHIPNAME.uicr nrf5 0x10001000 0 1 1 $_TARGETNAME
|
||||||
# Test if MEM-AP is locked by UICR APPROTECT
|
# Test if MEM-AP is locked by UICR APPROTECT
|
||||||
proc nrf52_check_ap_lock {} {
|
proc nrf52_check_ap_lock {} {
|
||||||
set dap [[target current] cget -dap]
|
set dap [[target current] cget -dap]
|
||||||
set err [catch {set APPROTECTSTATUS [ocd_$dap apreg 1 0xc]}]
|
set err [catch {set APPROTECTSTATUS [$dap apreg 1 0xc]}]
|
||||||
if {$err == 0 && $APPROTECTSTATUS != 1} {
|
if {$err == 0 && $APPROTECTSTATUS != 1} {
|
||||||
echo "****** WARNING ******"
|
echo "****** WARNING ******"
|
||||||
echo "nRF52 device has AP lock engaged (see UICR APPROTECT register)."
|
echo "nRF52 device has AP lock engaged (see UICR APPROTECT register)."
|
||||||
|
@ -71,7 +71,7 @@ proc nrf52_recover {} {
|
||||||
set target [target current]
|
set target [target current]
|
||||||
set dap [$target cget -dap]
|
set dap [$target cget -dap]
|
||||||
|
|
||||||
set IDR [ocd_$dap apreg 1 0xfc]
|
set IDR [$dap apreg 1 0xfc]
|
||||||
if {$IDR != 0x02880000} {
|
if {$IDR != 0x02880000} {
|
||||||
echo "Error: Cannot access nRF52 CTRL-AP!"
|
echo "Error: Cannot access nRF52 CTRL-AP!"
|
||||||
return
|
return
|
||||||
|
@ -79,37 +79,38 @@ proc nrf52_recover {} {
|
||||||
|
|
||||||
poll off
|
poll off
|
||||||
|
|
||||||
# Assert reset
|
# Reset and trigger ERASEALL task
|
||||||
$dap apreg 1 0 1
|
|
||||||
|
|
||||||
# Reset ERASEALLSTATUS event
|
|
||||||
$dap apreg 1 8 0
|
|
||||||
|
|
||||||
# Trigger ERASEALL task
|
|
||||||
$dap apreg 1 4 0
|
$dap apreg 1 4 0
|
||||||
$dap apreg 1 4 1
|
$dap apreg 1 4 1
|
||||||
|
|
||||||
for {set i 0} {1} {incr i} {
|
for {set i 0} {1} {incr i} {
|
||||||
set ERASEALLSTATUS [ocd_$dap apreg 1 8]
|
set ERASEALLSTATUS [$dap apreg 1 8]
|
||||||
if {$ERASEALLSTATUS == 1} {
|
if {$ERASEALLSTATUS == 0} {
|
||||||
echo "$target device has been successfully erased and unlocked."
|
echo "$target device has been successfully erased and unlocked."
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if {$i >= 5} {
|
if {$i == 0} {
|
||||||
|
echo "Waiting for chip erase..."
|
||||||
|
}
|
||||||
|
if {$i >= 150} {
|
||||||
echo "Error: $target recovery failed."
|
echo "Error: $target recovery failed."
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
sleep 100
|
sleep 100
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Assert reset
|
||||||
|
$dap apreg 1 0 1
|
||||||
|
|
||||||
# Deassert reset
|
# Deassert reset
|
||||||
$dap apreg 1 0 0
|
$dap apreg 1 0 0
|
||||||
|
|
||||||
if {$ERASEALLSTATUS == 1} {
|
# Reset ERASEALL task
|
||||||
sleep 100
|
$dap apreg 1 4 0
|
||||||
$target arp_examine
|
|
||||||
poll on
|
sleep 100
|
||||||
}
|
$target arp_examine
|
||||||
|
poll on
|
||||||
}
|
}
|
||||||
|
|
||||||
add_help_text nrf52_recover "Mass erase and unlock nRF52 device"
|
add_help_text nrf52_recover "Mass erase and unlock nRF52 device"
|
||||||
|
|
Loading…
Reference in New Issue