AnsweredAssumed Answered

Crc computation on K24 chip

Question asked by June on Aug 1, 2019
Latest reply on Aug 5, 2019 by Alexis Andalon

Hi,

I'm performing crc computation on K24 chip during run-time. As the address range to compute the crc is quite huge, it is broken up into several cycles. How to have the chip start a new calculation using an intermediate crc value from the previous calculation?

 

For example:

cycle 1: crc1 = Calculated crc from address 0x0001 to 0x0020

cycle 2: crc2 = calculated crc from crc1 and address 0x0021 to 0x0040

and so on...

 

How should crc1 be parsed in during cycle 2? As seed value or as a data?

Here's my code but it doesn't work:

<code>

static uint32_t Crc32(uint32_t const * const pData, uint32_t numLongs, uint32_t initCrc)

{

   // Steps #1 and #2

   CRC_CTRL = (CRC_CTRL_TOT(2U)) | // Input bits & bytes are transposed

   (CRC_CTRL_TOTR(2U)) | // Output bits & bytes are transposed

   (0UL << CRC_CTRL_WAS_SHIFT) | // Ready to write data

   (1UL << CRC_CTRL_TCRC_SHIFT); // 32-bit CRC

 

   // Step #3

   CRC_GPOLY = 0x04C11DB7; // CRC32 polynomial

 

   // Step #4 - Indicate seed will be written

   CRC_CTRL = (CRC_CTRL_TOT(2U)) | // Input bits & bytes are transposed

   (CRC_CTRL_TOTR(2U)) | // Output bits & bytes are transposed

   (1UL << CRC_CTRL_WAS_SHIFT) | // Ready to write seed

   (1UL << CRC_CTRL_TCRC_SHIFT); // 32-bit CRC

 

   // Step #5 - Write seed

  CRC_DATA = initCrc;

 

   // Step #6 - Indicate that data follows

   CRC_CTRL = (CRC_CTRL_TOT(2U)) | // Input bits & bytes are transposed

   (CRC_CTRL_TOTR(2U)) | // Output bits & bytes are transposed

   (0UL << CRC_CTRL_WAS_SHIFT) | // Ready to write data

   (1UL << CRC_CTRL_TCRC_SHIFT); // 32-bit CRC

 

   // Step #7 - Write the data values.

   for (uint32_t i = 0; i < numLongs; i++)

  {

    CRC_DATA = pData[i];

  }

 

   // Step #8 - Return CRC result.

   return CRC_DATA;

}

  

// Note: the following is a pseudo code just to illustrate the logic

// The following doesn't work. What's wrong?

main()

{

  while (!crcDone)

  {

     readData(&data[0]);

     if (cycle1)

     {

       crc = crc32(data[0], numBytes, 0xFFFFFFFFUL);

     }

     else

     {

       crc = crc32(data[0], numBytes, crc);

     }

  }

  CompareCrcWithStoredCrc();

}

 

// I have also tried the following but it doesn't work either:

main()

{

  while (!crcDone)

  {

     readData(&data[4]);

     if (cycle1)

     {

       crc = crc32(data[4], numBytes, 0x0UL);

     }

     else

     {

       memcpy(&data[0], &crc, 4);

       crc = crc32(data[0], numBytes+4, 0x0UL);

     }

  }

  CompareCrcWithStoredCrc();

}

 

<code>

 

Appreciate some advice. Thanks!

Outcomes