Page 2 of 2
Re: which algorithm to check STM32F4 CRC32
Posted: Mon Oct 28, 2013 12:05 pm
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();
}
Re: which algorithm to check STM32F4 CRC32
Posted: Mon Oct 28, 2013 12:08 pm
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.htmlBy 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.
Re: which algorithm to check STM32F4 CRC32
Posted: Mon Oct 28, 2013 12:09 pm
by efuentes
The stm32f4 has the value 0xFFFFFFFF in it's data register after you set the reset bit.
Awesome! Glad I could help!