Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dist/tools/bmp: additional improvements to auto-detection #21128

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

basilfx
Copy link
Member

@basilfx basilfx commented Jan 11, 2025

Contribution description

This extends the auto-detection logic by parsing the firmware version number from the device descriptor as returned by PySerial. For stable releases, this should return a proper version number, and restores out-of-the-box compatibility with older firmware versions.

found following Black Magic GDB servers:
        [/dev/cu.usbmodem81C986981] Serial: 81C98698 Firmware: 2.0.0 <- default 
connecting to [/dev/cu.usbmodem81C986981]...
auto-detected firmware version 2.0.0
GDB EXECUTABLE NOT FOUND! FALLING BACK TO /opt/homebrew/bin/arm-none-eabi-gdb
connecting successful.

The second improvements is to detect unsupported targets. The former message was a bit misleading. At least in v1.10.2 and v2.0.0 of the BMP, unsupported targets are prefixed with ***:

(gdb) mon swd_scan
Target voltage: 3.3V
Please report unknown device with Designer 0x673 Part ID 0x801
Available Targets:
No. Att Driver
*** 1   Unknown ARM Cortex-M Designer 0x673 Part ID 0x801 M4

The improvement will detect this, and report back. If the user tries attach to the chosen target, a proper error will occur.

found following Black Magic GDB servers:
        [/dev/cu.usbmodem81C986981] Serial: 81C98698 Firmware: 2.0.0 <- default 
connecting to [/dev/cu.usbmodem81C986981]...
auto-detected firmware version 2.0.0
GDB EXECUTABLE NOT FOUND! FALLING BACK TO /opt/homebrew/bin/arm-none-eabi-gdb
connecting successful.
scanning using SWD...
found following targets:
        Unknown ARM Cortex-M Designer 0x673 Part ID 0x801 M4 (unsupported)

Traceback (most recent call last):
  File "/Users/basilfx/Desktop/Projecten/RIOT/RIOT_bmp/dist/tools/bmp/./bmp.py", line 376, in <module>
    main()
    ~~~~^^
  File "/Users/basilfx/Desktop/Projecten/RIOT/RIOT_bmp/dist/tools/bmp/./bmp.py", line 348, in main
    assert targets[args.attach - 1][0], "target unsupported by probe"

Lastly, some code improvements are added as well. Most of them were suggested by @maribu in a patch that laid the groundwork for auto-detection.

Testing procedure

Use the tool with firmware versions 1.8.0 - 2.0.0-rc1.

Issues/PRs references

Follow-up of #21107.

Parse the version number from the product description as returned by
libusb. This works for stable firmware releases, and ensures that
older firmwares work out of the box.
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.
@basilfx basilfx requested a review from jia200x as a code owner January 11, 2025 22:45
@basilfx basilfx requested review from maribu and removed request for jia200x January 11, 2025 22:45
@github-actions github-actions bot added Area: doc Area: Documentation Area: tools Area: Supplementary tools labels Jan 11, 2025
Copy link
Member

@maribu maribu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx, looks good to me. I'll do a bit of testing later today

@@ -258,9 +304,9 @@ def parse_args():
parser.add_argument('--tpwr', action='store_true', help='enable target power')
parser.add_argument('--serial', help='choose specific probe by serial number')
parser.add_argument('--port', help='choose specific probe by port (overrides auto selection)')
parser.add_argument('--attach', help='choose specific target by number', default='1')
parser.add_argument('--attach', help='choose specific target by number', type=int, default='1')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
parser.add_argument('--attach', help='choose specific target by number', type=int, default='1')
parser.add_argument('--attach', help='choose specific target by number', type=int, default=1)

As the type is int, we can provide the default also as int.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a fixup commit to address this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: doc Area: Documentation Area: tools Area: Supplementary tools
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants