From a5a9121ad66b2d2ead1c3d44a7d10a19d9e98fac Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Fri, 30 Jan 2026 09:37:47 +0100 Subject: [PATCH] target: stm32mpxxx: fix return to SWD after reset A target reset can cause a power cycle, causing the DAP to switch from SWD to JTAG. The adapter can loose the connection because it keeps using SWD, triggering error messages. While some ST-Link FW can automatically reconnect the lost SWD connection, this is not possible with older FW nor with other adapters. Force a DAP initialization after reset to eventually switch it back to SWD. Change-Id: I29ea49d2d5ee013ad33371265fd6996353f391d6 Signed-off-by: Antonio Borneo Reviewed-on: https://review.openocd.org/c/openocd/+/9462 Tested-by: jenkins --- tcl/target/st/stm32mp13x.cfg | 2 ++ tcl/target/st/stm32mp15x.cfg | 2 ++ tcl/target/st/stm32mp21x.cfg | 2 ++ tcl/target/st/stm32mp23x.cfg | 3 ++- tcl/target/st/stm32mp25x.cfg | 3 ++- 5 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tcl/target/st/stm32mp13x.cfg b/tcl/target/st/stm32mp13x.cfg index 164e0ff1f..acd2ce0ed 100644 --- a/tcl/target/st/stm32mp13x.cfg +++ b/tcl/target/st/stm32mp13x.cfg @@ -119,6 +119,8 @@ $_CHIPNAME.ap1 configure -event reset-assert-post { $_CHIPNAME.ap1 configure -event reset-deassert-pre { adapter deassert srst deassert trst + catch {dap init} + catch {$::_CHIPNAME.dap apid 1} $::_CHIPNAME.ap1 arp_examine _handshake_with_wrapper $halt _enable_debug diff --git a/tcl/target/st/stm32mp15x.cfg b/tcl/target/st/stm32mp15x.cfg index 979a5a491..3d7225271 100644 --- a/tcl/target/st/stm32mp15x.cfg +++ b/tcl/target/st/stm32mp15x.cfg @@ -175,6 +175,8 @@ $_CHIPNAME.ap1 configure -event reset-assert-post { $_CHIPNAME.ap1 configure -event reset-deassert-pre { adapter deassert srst deassert trst + catch {dap init} + catch {$::_CHIPNAME.dap apid 1} $::_CHIPNAME.ap1 arp_examine _handshake_with_wrapper $halt if { $::EN_CA7_0 } { diff --git a/tcl/target/st/stm32mp21x.cfg b/tcl/target/st/stm32mp21x.cfg index f4073a9f5..9a102c6d9 100644 --- a/tcl/target/st/stm32mp21x.cfg +++ b/tcl/target/st/stm32mp21x.cfg @@ -182,6 +182,8 @@ $_CHIPNAME.axi configure -event reset-assert-post { $_CHIPNAME.axi configure -event reset-deassert-pre { adapter deassert srst deassert trst + catch {dap init} + catch {$::_CHIPNAME.dap apid 0} $::_CHIPNAME.axi arp_examine set is_dev_boot [_enable_dbgmcu_on_devboot] if { !$is_dev_boot } { diff --git a/tcl/target/st/stm32mp23x.cfg b/tcl/target/st/stm32mp23x.cfg index 015f816e4..7ca1830e3 100644 --- a/tcl/target/st/stm32mp23x.cfg +++ b/tcl/target/st/stm32mp23x.cfg @@ -171,7 +171,8 @@ $_CHIPNAME.axi configure -event reset-assert-post { $_CHIPNAME.axi configure -event reset-deassert-pre { adapter deassert srst deassert trst - + catch {dap init} + catch {$::_CHIPNAME.dap apid 0} $::_CHIPNAME.ap0 arp_examine _handshake_with_wrapper $halt diff --git a/tcl/target/st/stm32mp25x.cfg b/tcl/target/st/stm32mp25x.cfg index 6807d64a1..92410c7b5 100644 --- a/tcl/target/st/stm32mp25x.cfg +++ b/tcl/target/st/stm32mp25x.cfg @@ -191,7 +191,8 @@ $_CHIPNAME.axi configure -event reset-assert-post { $_CHIPNAME.axi configure -event reset-deassert-pre { adapter deassert srst deassert trst - + catch {dap init} + catch {$::_CHIPNAME.dap apid 0} $::_CHIPNAME.ap0 arp_examine _handshake_with_wrapper $halt