Skip to content

stlink: fix TypeError in _get_board_id() when mbed.htm exists but has no TargetID - #2056

Open
alwaysmy wants to merge 1 commit into
pyocd:developfrom
alwaysmy:fix-stlink-board-id-typeerror
Open

alwaysmy wants to merge 1 commit into
pyocd:developfrom
alwaysmy:fix-stlink-board-id-typeerror

Conversation

@alwaysmy

Copy link
Copy Markdown

Fixes #2055.

What

StlinkProbe._get_board_id() slices info['target_id_mbed_htm'][0:4] inside a try that only
catches KeyError. stlink/detect/base.py documents _read_htm_ids() as returning None on
failure and then stores that None in the same key, so an mbed.htm that exists but has no
parsable TargetID produces "key present, value None" — which raises TypeError and escapes,
aborting probe enumeration entirely.

Add TypeError to the caught exceptions so the existing "we can live without the board ID"
path handles it.

Why it started happening

The gate if info['target_id_usb_id'] == self._link.serial_number was removed in 0.35.0, so the
loop now slices for every enumerated MSD volume and only breaks on a match. The offending volume
therefore no longer needs to belong to the ST-Link: any volume with an unparsable mbed.htm
breaks enumeration of every ST-Link on the machine.

version usb_id gate before the slice caught triggered
0.20.0 – 0.34.3 present KeyError (none before 0.22.0) no
0.35.0 – 0.45.1, main removed KeyError yes

Testing

  • pyocd list before: single-line Error: 'NoneType' object is not subscriptable, exit code 1,
    no probe listed at all. After: exit code 0, ST-Link listed with n/a in the Target column,
    other probes unaffected. Verified on Windows / Python 3.14 with an ST-Link whose firmware does
    not answer get_board_id() and a DAPLink volume whose mbed.htm is a redirect page with no
    TargetID.
  • StlinkProbe.board_id now returns None instead of raising, which is the documented intent of
    that block.
  • The guard's input shapes:
input before after
key absent (the #695 case) None None
key present, value None TypeError None
key present, value "" "" ""
key present, value "0123…" "0123" "0123"

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant