cancel
Showing results for 
Search instead for 
Did you mean: 

CRC computation

lowpowermcu
Associate II
Posted on January 12, 2011 at 13:46

CRC computation

#stm-crc32 #stm32f2-crc
45 REPLIES 45
Posted on November 21, 2015 at 14:39

So you pick the guy who's post count to the forum is ONE, and hasn't posted in TWO years?

Yes, it doesn't look like he sets crc_reg in that case, probably want a crc_reg = CRC->DR

Seem to think I posted a working example earlier in the thread, where it does the last byte in software. But the purpose of writing crc_reg back into the register is that it causes the math to zero it out.

Please don't use the U and Ur abbreviations, you're not texting

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
rc
Associate II
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.

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 Venmo
Up vote any posts that you find helpful, it shows what's working..
DmtryVovk
Associate II
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);
}

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 Venmo
Up vote any posts that you find helpful, it shows what's working..
DmtryVovk
Associate II
Posted on September 08, 2016 at 08:59

THank you! Now it works fine!