Repository navigation
fix(bit_timing): make the sample point solver's register ranges configurable - #2165
ChuangMuLinze wants to merge 2 commits into
Conversation
…gurable `iterate_from_sample_point` built every candidate with `strict=True`, whose `brp <= 32`, `tseg1 <= 16` and `tseg2 <= 8` limits are the ISO 11898-1 minimum ranges. A controller whose registers reach further therefore had valid timings rejected, and `from_sample_point` raised "No suitable bit timings found" with no way for a caller to widen the search. STM32G431 FDCAN at 160 MHz for 250 kbit/s at 87.5% is such a clock: the only solution is brp=40, tseg1=13, tseg2=2, and the strict brp limit rejected it. `from_sample_point`, `iterate_from_sample_point` and `BitTiming` now take `tseg1_max`, `tseg2_max` and `brp_max`, and the solver scans prescalers up to the configured maximum. The defaults are the previous limits, so existing callers see no change. Fixes hardbyte#2083
AI Review: PR #2165 – configurable register ranges for the sample point solverThe PR fixes the reported case: API design
Documentation
Tests
Changelog
Verdictrequest changes |
`black --check .` is the first command of the lint environment and reformats this file: the parametrize decorator fits on one line, and so does the call in `test_from_sample_point_rejects_impossible_ranges`. No behavior changes.
|
The The other four failing jobs are not from this change.
|
|
About the What actually fails
Every other test in that job passes (739 passed, 140 skipped). Why it looks like a race rather than a regression The test body is: for duration, period in [(0.01, 0.003), (0.1, 0.011), (1, 0.4)]:
messages = []
self.bus2.send_periodic(can.Message(), period, duration)
while (msg := self.bus1.recv(period + self.TIMEOUT)) is not None:
messages.append(msg)
delta_t = messages[-1].timestamp - messages[0].timestampThe last line assumes Why it shouldn't be this PR The diff touches three files:
None of them is involved in I cannot reproduce it locally either, so I want to be explicit about my evidence: I'm on aarch64 Linux, so there is no macOS runner available to me to confirm the diagnosis by experiment. Two supporting observations: the previous run on this branch also had several What I'd suggest I'd prefer not to silently patch an unrelated test inside a bit-timing PR. If you'd rather have it hardened — e.g. asserting that Either way, a re-run would confirm whether it's environmental. |
Summary of Changes
iterate_from_sample_pointbuilt every candidate withstrict=True, whosebrp <= 32,tseg1 <= 16andtseg2 <= 8limits are the ISO 11898-1 minimum ranges every compliantcontroller must support. A controller whose registers reach further had valid timings rejected
and
from_sample_pointraisedNo suitable bit timings found, with no way for a caller to widenthe search.
BitTiming,from_sample_pointanditerate_from_sample_pointtaketseg1_max,tseg2_maxand
brp_max._restrict_to_minimum_rangeuses those bounds instead of hardcoded ones.brp_maxrather than stopping at 64.solution.
Related Issues / Pull Requests
BitTiming.from_sample_pointrejects valid timing solutions due to hardcoded register limits #2083Type of Change
Checklist
the docstrings, which the API docs render.
doc/changelog.d/2083.fixed.rst) for towncrier.tox) — see below for what I ran.Additional Notes
The case from the issue, STM32G431 FDCAN at 160 MHz for 250 kbit/s at 87.5%, now returns the
solution the issue predicted:
Without the new arguments it still raises, which
test_from_sample_point_keeps_default_rangespins.
Test run:
The five new behaviour tests fail on unpatched
main(unexpected keyword argument), so they coverthe change.
I ran pytest directly rather than through
tox; this sandbox has no tox environment, so Iinstalled
wrapt,pytest-timeoutandpytest-covto satisfy the project'saddopts. Everythingelse is the repository's own
tox.iniconfiguration.