Skip to content

Commit 2782a1d

Browse files
committed
fix(hil): special-case j-link debugger to not attach under reset
1 parent c148d14 commit 2782a1d

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

hil/src/commands/mcu.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,23 @@ fn attach_probe(probe: Probe, allow_erase: bool) -> Result<Session> {
443443
Permissions::new()
444444
};
445445

446-
probe
447-
.attach_under_reset(TARGET_NAME, perms)
448-
.wrap_err_with(|| format!("failed to attach to {TARGET_NAME}"))
446+
// J-Link probes sometimes have issues when attaching under reset, so we
447+
// detect them and fall back to a normal `attach` instead of
448+
// `attach_under_reset`.
449+
//
450+
// This heuristic is simple but effective: the probe driver exposes a
451+
// human‑readable name which contains the probe type. The `probe-rs`
452+
// implementation for J‑Link drivers uses the string "J-Link" (see
453+
// `JLinkFactory`'s `Display` implementation). As the name is available
454+
// without consuming the `Probe`, we can safely inspect it before we call
455+
// the consuming `attach*` methods.
456+
let probe_name = probe.get_name();
457+
458+
let session_result = if probe_name.contains("J-Link") || probe_name.contains("JLink") {
459+
probe.attach(TARGET_NAME, perms)
460+
} else {
461+
probe.attach_under_reset(TARGET_NAME, perms)
462+
};
463+
464+
session_result.wrap_err_with(|| format!("failed to attach to {TARGET_NAME}"))
449465
}

0 commit comments

Comments
 (0)