cancel
Showing results for 
Search instead for 
Did you mean: 

Getting the HAL_CRC module to generate a CRC32

ttatakis
Associate III

I'm trying to get the HAL_CRC module to generate a 32bit CRC32 that matches the online calculators and matches what I get out of python with binascii.crc32() or zlib. I have a DoCkecksum() call below that calls HAL_CRC_Calculate() and I have called it with every combination of the input parameters but none of them match the calculated crc I get with the online calculators or with my python script. My python script does match the online calculators and for the value in the function the CRC should be 0x47A79BF9.

I'm running a project on an STM32H745 Nucleo board. I've also attached the project. All the relevant code is in main.c.

uint32_t DoChecksum(uint32_t inputFormat, uint32_t inputReverse, uint32_t outReverse)

{

   uint32_t uiCRCCalc;

   uint32_t uiVal;

   uiVal= 0xC0DE50FF;

   hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE;

   hcrc.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_ENABLE;

   hcrc.Init.InputDataInversionMode = inputReverse;

   hcrc.Init.OutputDataInversionMode = outReverse;

   hcrc.Init.CRCLength= CRC_POLYLENGTH_32B;

   hcrc.InputDataFormat = inputFormat;

   HAL_CRC_DeInit(&hcrc);

   HAL_CRC_Init(&hcrc);

   uiCRCCalc = HAL_CRC_Calculate(&hcrc, &uiVal, 1);

   return(uiCRCCalc);

}

2 REPLIES 2

There are literally a dozen different "CRC32" implementations based on polynomials, shift direction and endianess.

The ST standard one is unhelpful in it's implementation. I've previously posted examples using bit-reversal, and dealing with trailing bytes that don't fit the word length.

I'd go look for the example(s) but the search here is so broken.

Problem with online calculators is they require no actual understanding.

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

https://community.st.com/s/question/0D50X00009XkbNMSAZ/crc-computation

https://community.st.com/s/question/0D50X00009XkgXtSAJ/programmable-crc-peripheral-in-newer-stm32-devices

I could perhaps port this into current times, but ST support work pays nothing..

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