Skip to main content
Graduate
April 11, 2024
Solved

Use of STM32L1xxxx CRC module for the computation of several CRC standards

  • April 11, 2024
  • 1 reply
  • 2674 views

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);

    This topic has been closed for replies.
    Best answer by Tesla DeLorean

    It's a signature line, like accept my answer to feed the broken metrics algorithm, or buy me coffee..

    1 reply

    ST Employee
    April 12, 2024

    Hello @elKarro ,

    I can't seem to get your message here "MCU speaks VHDL and CPU speaks assembly. Neither of them speaks HAL."

    booth speak different assembly depending on the cortex architecture for ARM based CPUs and MCUs.

    can you please explain your issue so i can try to help you through it.

    BR

    Graduate II
    April 12, 2024

    It's a signature line, like accept my answer to feed the broken metrics algorithm, or buy me coffee..

    elKarroAuthor
    Graduate
    April 12, 2024

    Thanks Tesla DeLorean, it seems it needed to be clarified :D