A very good post. Maybe ST can make an appnote about this subject. After all, CRC is not a trivial subject. So many ways to do it and only one correct.
We want to calculate the CRC check sum for program code which write to the FLASH memory address 0x08010000, we use the CRC peripheral in the STM32 family (Suggested by Mayla) but we get an error message (HardFault Stack_dump registers ) during processing to 27xxxx Bytes. No matter we add more stack size, it always the same result. We do not what the reason? Can anyone help us, thanks! The example is as below~BRAlan=============================#define FLASH_ADDRESS 0x08010000#define PROGRAM_SIZE 358068.....RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_CRC, ENABLE);CRCValue = CRC_CalcBlockCRC((uint32_t *), PROGRAM_SIZE ); //It will cause error inside this subroutine.......RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_CRC, DISABLE);printf(''\r\n CRC Value = 0x%0x\r\n'', CRCValue);
We want to calculate the CRC check sum for program code which write to the FLASH memory address 0x08010000, we use the CRC peripheral in the STM32 family (Suggested by Mayla) but we get an error message (HardFault Stack_dump registers ) during processing to 27xxxx Bytes. No matter we add more stack size, it always the same result. We do not what the reason? Can anyone help us, thanks! The example is as below~BRAlan=============================#define FLASH_ADDRESS 0x08010000#define PROGRAM_SIZE 358068.....RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_CRC, ENABLE);CRCValue = CRC_CalcBlockCRC((uint32_t *)
FLASH_ADDRESS
, PROGRAM_SIZE ); //It will cause error inside this subroutine.......RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_CRC, DISABLE);printf(''\r\n CRC Value = 0x%0x\r\n'', CRCValue);
The ST Library function has a count of 32-bit words, not bytes. Scale your length parameter accordingly.
/**
* @brief Computes the 32-bit CRC of a given buffer of data word(32-bit).
* @param pBuffer: pointer to the buffer containing the data to be computed
* @param BufferLength: length of the buffer to be computed
* @retval 32-bit CRC
*/
uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength)
{
uint32_t index = 0;
for(index = 0; index <
BufferLength
; index++)
{
CRC->DR = pBuffer[index];
}
return (CRC->DR);
}
Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Why the CRC value calculated from ST's CRC_CalcBlockCRC() is different from this one you provided here? We use to read a file and compare the result from each other. The example is as below~