Title: `brp` parameter validation for `BitTiming` can be too restrictive for some peripherals · Issue #2061 · hardbyte/python-can · GitHub
Open Graph Title: `brp` parameter validation for `BitTiming` can be too restrictive for some peripherals · Issue #2061 · hardbyte/python-can
X Title: `brp` parameter validation for `BitTiming` can be too restrictive for some peripherals · Issue #2061 · hardbyte/python-can
Description: Describe the bug The BitTiming class unconditionally requires that the bitrate prescaler brp is within the interval [1,64]; this is checked in the _validate function, which is unconditionally called from __init__ even when strict=False: ...
Open Graph Description: Describe the bug The BitTiming class unconditionally requires that the bitrate prescaler brp is within the interval [1,64]; this is checked in the _validate function, which is unconditionally calle...
X Description: Describe the bug The BitTiming class unconditionally requires that the bitrate prescaler brp is within the interval [1,64]; this is checked in the _validate function, which is unconditionally calle...
Opengraph URL: https://github.com/hardbyte/python-can/issues/2061
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`brp` parameter validation for `BitTiming` can be too restrictive for some peripherals","articleBody":"### Describe the bug\nThe `BitTiming` class unconditionally requires that the bitrate prescaler `brp` is within the interval `[1,64]`; this is checked in the `_validate` function, which is unconditionally called from `__init__` even when `strict=False`:\n```python\n def _validate(self) -\u003e None:\n if not 1 \u003c= self.brp \u003c= 64:\n raise ValueError(f\"bitrate prescaler (={self.brp}) must be in [1...64].\")\n\n # other checks omitted\n```\n\nI was using `python-can` with a FYSETC UCAN transceiver running candleLight firmware, which speaks the `gs_usb` protocol. The transceiver uses a clock frequency of `fclock=48MHz`, but it also supports a large range of possible `brp` values from 1 to 1024 to implement lower bitrates (see [bxcan.c](https://github.com/candle-usb/candleLight_fw/blob/5fc2e6b560928f94079e206364354250157448c2/src/can/bxcan.c#L57) ). \n\nI need to configure a baud rate of 33333 bit/s and want to use the default sample point of 87.5%, which requires a prescaler value \u003e 64 to keep the other paramters (specifically `tseg1` within their valid range). This is currently not possible without patching the code of `python-can` directly, since the `gs_usb` interface kind does not allow direct specification of the `BitTimings`, and the validation check will reject the prescaler value, so the automatic parameter finding does not work. However, the device supports higher prescaler values just fine; and removing the bitrate prescaler check in `_validate` allows me to configure the device and send CAN messages.\n\n\n\n### To Reproduce\nThe following code will raise `ValueError(\"No suitable bit timings found.\")` from `BitTimings.from_sample_point`\n```python\nimport can\ncan_bus = can.Bus(interface='gs_usb', channel=0, bitrate=33333)\n```\n\nNote: this requires a suitable board with candleLight firmware to be present and attached. Internally, the device configuration routine retrieves the CAN clock speed and calls `BitTiming.from_sample_point` with those values:\n\n```python\nfrom can.bit_timing import BitTiming\nBitTiming.from_sample_point(f_clock=48000000,bitrate=33333,sample_point=87.5)\n```\nThis can be called without hardware to reproduce the issue.\n\n### Expected behavior\nIdeally, the parameter validation takes the valid parameter range of the attached device into account (if known), so that the code above just works as-is. The `gs_usb` protocol allows the host to query valid timing parameters, including the CAN clock frequency and the range of allowed `brp` values (start, stop, increment). \n\nAlternatively, having an option to pass a raw `BitTimings` object to the `can.Bus` method would work as well, although it would be less convenient.\n\n### Additional context\n\nOS and version: Linux 6.17.0-23-generic (Ubuntu 25.10)\nPython version: 3.13.7\npython-can version: 4.6.1\npython-can interface/s (if applicable): gs_usb\n\n\n\n\u003cdetails\u003e\u003csummary\u003eTraceback and logs\u003c/summary\u003e\n\n```\nTraceback (most recent call last):\n File \"/home/user/Development/canbus/./gs_usb_bitrate_test.py\", line 3, in \u003cmodule\u003e\n can_bus = can.Bus(interface='gs_usb', channel=0, bitrate=33333)\n File \"/home/user/Development/canbus/venv/lib/python3.13/site-packages/can/util.py\", line 392, in wrapper\n return f(*args, **kwargs)\n File \"/home/user/Development/canbus/venv/lib/python3.13/site-packages/can/interface.py\", line 137, in Bus\n bus = cls(channel, **kwargs)\n File \"/home/user/Development/canbus/venv/lib/python3.13/site-packages/can/interfaces/gs_usb.py\", line 63, in __init__\n bit_timing = can.BitTiming.from_sample_point(\n f_clock=self.gs_usb.device_capability.fclk_can,\n bitrate=bitrate,\n sample_point=87.5,\n )\n File \"/home/user/Development/canbus/venv/lib/python3.13/site-packages/can/bit_timing.py\", line 295, in from_sample_point\n raise ValueError(\"No suitable bit timings found.\")\nValueError: No suitable bit timings found.\n```\n\n\u003c/details\u003e\n","author":{"url":"https://github.com/SeTcbPrivilege","@type":"Person","name":"SeTcbPrivilege"},"datePublished":"2026-05-15T15:30:00.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/2061/python-can/issues/2061"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:fa53cec8-9c7b-53c4-3dbc-bd60a05821cb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 964A:1DF241:5E362B1:7C64AE7:6A5DC2D3 |
| html-safe-nonce | f5258d569a383fc482635fa84698f31bdb550f86c87fec00794b05eecdf6b1d4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NjRBOjFERjI0MTo1RTM2MkIxOjdDNjRBRTc6NkE1REMyRDMiLCJ2aXNpdG9yX2lkIjoiNTE0Nzc0NTM3NjY2NjUwMTg0MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 8560c49555c326732c98e97107abf28019dbf53aa7d117301d83677c2d3c9819 |
| hovercard-subject-tag | issue:4455068446 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/hardbyte/python-can/2061/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9be1c0a6a372b7a9b44461ab2b9b133240e208f2aca142404fba11c9aad2eb37/hardbyte/python-can/issues/2061 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9be1c0a6a372b7a9b44461ab2b9b133240e208f2aca142404fba11c9aad2eb37/hardbyte/python-can/issues/2061 |
| og:image:alt | Describe the bug The BitTiming class unconditionally requires that the bitrate prescaler brp is within the interval [1,64]; this is checked in the _validate function, which is unconditionally calle... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | SeTcbPrivilege |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| turbo-cache-control | no-preview |
| go-import | github.com/hardbyte/python-can git https://github.com/hardbyte/python-can.git |
| octolytics-dimension-user_id | 855189 |
| octolytics-dimension-user_login | hardbyte |
| octolytics-dimension-repository_id | 69090889 |
| octolytics-dimension-repository_nwo | hardbyte/python-can |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 69090889 |
| octolytics-dimension-repository_network_root_nwo | hardbyte/python-can |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width