AnsweredAssumed Answered

STM32F446RCT6 CRC Calculation Regs

Question asked by kumar.utpal on Apr 20, 2017
Latest reply on Apr 20, 2017 by waclawek.jan

Dear All,

This is regarding the CRC checksum calculator for the STM32F446RC Controller. I am using the internal HW CRC module in F446RC to calculate CRC for UART communication protocol and sending the packet including CRC checksum to the PC end over Serial port. I am  able to receive the complete packet without any data loss/error at the PC end.

 At the PC end i am  using a simple CRC checksum function to validate the CRC. But i am  seeing the difference between the CRC received in data packet and the CRC calculated at the PC end. This may be an issue with CRC program that is used in PC end.

 Here is the C program that we are using at PC end to calculate CRC.


#define CRC32_POLYNOMIAL 0x04C11DB7


unsigned long CRC32Value(int i)
 int j;
 unsigned long ulCRC;
 ulCRC = i;
 for (j=8;j>0;j--)
  if (ulCRC & 1)
   ulCRC = (ulCRC >> 1)^CRC32_POLYNOMIAL;
  else ulCRC >>= 1;
 return ulCRC;

unsigned long CalculateBlockCRC32( unsigned long ulCount, unsigned char *ucBuffer)

 unsigned long ulTemp1;
 unsigned long ulTemp2;
 unsigned long ulCRC = 0;

 while (ulCount-- != 0)
  ulTemp1 = (ulCRC >> 8) & 0x00FFFFFFL;
  ulTemp2 = CRC32Value(((int)ulCRC^*ucBuffer++)&0xff);
  ulCRC = ulTemp1^ulTemp2;


Here is the data Packet:


data[56] = {0x00,0x00,0x00,0x00,0x18,0x00,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x00}


CRC Calculated at uC end : 0x2411F6DD

CRC calculated at PC end : 0x03F6C10A


The polynomial value used at both end are same (0x04C11DB7). But I see a difference in the way CRC is getting calculated in both ends. In F446, input data stream is 32 bit words, but in the PC end program it's calculating for every bytes. I hope this is the main difference for the CRC mismatch, but I couldn't find the right CRC program to use in PC application.


So please share us the correct CRC program to use at the PC end.