cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F446RCT6 CRC Calculation Regs

utpal kumar
Associate II
Posted on April 20, 2017 at 14:15

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;

 }

 return(ulCRC);

}

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.

Thanks,

Utpal

2 REPLIES 2
Posted on April 20, 2017 at 14:31

Posted on April 20, 2017 at 17:56

The CRC is done 32-bit wide, you'd need to either do it 32-bit at a time or juggle the order of the 4-bytes.

This is one of the design decisions made in the STM32 family that wasn't thought all the way through.

Jan provided a link to code previously posted to illustration functionality required at PC end, or more generally.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..