CRC Configuration

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CRC Configuration

Jump to solution
1,964 Views
bjrajendra
Senior Contributor I

Hello all,

I'm using codewarrior v2.9 platform for my MPC5602P. I adopted the Example MPC5748G CRC32 GHS614 to implement for MPC5602P. Though I initialized the registers, it is not updating properly.

ie., after the line

 CRC.CNTX[1].CRC_CFG.BIT.POLYG = 1;    /* crcCCITT polynomial is selected */

If I check in the debug window, the registers still show 0. One more interesting thing I found is context is defined as structure array of two. If I do this CRC.CNTX[10100].CRC_CFG.BIT.POLYG = 1 still executes without any errors.

#include "Pictus_Header_v1_09.h"

const uint8_t TextString1[] = {0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x20};

int main(void) {
   volatile int i = 0;
 System_Init();

 CRC.CNTX[1].CRC_CFG.BIT.POLYG = 0;    /* crcCCITT polynomial is selected */
 CRC.CNTX[1].CRC_CFG.BIT.INV = 0;
 CRC.CNTX[1].CRC_CSTAT.H[0] = 0xFFFF;   /* Seed value 0xFFFFFFFF */

   for(i=0; i<sizeof(TextString1)-1; i++) /* size of TextString1 is decreased by 1 due to null character of string */
   {
     *(uint8_t*)&(CRC.CNTX[0].CRC_INP) = TextString1[i];
   }

   /* Loop forever */
   for (;;) {
     i++;
   }
}

Hope some one comes with the solution.

Thanks & Regards,

BJ Rajendranath

0 Kudos
1 Solution
1,280 Views
jamesmurray
Contributor V

Is it correct to seed the register with a 32bit number when using 16bit CRCs?

When testing CRC32 I found that I had to play with the invert bits to get the same output as a standard Linux "crc32" programme. The FS code as supplied didn't match.

I also found that it was slower using the hardware CRC than the software function I already had and that the DMA example was even slower ?!

However, using the hardware CRC and 32bit writes (mind that aligmnent on reads) was optimal.

James

View solution in original post

5 Replies
1,280 Views
bjrajendra
Senior Contributor I

HI,

I finally accessed those registers using their memories. But still the CRC values calculated is not matching.

 *((uint32_t*) 0xFFE68000) = 0;                     /* crcCCITT polynomial is selected */ 
 *((uint32_t*) 0xFFE68008)=0xFFFF0000;   /* Seed value 0xFFFF0000 for crcCCITT */

  *((uint32_t*) 0xFFE68004) = 'A';                  /* input Register going to MSByte*/

I Just sent ASCII parameter 'A' whose CRC value is 0xB915 but I'm getting a CRC value 0x3050.

If I use this statement for Input register

 *(uint8_t*)&(CRC.CNTX[0].CRC_INP) = 'A';   /* input Register going to LSByte*/

The CRC value is 0xB1CA. Still the value is not correct.

Can anyone suggest where I went wrong.

 

Thanks & Regards,

BJ Rajendranath

 

0 Kudos
1,281 Views
jamesmurray
Contributor V

Is it correct to seed the register with a 32bit number when using 16bit CRCs?

When testing CRC32 I found that I had to play with the invert bits to get the same output as a standard Linux "crc32" programme. The FS code as supplied didn't match.

I also found that it was slower using the hardware CRC than the software function I already had and that the DMA example was even slower ?!

However, using the hardware CRC and 32bit writes (mind that aligmnent on reads) was optimal.

James

1,280 Views
bjrajendra
Senior Contributor I

Thanks James,

I got it. Thanks for your support. But I had this question.

Is CRC Module will take only strings for calculating the proper CRC?

Thanks,

Raju.

0 Kudos
1,280 Views
jamesmurray
Contributor V

I'm not sure what you mean? The CRC module takes 8bit, 16bit or 32bit numbers from whatever source and calculates the CRC.

Possibly the most common usage is to calculate the CRC of a data buffer, so that's most likely char type. As I said though, I found that sending it to the CRC module in 4 byte lumps greatly improved performance, but I had to tweak the swap/invert config bits to make it work. (The settings in the AN didn't work for me.)

To get the same results as: http://csbruce.com/software/crc32.c   I used:

CRC_0.CFG.R = 0x00000027; /* CRC-32 polynomial, set to match PC-side crc32 */
To figure that out I wrote code that used all combinations and stepped through in the debugger until I got the answer I wanted...

James

0 Kudos
1,279 Views
bjrajendra
Senior Contributor I

Hi James,

Finally I got it even for integer array also.

 const uint16_t TextString1[] = {0x72,0x61,0x6A,0x75};

I used  for(i=0; i<sizeof(TextString1)-1; i++)  for CRC_INP register. But the sizeof(TextString1) is giving a wrong size for (16 bit )integer array which resulted a wrong CRC.

Instead I used const uint8_t TextString1[] = {0x72,0x61,0x6A,0x75}; giving the right size. Therefore giving the right CRC

Thanks for your support,

Raju

0 Kudos