Skip to content

Commit b27eb50

Browse files
committed
dist/tools/bmp: detect unsupported targets
Instead of listing 'no targets found', detect unsupported targets as well. Once we need to attach, assert that the target is supported. Starting with firmware 2.0.0 of the BMP, not all targets are supported by defaults (depends on the firmware flavor). Adding support for this case therefore makes sense.
1 parent b07f32d commit b27eb50

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

dist/tools/bmp/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ unless the probe is accessed remotely (e.g. `--port` is a network address). If
6363
the firmware version cannot be determined, it will assume version 1.10.2. This
6464
can be overridden using the `--bmp-version` flag.
6565

66+
As of firmware version 2.0.0 of the Black Magic debugger, support for targets
67+
depend on the 'flavor' of firmware selected. This tool will indicate if that
68+
is the case.
69+
6670
## Examples (tested with BluePill STM32F103F8C6)
6771
* test connection:
6872
```

dist/tools/bmp/bmp.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,11 @@ def detect_targets(gdbmi, res):
105105
while True:
106106
for msg in res:
107107
if msg['type'] == 'target':
108-
m = re.fullmatch(pattern=r"\s*(\d+)\s*(.*)\s*", string=msg['payload'])
108+
m = re.fullmatch(pattern=r"([\s\*]*)(\d+)\s*(.*)\s*", string=msg['payload'])
109109
if m:
110-
targets.append(m.group(2))
110+
supported = "***" not in m.group(1)
111+
description = m.group(3)
112+
targets.append((supported, description))
111113
elif msg['type'] == 'result':
112114
assert msg['message'] == 'done', str(msg)
113115
return targets
@@ -284,10 +286,13 @@ def connect_to_target(args, port):
284286
targets = detect_targets(gdbmi, res)
285287
assert len(targets) > 0, "no targets found"
286288
print("found following targets:")
287-
for t in targets:
288-
print(f"\t{t}")
289+
for s, t in targets:
290+
if not s:
291+
print(f"\t{t} (unsupported)")
292+
else:
293+
print(f"\t{t}")
289294
print("")
290-
return gdbmi
295+
return (gdbmi, targets)
291296

292297

293298
def parse_args():
@@ -334,11 +339,14 @@ def main():
334339
debug_mode(args, port)
335340
sys.exit(0)
336341

337-
gdbmi = connect_to_target(args, port)
342+
(gdbmi, targets) = connect_to_target(args, port)
338343

339344
if args.action == 'list':
340345
sys.exit(0)
341346

347+
assert len(targets) >= args.attach, "attach greater than number of targets"
348+
assert targets[args.attach - 1][0], "target unsupported by probe"
349+
342350
assert gdb_write_and_wait_for_result(gdbmi, f'-target-attach {args.attach}', 'attaching to target')
343351

344352
# reset mode: reset device using reset pin

0 commit comments

Comments
 (0)