STM32F407 and CRC
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-01-19 2:55 AM
Hello friends.
I created CRC calculator, but I don't know, how to compare results.
My input data:
uint32_t data[16] = {
0x1234, 0x456, 0x78, 0x09, 0x10, 0x100, 0x1000, 0x01, 0x54, 0x35, 0x98, 0x2432, 0x2255, 0xAEFB, 0xAAAA, 0xFFFF };Function to calculation:
uint32_t CRC_Calculate32(uint32_t* arr, uint32_t count, uint8_t reset)
{ /* Reset CRC data register if necessary */ if (reset) { /* Reset generator */ LL_CRC_ResetCRCCalculationUnit(CRC); }/* Calculate CRC */
while (count--) { /* Set new value */ LL_CRC_FeedData32(CRC, *arr++); }/* Return data */
return LL_CRC_ReadData32(CRC);}
And I call this function:
uint32_t result;
Init_CRC(); result = CRC_Calculate32(data, 16, 1);And result is: 0xb0829f24
#crc32 #stm32f4discovery- Labels:
-
CRC
-
STM32F4 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-01-19 5:06 AM
DF8A8A2B
DF8A8A2B
00001234 00000456 00000078 00000009 00000010 00000100 00001000 00000001
00000054 00000035 00000098 00002432 00002255 0000AEFB 0000AAAA 0000FFFF
B0829F24 test// STM32 CRC32 Test App -
mailto:sourcer32@gmail.com
#include <windows.h>
#include <stdio.h>DWORD Crc32(DWORD Crc, DWORD Data)
{ int i;Crc = Crc ^ Data;
for (i = 0; i < 32; i++)
if (Crc & 0x80000000) Crc = (Crc << 1) ^ 0x04C11DB7; // Polynomial used in STM32 else Crc = (Crc << 1);return (Crc);
}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);
}void test(void)
{ DWORD data[16] = { 0x1234, 0x456, 0x78, 0x09, 0x10, 0x100, 0x1000, 0x01, 0x54, 0x35, 0x98, 0x2432, 0x2255, 0xAEFB, 0xAAAA, 0xFFFF }; DWORD Crc; int i;for (i = 0; i < 16; i++)
printf('%08X ', data[i]);putchar('\n');
Crc = 0xFFFFFFFF; // Initial state
for (i = 0; i < 16; i++) { Crc = Crc32Fast(Crc, data[i]); // 4-bytes at a time }printf('%08X test\n', Crc);
}int main(int argc, char **argv)
{ printf('%08X\n\n', Crc32(0xFFFFFFFF, 0x12345678)); // 0xDF8A8A2B printf('%08X\n\n', Crc32Fast(0xFFFFFFFF, 0x12345678)); // 0xDF8A8A2B test(); return (1);}Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-01-19 6:26 AM
Clive One, thank you.
It looks like very good.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-01-19 6:54 AM
When the forum starts working properly I'll try to edit the post with source code formatting, just can't make that happen in the current state.
Up vote any posts that you find helpful, it shows what's working..
