K64 Hardware CRC generate incorrect results

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

K64 Hardware CRC generate incorrect results

Jump to solution
955 Views
unknowncoder
Contributor III

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;
}
Labels (1)
Tags (2)
0 Kudos
1 Solution
770 Views
unknowncoder
Contributor III

Got it working, I directly setup the register with the following values

    volatile CRC_Type *const base  = CRC0;

    const uint32_t load_value = CRC_CTRL_TCRC(1u) | CRC_CTRL_TOTR(0u) |
                                CRC_CTRL_TOT(0u) | CRC_CTRL_FXOR(0u);

    base->CTRL  = load_value; /*Load initial value*/
    base->GPOLY = 0x04C11DB7u; /*Only now can we set the polynomial*/
    base->CTRL  |= CRC_CTRL_WAS(1u); /*Enable the bit to apply the seed value*/
    base->DATA  = seed;
    base->CTRL  = load_value; /*Start the CRC hardware*/

View solution in original post

1 Reply
771 Views
unknowncoder
Contributor III

Got it working, I directly setup the register with the following values

    volatile CRC_Type *const base  = CRC0;

    const uint32_t load_value = CRC_CTRL_TCRC(1u) | CRC_CTRL_TOTR(0u) |
                                CRC_CTRL_TOT(0u) | CRC_CTRL_FXOR(0u);

    base->CTRL  = load_value; /*Load initial value*/
    base->GPOLY = 0x04C11DB7u; /*Only now can we set the polynomial*/
    base->CTRL  |= CRC_CTRL_WAS(1u); /*Enable the bit to apply the seed value*/
    base->DATA  = seed;
    base->CTRL  = load_value; /*Start the CRC hardware*/