STM32F4 CRC32 algorithm headache
I am developing a serial comms protocol between two STM32F407s.
I am using the hardware CRC module to generate checksums for some of the data.
I am also writing a test script in python to aid development.
All has gone well until now.
Now I need my test script to generate a checksum that agrees with the F4's CRC module.
I have been unsuccessful.
Reading around, it seems that all I should need to do is reverse the bit order going in and reverse and invert the bits read out.
I have done this in my script and in the firmware. No joy.
I have tried 7 variants on CRC32 in my script, using crccheck lib. No joy.
I have tried implementing my own CRC32 function using the flow chart in Application Note AN4187. No joy.
I have systematically inverted and reversed bits, byte wise, word wise, and swapped endianness before, after and both, and compared against inverted, reversed and endianness swapped checksums with each of the above 8 algorithms, even fed the CRC modules byte by byte (2224 combinations). No fricking joy.
The source data was simply 0x01020304
F4's CRC output was: 0xA18723BA
bits reversed and inverted: 0xA02843B5
Does anyone have a proven concrete software implementation of the F4's hardware CRC module, either in c-like or python, that I can use to validate the firmware's output and complete my test script?
Or if not, check that your own F4 produces the same output for the source data?
Cheers
(Here's my attempted implementation:)
def dothething(inbytes, le=True, rr=False, xx=False, init=0xffffffff):
POLY = 0x4c11db7
crc = init
inbytes = bytes(inbytes)
for n in range(0,len(inbytes),4):
if le:
x = inbytes[n]<<0 | inbytes[n+1]<<1 | inbytes[n+2]<<2 | inbytes[n+3]<<3
else:
x = inbytes[n]<<3 | inbytes[n+1]<<2 | inbytes[n+2]<<1 | inbytes[n+3]<<0
if rr:
x = rev_bits_in_word(x)
crc = crc^x
for n in range(32):
crc = (crc<<1)
if crc&(1<<31):
crc = crc^POLY
crc=crc&0xffffffff #clamp to 32 bits
if rr:
crc = rev_bits_in_word(crc)
if xx:
crc = crc^0xffffffff
return crc