AnsweredAssumed Answered

K64 Hardware CRC generate incorrect results

Question asked by unknowncoder on Oct 19, 2018
Latest reply on Oct 19, 2018 by unknowncoder

Hi, 

I am trying to using the crc driver provided by K64 SDK to generate a 32bit CRC but the result is not correct.

I am comparing the crc value from the hardware to the software implementation below. The software implementation is correct because we use other MCU (SMT32F1) with the same CRC32 polynomial and it produced the correct results.

 

CRC hardware configuration 

config.polynomial = 0x04C11DB7;
config.seed = seed;
config.reflectIn = false;
config.reflectOut = false;
config.complementChecksum = false;
config.crcBits = kCrcBits32;
config.crcResult = kCrcFinalChecksum;

 

CRC software implementation that generates the correct CRC

uint32_t CRC32_Accumulate(uint32_t crc_seed, const uint32_t *const pBuffer, const uint32_t word_len)
{
    ASSERT_DEBUG_RETURN_RELEASE(0 == ((sizeof(uint32_t) * word_len) % sizeof(uint32_t)), 0);

    for( uint32_t word = 0; word < word_len; word++ )
    {
        crc_seed = crc_seed ^ pBuffer[word];

        uint32_t i = 32;

        while( i-- )
        {
            if( crc_seed & 0x80000000 )
            {
                crc_seed = (crc_seed << 1) ^ 0x04C11DB7; // Polynomial used in STM32
            }
            else
            {
                crc_seed = (crc_seed << 1);
            }
        }
    }

    return crc_seed;
}

Outcomes