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

CMSIS-DAP: hidapi backend improvement; protocol version fixes; more trace logging #1272

Merged
merged 8 commits into from
Dec 20, 2021

Conversation

flit
Copy link
Member

@flit flit commented Dec 20, 2021

There are two major, connected components to this PR, all focused on the CMSIS-DAP implementation.

The first component is some fixes/improvements:

  • Fix issue nRF52 program failure; packet order issue with CMSIS-DAP on Mac #1257 in the hidapi backend (used for CMSIS-DAP v1 on Mac and Windows) where command responses could get lost if the CMSIS-DAP maximum outstanding packet count was over 30.
    • Add a background read thread. This reads an incoming response as soon as it's available.
    • Limit outstanding packets to 30, matching the arbitrary limit built in to the Mac version of hidapi.
  • Introduce timeouts for packet reads in the hidapi, pyusb, and pyusb v2 backends (pywinusb already had a timeout).
  • Better handle unrecognized versions during detection of the CMSIS-DAP protocol version.
    • The debug log message with the protocol version now also includes a "v1"/"v2" based solely on use of bulk endpoints.
    • If an unrecognised or unparseable version is found (like DAPLink's 0254 or 0255 releases, or Microchip EDBG), fall back to either v1.0.0 or v2.0.0 based on use of bulk endpoints.
    • Compare only major+minor protocol versions, and output a debug log message if an unrecognised version is seen.

The second component improves CMSIS-DAP trace logging and test features:

  • Add USB packet trace logging to the backends. Can be enabled with -Lpyocd.probe.pydapaccess.interface.*backend.trace=debug.
  • Improve trace logging for building of transfer command packets in the CMSIS-DAP core (dap_access_cmsis_dap.py). Enabled with -Lpyocd.probe.pydapaccess.dap_access_cmsis_dap.trace=debug.
  • Add cmsis_dap.prefer_v1 session option to force selection of v1 if a probe provides both v1 and v2 interfaces. Naturally, v2 is and always has been, used by default.
  • New 'flushprobe' command that ensure all outstanding command responses have been received.

There are also some minor changes to go along with the above.

Thanks to @afeinman-snap for the bug report that drove these changes, and he and @bohdan-tymkiv for help solving it!

Fixes #1257.

- Log v1/v2 based on use of bulk endpoints, so it’s easy to see in a
  debug log.
- Explicit check for beta versions.
- Only compare against major protocol versions.
- Reintroduce explicit handling of DAPLink 0254 and 0255 so they are
  recognised as v2.x.
- Output debug log if an unknown major version is found or there is an
  error parsing.
- Set fallback protocol version based on bulk endpoint usage.
- _Command objects have unique IDs, output in trace logs.
- Trace logging of _read_packet(), _send_packet(), and aborts.
- Renamed _Command._get_free_words() to _get_free_transfers() to reflect actual return value.
@lgtm-com
Copy link

lgtm-com bot commented Dec 20, 2021

This pull request introduces 3 alerts when merging 25c9e4d into 3a4e837 - view on LGTM.com

new alerts:

  • 3 for Unused import

@flit
Copy link
Member Author

flit commented Dec 20, 2021

The AZP tests are failing to download a pyocd.yaml artifact used to configure the test agents due to a permissions problem. The difference is that this is the first PR from a fork.

… limit.

This change introduces a background read thread for the HidApiUSB
backend for CMSIS-DAP. Similar to the other backends, it reads and
queues incoming command responses as soon as they are available.
Also added a packet count maximum to deal with the arbitrary limit
of 30 queued IN reports in the Mac version of hidapi.
@flit flit force-pushed the feature/more_cmsis_dap_trace_logging branch from 25c9e4d to bddbd19 Compare December 20, 2021 18:56
@flit flit merged commit 269610f into pyocd:develop Dec 20, 2021
@flit flit deleted the feature/more_cmsis_dap_trace_logging branch January 18, 2022 19:04
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