CRC-32 Parameters Used in Cypress S26KL-S/S26KS-S HyperFlash™ Family - KBA223179

Version: **

 

Question:

What polynomial, initial value, and output XOR value should I use for the software-based CRC-32 calculator to get the same result with HyperFlash’s hardware CRC-32 calculator?

 

Answer:

The hardware CRC-32 calculator incorporated in the HyperFlash family of devices uses the following parameters:

Parameter

Value

Polynomial

0x1EDC6F41

Initial Value

0x00000000

Output XOR Value

0x00000000

Input Reflection

No

Output Reflection

No

The polynomial, 0x1EDC6F41, is commonly represented by:

X32 + X28 + X27 + X26 + X25 + X23 + X22 + X20 + X19 + X18 + X14 + X13 + X11 + X10 + X9 + X8 + X6 + 1


In addition to the CRC-32 parameters, you must take care of the data order used in the HyperFlash’s CRC-32 calculator as shown in the following screenshot.

 

Untitled.png

For example, if the Lower Order Word and the Higher Order Word are 0xF42D and 0x8CCF respectively, and the software-based CRC-32 calculator takes 8-bit byte stream, the input data bytes should be in the order of 0xF4-0x2D-0x8C-0xCF.

The following C source code and table provides a simple software CRC-32 calculator example and some results for reference.

uint32 Calculate_CRC32(const uint8 *byte_data, uint32 byte_count)

{

       uint32 pos, i;

       uint32 crc = 0; /* Initial Value */

 

       for (pos = 0; pos < byte_count; pos++)

       {

              crc ^= (uint32)(byte_data[pos] << 24);

 

              for (i = 0; i < 8; i++)

              {

                     if ((crc & 0x80000000) != 0)

                           crc = (uint32)((crc << 1) ^ 0x1EDC6F41); /* Polynomial */

                     else

                           crc <<= 1;

              }

       }

 

       return crc;

}

 

void Test_CRC32(void)

{

       uint16 sample_data[4] = {0xF42D, 0x8CCF, 0xF646, 0x3129};

       uint32 crc;

 

       /* Swap byte order for Little Endian systems */

       uint32 i;

       for (i = 0; i < 4; i++)

       {

              sample_data[i] = ((sample_data[i] >> 8) & 0xFF) | ((sample_data[i] & 0xFF) << 8);

       }

 

       crc = Calculate_CRC32((uint8 *)sample_data, 8);

 

       printf("CRC-32: %08X\n", crc);

}

 

Sample Data

CRC-32 Value

0xF42D 0x8CCF 0xF646 0x3129

0x22531137

0xFFFF 0xFFFF 0xFFFF 0xFFFF

0xB29FF223

0x0123 0x4567 0x89AB 0xCDEF

0xBAA822E2