tcl/target: add rescue mode to RP2040 config
[openocd.git] / tcl / target / rp2040.cfg
index 0593e03bad273a9f1cd6229e855d03c53b5e4ed1..de76b4e29c33a8e8e0a79dd7792f8e1c2e1b8131 100644 (file)
@@ -26,6 +26,13 @@ if { [info exists CPUTAPID] } {
        set _CPUTAPID 0x01002927
 }
 
+# Set to '1' to start rescue mode
+if { [info exists RESCUE] } {
+       set _RESCUE $RESCUE
+} else {
+       set _RESCUE 0
+}
+
 # Set to '0' or '1' for single core configuration, 'SMP' for -rtos hwthread
 # handling of both cores, anything else for isolated debugging of both cores
 if { [info exists USE_CORE] } {
@@ -37,6 +44,29 @@ set _BOTH_CORES [expr { $_USE_CORE != 0 && $_USE_CORE != 1 }]
 
 swj_newdap $_CHIPNAME cpu -expected-id $_CPUTAPID
 
+# The rescue debug port uses the DP CTRL/STAT bit DBGPWRUPREQ to reset the
+# PSM (power on state machine) of the RP2040 with a flag set in the
+# VREG_AND_POR_CHIP_RESET register. Once the reset is released
+# (by clearing the DBGPWRUPREQ flag), the bootrom will run, see this flag,
+# and halt. Allowing the user to load some fresh code, rather than loading
+# the potentially broken code stored in flash
+if { $_RESCUE } {
+       dap create $_CHIPNAME.rescue_dap -chain-position $_CHIPNAME.cpu -dp-id $_CPUTAPID -instance-id 0xf -ignore-syspwrupack
+       init
+
+       # Clear DBGPWRUPREQ
+       $_CHIPNAME.rescue_dap dpreg 0x4 0x00000000
+
+       # Verifying CTRL/STAT is 0
+       set _CTRLSTAT [$_CHIPNAME.rescue_dap dpreg 0x4]
+       if {[expr {$_CTRLSTAT & 0xf0000000}]} {
+               echo "Rescue failed, DP CTRL/STAT readback $_CTRLSTAT"
+       } else {
+               echo "Now restart OpenOCD without RESCUE flag and load code to RP2040"
+       }
+       shutdown
+}
+
 # core 0
 if { $_USE_CORE != 1 } {
        dap create $_CHIPNAME.dap0 -chain-position $_CHIPNAME.cpu -dp-id $_CPUTAPID -instance-id 0

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)