Use of STM32L1xxxx CRC module for the computation of several CRC standards
Premises:
- built with gcc version 11.3.1 20220712 (GNU Tools for STM32 11.3.rel1.20230912-1600)
- verified on STM32L151RC
- cross reference to crc: https://reveng.sourceforge.io/
STM32L1xxxx CRC module can compute crcs compliant to the following 4 standards:
- CRC-32/ISO-HDLC*
- CRC-32/JAMCRC
- CRC-32/BZIP2
- CRC-32/MPEG-2
(*) ISO-HDLC is implemented in these softwares: WinRar, ExamDiff, FreeCommander, HashMyFiles.
CRC module digests one int32 at a time, it doesn't digest byte-per-byte, so the input data must be a stream of m bytes, where m is multiple of 4: m == n * 4, having its base address aligned to uint32_t. That's why the byte stream is passed as uint32_t data[] in the examples.
Given the MCU endianness and the CRC module implementation, in order to meet the wanted results each dword must be bit-reflected for ISO-HDLC/JAMCRC while it must be byte-reversed for BZIP2/MPEG-2. Once all the data has been digested, crc must be finalized (except for MPEG-2):
- ISO-HDLC -> bit-reflect then xor with 0xFFFFFFFF
- JAMCRC -> bit-reflect
- BZIP2 -> xor with 0xFFFFFFFF
Attached an implementation, here're the prototypes:
uint32_t CalcCrc32_ISO_HDLC(uint32_t data[], unsigned n);
uint32_t CalcCrc32_JAMCRC(uint32_t data[], unsigned n);
uint32_t CalcCrc32_BZIP2(uint32_t data[], unsigned n);
uint32_t CalcCrc32_MPEG_2(uint32_t data[], unsigned n);
