This is an automated email from Gerrit.

"Antonio Borneo <[email protected]>" just uploaded a new patch set to 
Gerrit, which you can find at https://review.openocd.org/c/openocd/+/6695

-- gerrit

commit db1e841092bfdc1104e6924ec1633110c28ec78f
Author: Antonio Borneo <[email protected]>
Date:   Thu Nov 11 23:28:33 2021 +0100

    adi_v5_swd: add jtag-to-swd through dormant
    
    ARM IHI 0031A does not support SWJ-DP, so no switch between JTAG
    and SWD.
    ARM IHI 0031B is not publicly available ans it's reported as
    "Confidential Beta" in the history list in following doc versions.
    From ARM IHI 0031C the direct switch between JTAG and SWD is
    already deprecated in favor of passing through dormant mode. With
    no access to IHI 0031B we haven't info if any device strictly
    requires the direct switch.
    
    OpenOCD implements only the deprecated direct switch, so changing
    it could cause regression on devices that do not implement dormant
    mode.
    Plus, not all the adapters support dormant mode.
    
    Nevertheless there are already target devices that only allow
    entering in SWD by passing through dormant.
    
    Let the code try both method, alternating one tentative with the
    deprecated legacy direct switch, then another tentative passing
    through dormant, and repeat till timeout.
    This would work on any device that don't support dormant, on new
    devices that require switch through dormant and will work with
    adapters that don't support dormant.
    
    Change-Id: Ib8619635277d497872079a33fa4e38be9beb84a0
    Signed-off-by: Antonio Borneo <[email protected]>

diff --git a/src/target/adi_v5_swd.c b/src/target/adi_v5_swd.c
index 9e6ed1b16..5d23e9dc8 100644
--- a/src/target/adi_v5_swd.c
+++ b/src/target/adi_v5_swd.c
@@ -121,8 +121,14 @@ static int swd_connect(struct adiv5_dap *dap)
 
        int64_t timeout = timeval_ms() + 500;
 
+       dap->jtag_to_swd_through_dormant = false;
        do {
-               swd->switch_seq(JTAG_TO_SWD);
+               if (dap->jtag_to_swd_through_dormant) {
+                       swd->switch_seq(JTAG_TO_DORMANT);
+                       swd->switch_seq(DORMANT_TO_SWD);
+               } else {
+                       swd->switch_seq(JTAG_TO_SWD);
+               }
 
                /* Clear link state, including the SELECT cache. */
                dap->do_reconnect = false;
@@ -137,6 +143,7 @@ static int swd_connect(struct adiv5_dap *dap)
 
                alive_sleep(1);
 
+               dap->jtag_to_swd_through_dormant = 
!dap->jtag_to_swd_through_dormant;
        } while (timeval_ms() < timeout);
 
        if (status != ERROR_OK) {
@@ -379,7 +386,13 @@ static void swd_quit(struct adiv5_dap *dap)
 {
        const struct swd_driver *swd = adiv5_dap_swd_driver(dap);
 
-       swd->switch_seq(SWD_TO_JTAG);
+       if (dap->jtag_to_swd_through_dormant) {
+               swd->switch_seq(SWD_TO_DORMANT);
+               swd->switch_seq(DORMANT_TO_JTAG);
+       } else {
+               swd->switch_seq(SWD_TO_JTAG);
+       }
+
        /* flush the queue before exit */
        swd->run();
 }
diff --git a/src/target/arm_adi_v5.h b/src/target/arm_adi_v5.h
index 7ef2f782c..0f0061b74 100644
--- a/src/target/arm_adi_v5.h
+++ b/src/target/arm_adi_v5.h
@@ -379,6 +379,11 @@ struct adiv5_dap {
 
        /* ADIv6 only field indicating ROM Table address size */
        unsigned int asize;
+
+       /**
+        * Record if enter in SWD required passing through DORMANT
+        */
+       bool jtag_to_swd_through_dormant;
 };
 
 /**

-- 

Reply via email to