cancel
Showing results for 
Search instead for 
Did you mean: 

CRC calculation unit gives bit reversed result

ericbrocke9
Associate II
Posted on November 18, 2009 at 12:04

CRC calculation unit gives bit reversed result

9 REPLIES 9
ericbrocke9
Associate II
Posted on May 17, 2011 at 12:41

I'm using the CRC calculation unit and it seems that the result of the data register (CRC_DR) is bit-reversed and bit-wise inverted.

Entering 0x00000000 gives 0xC704DD7B as result which should be 0x2144DF1C (using srec).

See also:

http://zorc.breitbandkatze.de/crc.html

http://www.lammertbies.nl/comm/info/crc-calculation.html?crc=00000000&method=hex

Can anyone (from ST) confirm this? And what is the reason for this behaviour?

ericbrocke9
Associate II
Posted on May 17, 2011 at 12:41

Addition:

The reset value of the CRC_DR is 0xFFFFFFFF and not 0x00000000 as mentioned in the Reference Manual (RM0008 Rev 5).

16-32micros
Associate III
Posted on May 17, 2011 at 12:41

Hi Eric,

One correction : the reset value is 0x00000000 as described in the RM0008.

You can check it easily after reset. The CRC clock is disabled by default so all the digital parts and registers are 0. However, once enabled it initializes to 0xFFFFFFFF.

Cheers,

STOne-32.

ericbrocke9
Associate II
Posted on May 17, 2011 at 12:41

Hi STOne-32,

You are right about the reset value. I'd make a mistake about reading the value after enabling the CRC clock.

What abbout the first CRC issue?

Thanks,

Eric.

mjohansson
Associate II
Posted on May 17, 2011 at 12:41

Did you get anywhere on this? I'm also trying to use the hw CRC calculation unit and I'm getting the same results as you and not the results I'm expecting.

16-32micros
Associate III
Posted on May 17, 2011 at 12:41

Hi,

Here is attached an equivalent algorithm to the embedded one and is written in C that you can use :) to check the results ... Enjoy it { just change .txt to .c }

Cheers,

STOne-32.

[ This message was edited by: STOne-32 on 19-01-2009 17:16 ]

ericbrocke9
Associate II
Posted on May 17, 2011 at 12:41

Here is a code snippet to do the job:

static u32 rbit(u32 d)

{

__asm__ (

'' rbit %0, %0''

: ''=r'' (d)

: ''0'' (d)

: ''cc''

);

return d;

}

void foo(void)

u32 *p, crc32;

p = ...;

Crc.CR.bit.RESET = 1;

while ( ... ) {

Crc.DR = rbit(*pd++);

}

crc32 = rbit(Crc.DR) ^ 0xFFFFFFFF;

}

The toolchain I used was CoudeSourcery. It doesn't have an intrisic function to do the bitreverse, So I made an inline function who use the Thumb-2 instruction 'rbit'.

spam3
Associate II
Posted on May 17, 2011 at 12:41

I seem to have different results with a stm32f107 chip. I was expecting what Eric got (0xC704DD7B) but instead the chip returned 0x552d22c8.

void foo(void)

{

CRC->CR = CRC_RESET;

/* CRC->DR is now 0xffffffff */

CRC->DR = 0x00000000;

/* CRC->DR is now 0x552d22c8 */

}

Can anyone tell me if i overlooked something?

swhite
Associate III
Posted on May 17, 2011 at 12:41

Try reading my post on the subject.

http://www.st.com/mcu/forums-cat-8643-23.html