Honor caller deadlines in Cortex-M and J-Link operations. - #75
Merged
Merged
Conversation
Cortex-M operations imposed a five-second limit even when their caller allowed more time. Pass the supplied context through acquisition, run control, register access, and release so the caller chooses the operation deadline. Keep the independent five-second restoration attempt after failed acquisition. Cancellation must not prevent that cleanup, and a retained target still permits the caller to retry release with its own context.
J-Link inspection stopped after one second or 101 attempts even when the open context allowed more time. Retry an unconfigured USB device until configuration appears or the caller's context ends, preserving both cancellation and the unconfigured-state error when waiting fails. Other inspection errors still return immediately, and retries retain their ten-millisecond spacing.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Owner
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cortex-M acquisition, halt/resume/status, register access, and release now use the caller's context without adding a five-second deadline. J-Link configuration inspection also uses the caller's context, removing its one-second deadline and 101-attempt limit. It still retries only
usb.ErrNotConfigured, with 10 ms between attempts.For an already acquired, halted target, the call stays the same. Before, a thirty-second allowance was cut to five seconds:
After, the same call can use the full thirty seconds, unless
ctxends sooner:The target still needs
Releasebefore its memory owner is closed. A failed transfer may leave cleanup pending; retain both owners and supply a usable context for restoration.Likewise, before this change
jlink.Open(ctx, device)stopped retrying an unconfigured device after one second or 101 attempts. Afterward,jlink.Open(ctx, device)retries until configuration appears orctxends. Ownership is unchanged: close the session on success, or the supplied device on error. A failed session close may need another attempt.Why
The library was shortening caller deadlines even when the caller had deliberately allowed more time. Callers now choose their own limits. A context without a deadline or cancellation can wait indefinitely for a target transition or USB configuration.
Failed Cortex-M acquisition still attempts restoration with an independent five-second context. That cleanup must remain possible after cancellation; a non-nil target returned with an error retains any cleanup obligation for a later
Release.Documentation
The Cortex-M guide and API comments describe caller-owned deadlines, including release. The architecture guide and J-Link capability table describe configuration retries under the caller's context.
Hardware evidence
On macOS, two fresh CMSIS-DAP v2 sessions on the nRF51822 micro:bit at 1 MHz/AP0 read all 19 supported registers, wrote and restored R4/SP/MSP/PSP/PC, and resumed the counter program. The counter stopped while halted and advanced after resume and release. Both sessions restored initially disabled debug and running state before closing the Arm debug owner; both owners closed successfully. The bench used serial
9900360140124e4500279015000000360000000097969901and the retained counter firmware:The J-Link EDU Mini V2 returned the same firmware metadata and selected interface across close and immediate reopen. Both sessions closed successfully:
These runs exercised ordinary operation after removing the limits; they did not provoke a slow target or prolonged unconfigured USB state. Deadline propagation, extended retries, and cancellation have behavioral-test coverage. No firmware was reloaded, and target state after the Arm owner closed was not measured.