cancel
Showing results for 
Search instead for 
Did you mean: 

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

elKarro
Associate III

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

MCU speaks VHDL and CPU speaks assembly. Neither of them speaks HAL.
1 ACCEPTED SOLUTION

Accepted Solutions

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

5 REPLIES 5
STea
ST Employee

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

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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

MCU speaks VHDL and CPU speaks assembly. Neither of them speaks HAL.

Thanks STea, I don't need any help about that.
But since you offered to, you could please answer to a previous question I asked:
https://community.st.com/t5/stm32-mcus-embedded-software/usart-sr-clearing-sequence-of-idle-ore-nf-fe-pe-a-silicon-level/td-p/647799
I guess you have access to that kind of documentation, as a ST Employee.
Thanks in advance.

MCU speaks VHDL and CPU speaks assembly. Neither of them speaks HAL.

Hello @elKarro ,

Thanks @Tesla DeLorean for pointing that out I didn't see the separator in the question, so I thought it was a part of your question :p .

regarding the question that you shared I'll take a look and see what I can do.

BR

 

 

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.