diff --git a/src/target/adiv5.c b/src/target/adiv5.c index 83bcb4e..dd7afef 100644 --- a/src/target/adiv5.c +++ b/src/target/adiv5.c @@ -739,9 +739,10 @@ void adiv5_dp_init(ADIv5_DP_t *dp, const uint32_t idcode) DEBUG_WARN("DPv0 detected based on JTAG IDCode\n"); if (dp->version >= 2) { - adiv5_dp_write(dp, ADIV5_DP_SELECT, 2); /* TARGETID is on bank 2 */ + /* TARGETID is on bank 2 */ + adiv5_dp_write(dp, ADIV5_DP_SELECT, ADIV5_DP_BANK2); const uint32_t targetid = adiv5_dp_read(dp, ADIV5_DP_TARGETID); - adiv5_dp_write(dp, ADIV5_DP_SELECT, 0); + adiv5_dp_write(dp, ADIV5_DP_SELECT, ADIV5_DP_BANK0); /* Use TARGETID register to identify target */ const uint16_t tdesigner = (targetid & ADIV5_DP_TARGETID_TDESIGNER_MASK) >> ADIV5_DP_TARGETID_TDESIGNER_OFFSET; diff --git a/src/target/adiv5.h b/src/target/adiv5.h index b783c4b..04d9e83 100644 --- a/src/target/adiv5.h +++ b/src/target/adiv5.h @@ -31,12 +31,6 @@ #define ADIV5_DP_REG(x) (x) #define ADIV5_AP_REG(x) (ADIV5_APnDP | (x)) -#define ADIV5_DP_BANK0 0x00U -#define ADIV5_DP_BANK1 0x10U -#define ADIV5_DP_BANK2 0x20U -#define ADIV5_DP_BANK3 0x30U -#define ADIV5_DP_BANK4 0x40U - /* ADIv5 DP Register addresses */ #define ADIV5_DP_DPIDR ADIV5_DP_REG(0x0U) #define ADIV5_DP_ABORT ADIV5_DP_REG(0x0U) @@ -60,6 +54,13 @@ #define ADIV5_DP_DPIDR_DESIGNER_OFFSET 1U #define ADIV5_DP_DPIDR_DESIGNER_MASK (0x7ffU << ADIV5_DP_DPIDR_DESIGNER_OFFSET) +/* DP SELECT register DP bank numbers */ +#define ADIV5_DP_BANK0 0U +#define ADIV5_DP_BANK1 1U +#define ADIV5_DP_BANK2 2U +#define ADIV5_DP_BANK3 3U +#define ADIV5_DP_BANK4 4U + /* DP TARGETID */ #define ADIV5_DP_TARGETID_TREVISION_OFFSET 28U #define ADIV5_DP_TARGETID_TREVISION_MASK (0xfU << ADIV5_DP_TARGETID_TREVISION_OFFSET) diff --git a/src/target/adiv5_swdp.c b/src/target/adiv5_swdp.c index afc86b3..21f4024 100644 --- a/src/target/adiv5_swdp.c +++ b/src/target/adiv5_swdp.c @@ -140,10 +140,11 @@ uint32_t adiv5_swdp_scan(uint32_t targetid) if (dp_version >= 2) { scan_multidrop = true; - /* Read TargetID. Can be done with device in WFI, sleep or reset!*/ - adiv5_dp_write(initial_dp, ADIV5_DP_SELECT, 2); /* TARGETID is on bank 2 */ + /* Read TargetID. Can be done with device in WFI, sleep or reset! */ + /* TARGETID is on bank 2 */ + adiv5_dp_write(initial_dp, ADIV5_DP_SELECT, ADIV5_DP_BANK2); dp_targetid = adiv5_dp_read(initial_dp, ADIV5_DP_TARGETID); - adiv5_dp_write(initial_dp, ADIV5_DP_SELECT, 0); + adiv5_dp_write(initial_dp, ADIV5_DP_SELECT, ADIV5_DP_BANK0); const uint16_t tdesigner = (dp_targetid & ADIV5_DP_TARGETID_TDESIGNER_MASK) >> ADIV5_DP_TARGETID_TDESIGNER_OFFSET;