2024-12-06 05:04 AM - edited 2024-12-06 05:42 AM
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;
2024-12-09 03:43 PM
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
2024-12-09 03:46 PM
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.
2024-12-10 12:09 AM
Hello @davidcodes
Could you please try with changing the default initial value?
hcrc.Init.InitValue= 0x00000000;
hcrc.Init.DefaultInitValueUse =DEFAULT_INIT_VALUE_DISABLE;