K64 Hardware CRC generate incorrect results

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

K64 Hardware CRC generate incorrect results

ソリューションへジャンプ
904件の閲覧回数
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;
}
ラベル(1)
タグ(2)
0 件の賞賛
1 解決策
719件の閲覧回数
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*/

元の投稿で解決策を見る

1 返信
720件の閲覧回数
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*/