CRC32 Calculation STM32L071CBT
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;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?
