This is an automated email from Gerrit.

Tomas Vanek ([email protected]) just uploaded a new patch set to Gerrit, which you 
can find at http://openocd.zylin.com/5845

-- gerrit

commit 3cec74e731f2fbfe337a868f8257cad2a7c0af8b
Author: Tomas Vanek <[email protected]>
Date:   Thu Oct 1 12:36:00 2020 +0200

    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 <[email protected]>
    Reported-by: Pieter De Gendt <[email protected]>

diff --git a/tcl/target/nrf52.cfg b/tcl/target/nrf52.cfg
index 88f2c69..d0c52fd 100644
--- a/tcl/target/nrf52.cfg
+++ b/tcl/target/nrf52.cfg
@@ -53,7 +53,7 @@ flash bank $_CHIPNAME.uicr nrf5 0x10001000 0 1 1 $_TARGETNAME
 # Test if MEM-AP is locked by UICR APPROTECT
 proc nrf52_check_ap_lock {} {
        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} {
                echo "****** WARNING ******"
                echo "nRF52 device has AP lock engaged (see UICR APPROTECT 
register)."
@@ -71,7 +71,7 @@ proc nrf52_recover {} {
        set target [target current]
        set dap [$target cget -dap]
 
-       set IDR [ocd_$dap apreg 1 0xfc]
+       set IDR [$dap apreg 1 0xfc]
        if {$IDR != 0x02880000} {
                echo "Error: Cannot access nRF52 CTRL-AP!"
                return
@@ -79,37 +79,38 @@ proc nrf52_recover {} {
 
        poll off
 
-       # Assert reset
-       $dap apreg 1 0 1
-
-       # Reset ERASEALLSTATUS event
-       $dap apreg 1 8 0
-
-       # Trigger ERASEALL task
+       # Reset and trigger ERASEALL task
        $dap apreg 1 4 0
        $dap apreg 1 4 1
 
        for {set i 0} {1} {incr i} {
-               set ERASEALLSTATUS [ocd_$dap apreg 1 8]
-               if {$ERASEALLSTATUS == 1} {
+               set ERASEALLSTATUS [$dap apreg 1 8]
+               if {$ERASEALLSTATUS == 0} {
                        echo "$target device has been successfully erased and 
unlocked."
                        break
                }
-               if {$i >= 5} {
+               if {$i == 0} {
+                       echo "Waiting for chip erase..."
+               }
+               if {$i >= 150} {
                        echo "Error: $target recovery failed."
                        break
                }
                sleep 100
        }
 
+       # Assert reset
+       $dap apreg 1 0 1
+
        # Deassert reset
        $dap apreg 1 0 0
 
-       if {$ERASEALLSTATUS == 1} {
-               sleep 100
-               $target arp_examine
-               poll on
-       }
+       # Reset ERASEALL task
+       $dap apreg 1 4 0
+
+       sleep 100
+       $target arp_examine
+       poll on
 }
 
 add_help_text nrf52_recover "Mass erase and unlock nRF52 device"

-- 


_______________________________________________
OpenOCD-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to