CRC Calculation for 8-bit values
I am experimenting with CRC Calculation on a STM32F4-Discovery.
As I have seen in the reference manual this MCU is using CRC-32 used in Ethernet. I am also using https://crccalc.com/ (CRC-32/MPEG-2) to validate the results.
I just activate the CRC in CubeMX and this is my source code for 32-bit values:
uint32_t raw_data_32_bit[BUFFER_SIZE] = { 0x00, 0x01, 0x10, 0x1A, 0xAC, 0xC0 };
uint32_t crc_value_32_bit = 0;
uint8_t is_error_32_bit = 1;
crc_value_32_bit = HAL_CRC_Calculate(&hcrc, raw_data_32_bit, BUFFER_SIZE);
if (crc_value_32_bit == expected_crc_value_32_bit) {
is_error_32_bit = 0;
}which is working like a charm.
Then I would like to do the same for 8-bit values with this code:
uint32_t expected_crc_value_8_bit = 0xA4541FC6;
uint8_t raw_data_8_bit[BUFFER_SIZE] = { 0x00, 0x01, 0x10, 0x1A, 0xAC, 0xC0 };
uint32_t crc_value_8_bit = 0;
uint8_t is_error_8_bit = 1;
crc_value_8_bit = HAL_CRC_Calculate(&hcrc, (uint32_t *) raw_data_8_bit, BUFFER_SIZE); // returns 0xe7206456
if (crc_value_8_bit == expected_crc_value_8_bit) {
is_error_8_bit = 0;
}but it returns a different result from the result returns from https://crccalc.com/. The only way to make it work is to create a new 32-bit array using this code:
uint32_t data [BUFFER_SIZE];
for (uint8_t i = 0; i < BUFFER_SIZE; i++)
data[i] = raw_data_8_bit[i];
crc_value_8_bit = HAL_CRC_Calculate(&hcrc, data, BUFFER_SIZE);
if (crc_value_8_bit == expected_crc_value_8_bit) {
is_error_8_bit = 0;
}Could someone explain why the 8-bit returns something different from the expected? What am I doing wrong?
