which algorithm to check STM32F4 CRC32

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

jarekl
Posts: 17
Joined: Tue Oct 15, 2013 11:32 am

Re: which algorithm to check STM32F4 CRC32

Post by jarekl »

Ok. My bad. I didn't apply the change to RBIT() consistently. This code works !!! Thanks a lot

Code: Select all

#define crcReset() (CRC->CR = 1)
#define crcRead() (__RBIT(CRC->DR) ^ 0xFFFFFFFF)
#define crcWrite(x) {CRC->DR = __RBIT(x);}
uint32_t
crc32(uint32_t *p, int len)
{
   int i;
   crcReset();
   for ( i = 0; i < len; i++)
      crcWrite(p[i]);
   return crcRead();
}
efuentes
Posts: 35
Joined: Wed Jul 25, 2012 6:16 am

Re: which algorithm to check STM32F4 CRC32

Post by efuentes »

That's a little strange. I am positive that __RBIT is correct and I use the macros in the exact same way almost everyday as part of a bootloader.

The only thing that I can think of is to check in the initial conditions of whatever tool you use on your computer.

In order to calculate the crc32 on my computer, I have been using python's binascii module: http://docs.python.org/2/library/binascii.html

By default, the binascii module loads 0 into it's internal data register where as the stm32f4 has the value 0xFFFFFFFF in it's data register after you set the reset bit.

This caused a bit of trouble on my end if you can imagine :) . Once I made sure they both started with the same initial conditions and I made those modifications to reading and writing to the data register, the two implementations have matched up extremely well.
efuentes
Posts: 35
Joined: Wed Jul 25, 2012 6:16 am

Re: which algorithm to check STM32F4 CRC32

Post by efuentes »

The stm32f4 has the value 0xFFFFFFFF in it's data register after you set the reset bit.


Awesome! Glad I could help!
Post Reply