2011-01-12 04:46 AM
2011-05-17 05:21 AM
The bit reverses on the data and the CRC register above relate to making the STM32's CRC perform a computation which matches the polynomial, and inverse conditions of the one used by PKZIP.
The issues are related to endian, and shift direction. In my opinion the choices by ST were particularly bad. The code snippet from the second post to this thread will allow you to validate the 32-bit computation used by the STM32. It will work on small-endian machines, and does validate the numbers you were seeing.2011-06-17 02:13 AM
CRC computation does not work!
Hi, I am completely stuck -- the STM32 does not compute any CRC value for me -- I always read zero from the CRC_DR register. I just used the standard peripheral library V3.5.0. My test code is: #include ''stm32f10x_crc.h'' uint32_t crc; const uint32_t crctestdata[] = { 0x01020304, 0x05060708, 0x090a0b0c, 0x0d0e0f00}; void test(void) { CRC_ResetDR(); crc = CRC_CalcBlockCRC(crctestdata, 4); } I am using the STM32F10ZGT on an STM3210E-EVAL board. Regards Dirk2011-06-17 03:14 AM
the STM32 does not compute any CRC value for me -- I always read zero from the CRC_DR register.
Yeah, that sounds like the clock has not been enabled. RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC, ENABLE);
2011-06-17 04:43 AM
2011-06-29 04:44 AM
The function uint32_t revbit(uint32_t data) doesnt work for me.
I get the same data as were inserted.
I was trying debug it, Assembler part - asm(''rbit r0,r0''); - works but function doesnt return register R0.
Thanks.
2011-06-29 09:15 AM
The functionuint32_t revbit(uint32_t data) doesnt work for me.
I get the same data as were inserted.
I was trying debug it, Assembler part -asm(''rbit r0,r0''); -works but function doesnt return register R0.
It is a cheap hack. I'd probably write the whole thing in assembler myself, and in-line, the code was provided as a quick demonstration / proof of concept. The assembler I'd expect for the function would be revbit: rbit r0,r0 bx lr Or you could just implement it in C u32 revbit(u32 data) { int i; u32 rev = 0; for(i=0; i<32; i++) rev |= ((data >> i) & 1) << (31 - i); return rev; }; What tool chain are you using? This was based on the IAR code providedhttps://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/CRC calculation in software&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=2175
, it probably will require attention with Keil or GNU.2011-06-29 11:42 AM
In Keil
__asm u32 revbit(u32 data) { rbit r0, r0 bx lr }2012-06-15 10:21 AM
If I have for example an a vector with the following datas
[0x01][0x04][0x75][0x54][0x00][0x02] I know that the CRC with 6bytes result [0x2A][0x17] How can I convert this data for to use this function????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);
} THANKS!!!!2012-06-15 11:28 AM
If I have for example an a vector with the following datas [0x01][0x04][0x75][0x54][0x00][0x02]
I know that the CRC with 6bytes result [0x2A][0x17]
Looks like you have a 16-bit CRC, not sure the 32-bit method is applicable. Any hint on the protocol or bus being used here?
2012-06-16 09:51 PM
I typed in ''01 04 75 54 00 02'' (Hex) to this on-line CRC calculator,
http://www.lammertbies.nl/comm/info/crc-calculation.htm CRC-16 (Modbus) results in 0x172A Of course, double check is required. Tsuneo