Author Topic: STM32 CRC calculator  (Read 15183 times)

0 Members and 1 Guest are viewing this topic.

Offline HarvsTopic starter

  • Super Contributor
  • ***
  • Posts: 1202
  • Country: au
STM32 CRC calculator
« on: March 21, 2014, 01:51:01 am »
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: 0x7157cda5

I'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.pdf
page 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: [Select]
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_CRC, ENABLE);
  uint8_t buffer[32] = "DEADBEEFDEADBEEFDEADBEEFDEADBEEF";
  CRC_ResetDR();
  CRC_CalcBlockCRC((uint32_t*)buffer, 32/4);
  printf("CRC value: %#x", CRC_GetCRC());

Gives me an output of: 0x36b4e934
 

Offline HarvsTopic starter

  • Super Contributor
  • ***
  • Posts: 1202
  • Country: au
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: STM32 CRC calculator
« Reply #2 on: March 21, 2014, 11:03:46 am »
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.
================================
https://dannyelectronics.wordpress.com/
 

Offline HarvsTopic starter

  • Super Contributor
  • ***
  • Posts: 1202
  • Country: au
Re: STM32 CRC calculator
« Reply #3 on: March 21, 2014, 11:41:03 am »
STM32's CRC is basically useless until you are on a F3.

Well 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.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: STM32 CRC calculator
« Reply #4 on: March 21, 2014, 03:58:57 pm »
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.
================================
https://dannyelectronics.wordpress.com/
 

Offline HarvsTopic starter

  • Super Contributor
  • ***
  • Posts: 1202
  • Country: au
Re: STM32 CRC calculator
« Reply #5 on: March 22, 2014, 01:28:54 am »
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.
 

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5550
  • Country: us
Re: STM32 CRC calculator
« Reply #6 on: March 22, 2014, 07:26:50 pm »
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.

All you want to know about CRC algorithms with many different implementations and approaches:

http://www.csm.ornl.gov/~dunigan/crc.html

Edit: 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
« Last Edit: March 22, 2014, 08:14:09 pm by miguelvp »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf