7
31
Fork
You've already forked blackmagic
23

Feature: implementation of jtagtap_cycle for JLink backend #2182

Merged
ALTracer merged 3 commits from feature/jtagtap_cycle_jlink into main 2026年02月06日 19:08:58 +01:00
ALTracer commented 2026年01月29日 19:22:55 +01:00 (Migrated from github.com)
Copy link

Detailed description

  • This is a minor new feature.
  • The problem is rudimentary/poor implementation of jtagtap_cycle() in jlink.c backend used by BMDA. (and it didn't even exist until very recently)
  • This PR solves it by providing one moderately optimized variant.

Tracking: #2180.
Note that jlink_jtag_init() used to rely on a direct jlink_transfer() of a baked byte buffer with 56 idle clocks and SWD-to-JTAG switch sequence, I replaced that with a jlink_jtag_cycle() call for 56-5=51 clocks and a shorter, 16-bit sequence. The caveat is that new function may raise an exception, and at scan time it results in immediate SIGABRT because it's unhandled (by any TRY-CATCH up the callsite). It also happens to be the first 0xCF opcode transfer. If such behaviour is unwanted, discard commit 1.

Tested on J-Link V9 against a RISC-V MCU.

Your checklist for this pull request

Closing issues

## Detailed description * This is a minor new feature. * The problem is rudimentary/poor implementation of `jtagtap_cycle()` in jlink.c backend used by BMDA. (and it didn't even exist until very recently) * This PR solves it by providing one moderately optimized variant. Tracking: #2180. Note that `jlink_jtag_init()` used to rely on a direct `jlink_transfer()` of a baked byte buffer with 56 idle clocks and SWD-to-JTAG switch sequence, I replaced that with a `jlink_jtag_cycle()` call for 56-5=51 clocks and a shorter, 16-bit sequence. The caveat is that new function may raise an exception, and at scan time it results in immediate SIGABRT because it's unhandled (by any TRY-CATCH up the callsite). It also happens to be the first 0xCF opcode transfer. If such behaviour is unwanted, discard commit 1. Tested on J-Link V9 against a RISC-V MCU. ## Your checklist for this pull request * [x] I've read the [Code of Conduct](https://github.com/blackmagic-debug/blackmagic/blob/main/CODE_OF_CONDUCT.md) * [x] I've read the [guidelines for contributing](https://github.com/blackmagic-debug/blackmagic/blob/main/CONTRIBUTING.md) to this repository * [x] It builds for hardware native (see [Building the firmware](https://github.com/blackmagic-debug/blackmagic?tab=readme-ov-file#building-black-magic-debug-firmware)) * [x] It builds as BMDA (see [Building the BMDA](https://github.com/blackmagic-debug/blackmagic?tab=readme-ov-file#building-black-magic-debug-app)) * [x] I've tested it to the best of my ability * [x] My commit messages provide a useful short description of what the commits do ## Closing issues
dragonmux left a comment
Copy link

Couple of things we notice reviewing this, but with them fixed we'll be happy to merge this.

Couple of things we notice reviewing this, but with them fixed we'll be happy to merge this.
@ -56,7 +54,10 @@ bool jlink_jtag_init(void)

Please don't use the number 2 in the name here - tms_swd_to_jtag_seq reads easier and more naturally.

Please don't use the number 2 in the name here - `tms_swd_to_jtag_seq` reads easier and more naturally.
@ -122,6 +123,21 @@ static bool jlink_jtag_next(bool tms, bool tdi)

These could do with U suffixing and you might as well use UINT64_MAX here unless the J-Link doesn't like the trailing set bits in the buffers - but that raises the max clock sequence length to 64 from 63.

These could do with `U` suffixing and you might as well use `UINT64_MAX` here unless the J-Link doesn't like the trailing set bits in the buffers - but that raises the max clock sequence length to 64 from 63.

Please use write_le8() here not memcpy() as this makes invalid assumptions about byte layout within a uint64_t that will get violated on the wrong endian system.

Please use `write_le8()` here not `memcpy()` as this makes invalid assumptions about byte layout within a `uint64_t` that will get violated on the wrong endian system.
dragonmux left a comment
Copy link

The suggested other way to express the cycle logic we think fits quite well - doesn't need byte ordering shenanigans, or wide shift and subtract - with the first block of the #if/#else removed and the two small notes below addressed, we'll be happy to merge this.

The suggested other way to express the cycle logic we think fits quite well - doesn't need byte ordering shenanigans, or wide shift and subtract - with the first block of the `#if`/`#else` removed and the two small notes below addressed, we'll be happy to merge this.
@ -122,6 +123,21 @@ static bool jlink_jtag_next(bool tms, bool tdi)

Perhaps for this call memset()? (memset(tms_buf, tms ? 0xffU : 0U, clock_bytes);, etc)

Perhaps for this call `memset()`? (`memset(tms_buf, tms ? 0xffU : 0U, clock_bytes);`, etc)

This looks to be missing its - 1U to convert the value into a mask?

This looks to be missing its ` - 1U` to convert the value into a mask?
ALTracer (Migrated from github.com) reviewed 2026年02月06日 18:35:01 +01:00
@ -122,6 +123,21 @@ static bool jlink_jtag_next(bool tms, bool tdi)
ALTracer (Migrated from github.com) commented 2026年02月06日 18:35:01 +01:00
Copy link

Yes, completely missed memset, I was looking at git history of jtag-related jlink functions, and they all seem to fill byte buffers. This way there's no 64-bit limit, you could generate up to 2 KiB of data per command (J-Link fw capacity).

Yes, completely missed memset, I was looking at git history of jtag-related jlink functions, and they all seem to fill byte buffers. This way there's no 64-bit limit, you could generate up to 2 KiB of data per command (J-Link fw capacity).
ALTracer (Migrated from github.com) reviewed 2026年02月06日 18:53:39 +01:00
@ -122,6 +123,21 @@ static bool jlink_jtag_next(bool tms, bool tdi)
ALTracer (Migrated from github.com) commented 2026年02月06日 18:53:39 +01:00
Copy link

The function in question does not exist, abandoning in favor of rewrite.

The function in question does not exist, abandoning in favor of rewrite.
dragonmux left a comment
Copy link

LGTM, merging. Thank you for the contribution and this improvement to the J-Link backend!

LGTM, merging. Thank you for the contribution and this improvement to the J-Link backend!
Sign in to join this conversation.
No reviewers
Labels
Clear labels
BMD App
Black Magic Debug App (aka. PC hosted) (not firmware)
BMP Firmware
Black Magic Probe Firmware (not PC hosted software)
Bug
Confirmed bug
Build system
Build system
Can't reproduce
Maintainers can't reproduce this problem
CI
Continuous Integration System
Contribution wanted
User contributions welcome
Documentation
Project documentation
Draft
Work in progress draft
Duplicate
This issue or pull request already exists
Enhancement
General project improvement
Feedback wanted
Requires additional submitter feedback
Foreign Host Board
Non Native hardware to runing Black Magic firmware on
GDB
Issue/PR related to GDB
Good first issue
Good for newcommers
HwIssue Mitigation
Solving or mitigating a Hardware issue in Software
Information Needed
Maintainers need more information
NativeHardware
Official Black Magic Debug Hardware
New Host Board
New hardware to run Black Magic firmware on
New Target
New debug target
Off Topic
Something that does not involve the project in any way
Potential Bug
A potential, unconfirmed or very special circumstance bug
Regression
Bug caused by a regression
User Interest Needed
More user interest required before consideration
User Testing Needed
Looking for user testing reports
Won't fix
Outside of the project scope or works as intended
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
blackmagic-debug/blackmagic!2182
Reference in a new issue
blackmagic-debug/blackmagic
No description provided.
Delete branch "feature/jtagtap_cycle_jlink"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?