STM32 CRC calculator - Page 1
Forum section: electronics / general

author: Harvs
author_rank: Super Contributor
timestamp: March 21, 2014, 01:51:01 am
content: I'm trying to generate a CRC at both the server end (JAVA) and the device end to compare after transmitting a file via GPRS.The JAVA code just uses the util.zip.CRC32 library and is straightforward. I've checked the output of that against online CRC32 calculators and have no issue.The following 32 byte test string:String input = "DEADBEEFDEADBEEFDEADBEEFDEADBEEF";has a CRC output of: 0x7157cda5I'm using an F4 device. According to the appnote:http://www.st.com/st-web-ui/static/active/en/resource/technical/document/application_note/DM00068118.pdfpage 13, the fixed initial value and polynomial is the same as CRC32 and the same as the JAVA implementation, so in theory they should be the same... right?So I've tried feeding it into the CRC generator in different ways but I can't seem to get a match for the same string. I'm hoping someone has done this before and can see the error of my ways.Code:RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_CRC, ENABLE);uint8_t buffer = "DEADBEEFDEADBEEFDEADBEEFDEADBEEF";CRC_ResetDR();CRC_CalcBlockCRC((uint32_t*)buffer, 32/4);printf("CRC value: %#x", CRC_GetCRC());Gives me an output of: 0x36b4e934

author: Harvs
author_rank: Super Contributor
timestamp: March 21, 2014, 02:23:36 am
content: I thought it may have something to do with endianness. Turns out I was right, if anyone else has this issue see the solutions in this thread:https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2FCRC%20computation&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=4570

author: dannyf
author_rank: Super Contributor
timestamp: March 21, 2014, 11:03:46 am
content: STM32's CRC is basically useless until you are on a F3.For a full featured CRC engine, look at PIC24.The CRC module, as well as the external interrupt module and the "option byte" / "alternate functions" are something ST could have learned from Microchip.

author: Harvs
author_rank: Super Contributor
timestamp: March 21, 2014, 11:41:03 am
content: Quote from: dannyf on March 21, 2014, 11:03:46 amWell I wouldn't go that far. Yes it's missing stuff... But by calling an rbit instruction before each load of the CRC peripheral it outputs the same as CRC32 on a PC. Which given I'm transferring a file from server to it, that's all I need.

author: dannyf
author_rank: Super Contributor
timestamp: March 21, 2014, 03:58:57 pm
content: For a CRC to be useful, you need to have the ability to initialize it, pick your own polonomial, control the shift direction and shift length.ST didn't get there until F3. It is unconscionable that a vendor as reputable as ST could have put such a product out there. Good for them that they eventually figured it out.

author: Harvs
author_rank: Super Contributor
timestamp: March 22, 2014, 01:28:54 am
content: Actually the thing it's missing for me is the ability to work on byte wide data. Can the PIC24 do that?It means having to implement the CRC32 algorithm in software for the last 1 to 3 bytes of data in an arbitrary length file, which is rather annoying. Yeah I could expand the file on the PC before adding the CRC, but it's still annoying.

author: miguelvp
author_rank: Super Contributor
timestamp: March 22, 2014, 07:26:50 pm
content: Quote from: Harvs on March 22, 2014, 01:28:54 amAll you want to know about CRC algorithms with many different implementations and approaches:http://www.csm.ornl.gov/~dunigan/crc.htmlEdit: another link of someone's implementation for embedded systems based on that paper linked above:http://www.barrgroup.com/Embedded-Systems/How-To/CRC-Calculation-C-Code