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

CRC16 Implementation Documentation #330

Closed
jcsoo opened this issue Apr 18, 2019 · 2 comments
Closed

CRC16 Implementation Documentation #330

jcsoo opened this issue Apr 18, 2019 · 2 comments

Comments

@jcsoo
Copy link

jcsoo commented Apr 18, 2019

Comments in the protocol implementation suggest that a standard CRC16 calculation is being used with the polynomial 0x3D65 (typically used in CRC-16-DNP):

https://github.com/madcowswe/ODrive/blob/4e039e160416f52195e2199cec62a92fa2f103b6/Firmware/fibre/python/fibre/protocol.py#L64-L66

However, running the commented code produces 0x9a3a:

>>> hex(fibre.protocol.calc_crc16(0xfeef, [1, 2, 3, 4, 5, 0x10, 0x13, 0x37]))
'0x9a3a'

which is a different result than what the referenced online calculator generates when using the the same polynomial and initial value:

image

It probably doesn't make sense to change the algorithm at this point, but if it really is different, it should be documented so that driver implementers know that they have to reproduce this specific algorithm rather than using an existing CRC library.

It would also be handy to have a few test cases to make it easier to confirm correct implementation.

@metanoic
Copy link
Contributor

metanoic commented Jun 7, 2019

Existing CRC libraries should be capable of handling this fine. You need to untick the input and result reflection options in the CRC detailed parameters section and there is no final Xor'ing, so set that to 0x0 or leave blank. Doing so will yield 0x9A3A as the result.

Capture

@samuelsadok
Copy link
Member

I clarified the CRC documentation a bit now. See: https://github.com/madcowswe/ODrive/blob/devel/docs/protocol.md#crc-algorithms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
ODrive Development
  
Next release
Development

No branches or pull requests

4 participants