Skip to main content
lowpowermcu
Associate III
January 12, 2011
Question

CRC computation

  • January 12, 2011
  • 45 replies
  • 12131 views
Posted on January 12, 2011 at 13:46

CRC computation

#stm-crc32 #stm32f2-crc
This topic has been closed for replies.

45 replies

rc_it
Explorer II
November 30, 2015
Posted on November 30, 2015 at 22:21

It looks like it depends on which part you have for bit reversal and unit sizes. This is from the app note:

I'm using the F4 part and I need byte support so it looks like the hardware doesn't quite cut it.

Tesla DeLorean
Guru
November 30, 2015
Posted on December 01, 2015 at 00:53

Yes, the F4/F2/F1 implementation is somewhat restrictive, but both the M3/M4 cores have a bit reversal instruction. So groups of 4 bytes can be handled directly, and the trailing bytes managed separately.The F3/F0 parts have a more flexible solution.

https://community.st.com/0D50X00009XkgXtSAJ

 

Edit: Fixed broken link, original post from 20-Oct-2015

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
DmtryVovk
Associate II
September 6, 2016
Posted on September 06, 2016 at 18:49

Dear clive, please point me what i am doing wrong. The problem isdifferent CRC on PC and MCU.

//Calculate CRC using hardware stm32 crc modul
for
(i=4; i<64; i= i+4){
CRC->CR |= CRC_CR_RESET;
memcpy
(&temp_32, &UserRxBufferFS[i], 4);
CRC->DR = temp_32; 
//Wrong as PC value
}

//PC side (visual studio). I use your function.
uint32_t i;
CRC_result = 0xFFFFFFFF;
for
(i=4; i<64; i = i+4){
memcpy
(&temp_32, &Output[i] , 4);
CRC_result = Crc32Fast(CRC_result, temp_32);
}
DWORD
Crc32Fast(
DWORD
Crc, 
DWORD
Data)
{
static
const
DWORD
CrcTable[16] = { 
// Nibble lookup table for 0x04C11DB7 polynomial
0x00000000,0x04C11DB7,0x09823B6E,0x0D4326D9,0x130476DC,0x17C56B6B,0x1A864DB2,0x1E475005,
0x2608EDB8,0x22C9F00F,0x2F8AD6D6,0x2B4BCB61,0x350C9B64,0x31CD86D3,0x3C8EA00A,0x384FBDBD };
Crc = Crc ^ Data; 
// Apply all 32-bits
// Process 32-bits, 4 at a time, or 8 rounds
Crc = (Crc << 4) ^ CrcTable[Crc >> 28]; 
// Assumes 32-bit reg, masking index to 4-bits
Crc = (Crc << 4) ^ CrcTable[Crc >> 28]; 
// 0x04C11DB7 Polynomial used in STM32
Crc = (Crc << 4) ^ CrcTable[Crc >> 28];
Crc = (Crc << 4) ^ CrcTable[Crc >> 28];
Crc = (Crc << 4) ^ CrcTable[Crc >> 28];
Crc = (Crc << 4) ^ CrcTable[Crc >> 28];
Crc = (Crc << 4) ^ CrcTable[Crc >> 28];
Crc = (Crc << 4) ^ CrcTable[Crc >> 28];
return
(Crc);
}

Tesla DeLorean
Guru
September 6, 2016
Posted on September 06, 2016 at 20:15

Resetting in every iteration of the loop is probably not helpful.

Suggest you provide a test vector of the data you are pushing through the CRC and the data you are seeing on the PC and MCU side.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
DmtryVovk
Associate II
September 8, 2016
Posted on September 08, 2016 at 08:59

THank you! Now it works fine!