Skip to content

Commit

Permalink
dist/tools/bmp: detect unsupported targets
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
basilfx committed Jan 11, 2025
1 parent 6f742c7 commit c3a92e6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
4 changes: 4 additions & 0 deletions dist/tools/bmp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ unless the probe is accessed remotely (e.g. `--port` is a network address). If
the firmware version cannot be determined, it will assume version 1.10.2. This
can be overridden using the `--bmp-version` flag.

As of firmware version 2.0.0 of the Black Magic debugger, support for targets
depend on the 'flavor' of firmware selected. This tool will indicate if that
is the case.

## Examples (tested with BluePill STM32F103F8C6)
* test connection:
```
Expand Down
20 changes: 14 additions & 6 deletions dist/tools/bmp/bmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ def detect_targets(gdbmi, res):
while True:
for msg in res:
if msg['type'] == 'target':
m = re.fullmatch(pattern=r"\s*(\d+)\s*(.*)\s*", string=msg['payload'])
m = re.fullmatch(pattern=r"([\s\*]*)(\d+)\s*(.*)\s*", string=msg['payload'])
if m:
targets.append(m.group(2))
supported = "***" not in m.group(1)
description = m.group(3)
targets.append((supported, description))
elif msg['type'] == 'result':
assert msg['message'] == 'done', str(msg)
return targets
Expand Down Expand Up @@ -284,10 +286,13 @@ def connect_to_target(args, port):
targets = detect_targets(gdbmi, res)
assert len(targets) > 0, "no targets found"
print("found following targets:")
for t in targets:
print(f"\t{t}")
for s, t in targets:
if not s:
print(f"\t{t} (unsupported)")
else:
print(f"\t{t}")
print("")
return gdbmi
return (gdbmi, targets)


def parse_args():
Expand Down Expand Up @@ -334,11 +339,14 @@ def main():
debug_mode(args, port)
sys.exit(0)

gdbmi = connect_to_target(args, port)
(gdbmi, targets) = connect_to_target(args, port)

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

assert len(targets) >= args.attach, "attach greater than number of targets"
assert targets[args.attach - 1][0], "target unsupported by probe"

assert gdb_write_and_wait_for_result(gdbmi, f'-target-attach {args.attach}', 'attaching to target')

# reset mode: reset device using reset pin
Expand Down

0 comments on commit c3a92e6

Please sign in to comment.