cancel
Showing results for 
Search instead for 
Did you mean: 

CRC32 Calculation STM32L071CBT

davidcodes
Associate

Hi all,
I know similar issues have been discussed before but I have not been able to find another post with the same issue. I am trying to use a CRC32 calculation to validate my flash memory, I am using KEIL IDE and the STM32L071CBT.

This has been my current approach, enabling the HEX file generation on KEIL IDE and using a batch file (used with my after-build option in KEIL)  with the following code:


.\bin\srec_cat .\Device\OutputHexFile.hex -intel -crop 0x08000000 0x0801FFFC -fill 0xFF 0x08000000 0x0801FFFC -crc32-l-e 0x0801FFFC -o .\Device\OutputHexFile_CRC.hex -intel

From my understanding this should calculate the CRC32 (Little-Endian) and place the value at the address 0x0801FFFC. 

I use the HAL peripheral, HAL_CRC_Calculate in my code to calculate the CRC-32 little-endian value:

#define ROM_START     (uint8_t*)(0x08000000)
#define ROM_END       (uint8_t*)(0x0801FFFB)
#define CHECKSUM      (uint8_t*)(0x0801FFFC)

#define ROM_LEN       (uint32_t)(ROM_END - ROM_START + 1u) 
#define ROM_LEN_WORDS ((ROM_LEN + 3u) / 4u)  


uint32_t crc, checksum;


crc = HAL_CRC_Calculate(&hcrc, (uint32_t*)ROM_START, ROM_LEN_WORDS);
checksum = *(uint32_t*)CHECKSUM;
 
Then I compare the checksum and crc variables to check for any issues with the flash memory.

Because my STM32L071CBT has a flash memory size of 128KB.

When I try to print the different variables I get different values, but I thought they should be the same. 

Can I have some actual code example or updates to how I should fix this? Or should I not trust the HAL_CRC_Calculate?
 
12 REPLIES 12

The method of on-line calculation, cited in the original post of that thread, is byte wise, the STM32 does it 32-bit word wise, and with an endian ordering that is unhelpful, ie the LSB is shifted out LAST rather than first.

If you can compile C code on all your platforms, ie host and target, you should be able check and confirm the data processed, and the CRCs computed.

Perhaps start by doing smaller blocks, where you can output and compare a managable subset, side by side.

You could try a one or four word pattern.

You could try just the content of the Vector Table

 

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

I'm not using SRecords or Batch files

What I'm saying is get it to a point where you can do like-for-like comparisons.

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

Hello @davidcodes 

Could you please try with changing the default initial value?

  hcrc.Init.InitValue= 0x00000000;
  hcrc.Init.DefaultInitValueUse =DEFAULT_INIT_VALUE_DISABLE;

 

If your question is answered, please close this topic by clicking "Accept as Solution".

Thanks
Omar