AnsweredAssumed Answered

Which is valid, upper or lower of CRC_CRC in 16-bit CRC mode?

Question asked by Yasuhiko Koumoto on Feb 24, 2015
Latest reply on May 14, 2015 by Jorge_Gonzalez

Hello experts,

 

I have a question of the crc_demo sample in KINETIS_120MHZ_SC provided by the freescale.

According to Kinetis K70 Reference Manual "35.3.2.1 16-bit CRC", the usage of CRC_CRC is described as below.

 

6. Clear the CTRL[WAS] bit to start writing data values.
7. Write data values into CRC[HU:HL:LU:LL]. A CRC is computed on every data
value write, and the intermediate CRC result is stored back into CRC[LU:LL].
8. When all values have been written, read the final CRC result from CRC[LU:LL].


I think it would be inconsistent with the sample code.

The original code is as follows.

 

  sizeWords = sizeBytes>>1;
  j = 0;
  for(i=0;i<sizeWords;i++){ 
      data_in = (msg[j] << 8) | (msg[j+1]);
      j += 2;
      CRC_CRCH=data_in;                 //DES was CRC_CRC_LOW=data_in; 
  }
  if(j<sizeBytes)
  { 
     pCRCBytes = (uint8_t*)&CRC_CRC;
     *pCRCBytes++ = msg[j];
  }
  data_out=CRC_CRCH;                    //DES was CRC_CRC;

 

I guess it might be as follows.

 

  sizeWords = sizeBytes>>1;
  j = 0;
  for(i=0;i<sizeWords;i++){ 
      data_in = (msg[j+1] << 8) | (msg[j]); // CHANGE
      j += 2;
      CRC_CRCL=data_in;                    // CHANGE 
  }
  if(j<sizeBytes)
  { 
     pCRCBytes = (uint8_t*)&CRC_CRC;
     *pCRCBytes++ = msg[j];
  }
  data_out=CRC_CRCL;                        //CHANGE


Am I not correct?

Can anyone teach me the truth?

 

Best regards,

Yasuhiko Koumoto.

Outcomes