From b79fc11a046e1c790c9d581ae846fae2bccc1453 Mon Sep 17 00:00:00 2001 From: mean Date: Sun, 13 Oct 2024 08:27:05 +0200 Subject: [PATCH] Add Jtag to Dormant sequence in case the target has both jtag and swd and is jtag by default --- src/target/adiv5_internal.h | 5 +++++ src/target/adiv5_swd.c | 11 +++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/target/adiv5_internal.h b/src/target/adiv5_internal.h index 8e82d74e9c0..153d7d6e1f5 100644 --- a/src/target/adiv5_internal.h +++ b/src/target/adiv5_internal.h @@ -44,6 +44,11 @@ #define ADIV5_SWD_TO_JTAG_SELECT_SEQUENCE 0xe73cU /* 16 bits, LSB (MSB: 0x3ce7) */ #define ADIV5_JTAG_TO_SWD_SELECT_SEQUENCE 0xe79eU /* 16 bits, LSB (MSB: 0x79e7) */ +/* ADIv5 JTAG to dormant sequence */ +#define ADIV5_JTAG_TO_DORMANT_SEQUENCE0 0x1fU /* 5 bits */ +#define ADIV5_JTAG_TO_DORMANT_SEQUENCE1 0x33bbbbbaU /* 31 bits, LSB (MSB : 0x2eeeeee6) */ +#define ADIV5_JTAG_TO_DORMANT_SEQUENCE2 0xffU /* 8 bits */ + /* * ADIv5 Selection Alert sequence * This sequence is sent MSB first and can be represented as either: diff --git a/src/target/adiv5_swd.c b/src/target/adiv5_swd.c index fc6979c8942..f63f5ed755b 100644 --- a/src/target/adiv5_swd.c +++ b/src/target/adiv5_swd.c @@ -75,11 +75,18 @@ static void dormant_to_swd_sequence(void) * ยง5.3.4 Switching out of Dormant state */ - DEBUG_INFO("Switching out of dormant state into SWD\n"); - /* Send at least 8 SWCLKTCK cycles with SWDIOTMS HIGH */ swd_line_reset_sequence(false); + + /* If the target is both Jtag and SWD with Jtag as default, switch Jtag->DS first. + * See B5.3.2 + */ + DEBUG_INFO("Switching from jtag do dormant \n"); + swd_proc.seq_out(ADIV5_JTAG_TO_DORMANT_SEQUENCE0, 5U); + swd_proc.seq_out(ADIV5_JTAG_TO_DORMANT_SEQUENCE1, 31U); + swd_proc.seq_out(ADIV5_JTAG_TO_DORMANT_SEQUENCE2, 8U); // not sure this one is needed /* Send the 128-bit Selection Alert sequence on SWDIOTMS */ + DEBUG_INFO("Switching out of dormant state into SWD\n"); swd_proc.seq_out(ADIV5_SELECTION_ALERT_SEQUENCE_0, 32U); swd_proc.seq_out(ADIV5_SELECTION_ALERT_SEQUENCE_1, 32U); swd_proc.seq_out(ADIV5_SELECTION_ALERT_SEQUENCE_2, 32U);