This repository was archived by the owner on Mar 7, 2026. It is now read-only.
Feature: Restore lost JTAG-DP state across resets#2072
Open
ALTracer wants to merge 4 commits intoblackmagic-debug:mainfrom
Open
Feature: Restore lost JTAG-DP state across resets#2072ALTracer wants to merge 4 commits intoblackmagic-debug:mainfrom
ALTracer wants to merge 4 commits intoblackmagic-debug:mainfrom
Conversation
dragonmux
suggested changes
Feb 9, 2025
src/target/adiv5_swd.c
Outdated
| dp->low_access = adiv5_swd_raw_access; | ||
| dp->error = adiv5_swd_clear_error; | ||
| dp->abort = adiv5_swd_abort; | ||
| dp->ensure_idle = NULL; |
Member
There was a problem hiding this comment.
No need to assign here - calloc() ensures the struct is 0'd out anyway.
Contributor
Author
There was a problem hiding this comment.
Deleted. I thought it'd be important to always fill this field in case protocols are switched, but indeed it is freshly calloc'ed.
| uint32_t adiv5_jtag_raw_access(adiv5_debug_port_s *dp, uint8_t rnw, uint16_t addr, uint32_t value); | ||
| uint32_t adiv5_jtag_clear_error(adiv5_debug_port_s *dp, bool protocol_recovery); | ||
| void adiv5_jtag_abort(adiv5_debug_port_s *dp, uint32_t abort); | ||
| void adiv5_jtag_ensure_idle(adiv5_debug_port_s *dp); |
Member
There was a problem hiding this comment.
Given this is only used in adiv5_jtag.c, you can put this at the top of that file and mark it static.
Contributor
Author
There was a problem hiding this comment.
Deleted. Implementation moved.
* In some targets like AT32F403A, a nRST falling edge behaves like TRST. IR is loaded with IDCODE. Next transaction expects DPACC but gets a 8974008e:7. * Mangle internal JTAG IR cache to BYPASS state so that daisy-chaining works. For the active/attached target, BMD logic should run through Capture-IR. * Nothing is needed in SWD transport, so avoid calling a null pointer.
f642f1f to
a1ae913
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Detailed description
reset_config srst_pulls_trst.load/reset, as if nRST falling edge asserts TRST. Thus it's impossible to flash it, SWD is required (and it does protocol recovery).35-bit DPACC/APACC of 8974008e:7 (<<3, + 7) is 0x44ba00477, and 0x4ba00477 is JTAG-DP v0 IDCODE. So I assume IR gets loaded with IDCODE as if TAP is reset.
BMD has internal IR cache for all JTAG devices. If this device is selected, its IR should be changed to DPACC/APACC/ABORT for next access. If another device is selected but this target was reset by a shared nRST network, then IR should be changed to BYPASS for daisy-chain operation to continue.
A new function,
adiv5_jtag_ensure_idle(), is added to struct debug_port, and NULL-checked to not break SWD transport.This is tested on BMDA+blackpill-f411ce and at32f403acgu7 to fix flash loading.
TODO: BMDA CMSIS-DAP backend for JTAG sequences?
Your checklist for this pull request
Closing issues