Skip to content

CAN: Fix CRC field decoding for CAN-FD#131

Open
stephan-thiele wants to merge 7 commits intosigrokproject:masterfrom
stephan-thiele:can/fix-fd-bitstuffing
Open

CAN: Fix CRC field decoding for CAN-FD#131
stephan-thiele wants to merge 7 commits intosigrokproject:masterfrom
stephan-thiele:can/fix-fd-bitstuffing

Conversation

@stephan-thiele
Copy link
Copy Markdown
Contributor

@stephan-thiele stephan-thiele commented Mar 5, 2026

Currently in CAN decoder, CRC field of CAN-FD is decoded in a wrong way. On classic CAN, CRC-15 field occurs directly after data field. On CAN-FD however, after data field, an SBC field (stuff bit count, modulo 8, gray coded with parity bit) and a CRC-17 or CRC-21 (depending on data length) occur. Additionally, CRC sequence on CAN-FD does not use NRZ bit stuffing but a fixed bit stuffing instead. Currently on CAN-FD, the SBC field and the stuff bits are part of the CRC value which is incorrect.

To fix this, in this PR the following steps are done:

  • Implement fixed bit stuffing for CAN-FD CRC field
  • Split up CAN-FD CRC field into SBC and CRC
  • Decode SBC gray code value and check parity bit (annotate warning on invalid parity)

Behaviour of the decoder changes from:

image

To:

image

Dump used shown in the images is: https://github.com/sigrokproject/sigrok-dumps/blob/master/can/can_fd/arbitrary_traffic/can_fd_std_brs_8.sr

I have made a regression test with sigrok-test by running pdtest -r -v can. Tests of classic CAN dumps pass, except nmea2000_fuel_flow_gps_snippet. To me it looks like the sample rate of the recording is too low which leads to invalid values:

image

There are only very few samples per bit and the decoder also annotates warnings on some frames. I'd suggest to remove it entirely as, in my opinion, it is not very useful for regression tests in this state.

CAN-FD tests fail as expected in CRC field area.

I have validated some decoded CRC values for CRC-17 and CRC-21 by using PEAK CAN FD Frame Analyzer tool: https://www.peak-system.com/products/software/tools/can-fd-frame-analyzer/

I will do another PR in sigrok-test repo with updated test vectors and link it here once it is created.

Edit: PR with the updated test vectors is now created: sigrokproject/sigrok-test#29

@stephan-thiele stephan-thiele force-pushed the can/fix-fd-bitstuffing branch from 0ba3408 to 96c4e38 Compare March 18, 2026 18:52
@stephan-thiele
Copy link
Copy Markdown
Contributor Author

Removed a redundant variable assignment via rebase and force-pushed to avoid a fixup commit, as the review had not started yet.

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