GithubHelp home page GithubHelp logo

fastcrc's Introduction

FastCRC

Fast CRC Arduino library Up to 30 times faster than crc16.h (_avr_libc)

  • uses the on-chip hardware for Teensy 3.0 / 3.1 / 3.2 / 3.5 / 3.6
  • uses fast table-algorithms for other chips

List of supported CRC calculations:

7 BIT:

CRC7 (poly=0x09 init=0x00 refin=false refout=false xorout=0x00 check=0x75) MultiMediaCard interface

8 BIT:

SMBUS (poly=0x07 init=0x00 refin=false refout=false xorout=0x00 check=0xf4)

MAXIM (poly=0x31 init=0x00 refin=true refout=true xorout=0x00 check=0xa1)

16 BIT:

KERMIT (Alias CRC-16/CCITT, CRC-16/CCITT-TRUE, CRC-CCITT) (poly=0x1021 init=0x0000 refin=true refout=true xorout=0x0000 check=0x2189 Attention: sometimes you'll find byteswapped presentation of result in other implementations)

CCITT-FALSE (poly=0x1021 init=0xffff refin=false refout=false xorout=0x0000 check=0x29b1)

MCRF4XX (poly=0x1021 init=0xffff refin=true refout=true xorout=0x0000 check=0x6f91)

MODBUS (poly=0x8005 init=0xffff refin=true refout=true xorout=0x0000 check=0x4b37)

XMODEM (Alias ZMODEM, CRC-16/ACORN) (poly=0x1021 init=0x0000 refin=false refout=false xorout=0x0000 check=0x31c3)

X25 (Alias CRC-16/IBM-SDLC, CRC-16/ISO-HDLC, CRC-B) (poly=0x1021 init=0xffff refin=true refout=true xorout=0xffff check=0x906e)

32 BIT:

CRC32, CRC-32/ADCCP, PKZIP, ETHERNET, 802.3 (poly=0x04c11db7 init=0xffffffff refin=true refout=true xorout=0xffffffff check=0xcbf43926)

CKSUM, CRC-32/POSIX (poly=0x04c11db7 init=0x00000000 refin=false refout=false xorout=0xffffffff check=0x765e7680)

fastcrc's People

Contributors

boscs avatar frankboesing avatar frankleonrose avatar gitmodu avatar imwhocodes avatar kenneththompson avatar paulstoffregen avatar per1234 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fastcrc's Issues

FastCRC lib question

Frank, can I use this to calculate the CRC for AD74412R?

From the data sheet:
SPI CRC:
To ensure that data is received correctly in noisy environments, the AD74412R has a CRC implemented in the SPI interface. This CRC is based on an 8-bit CRC. The device controlling the AD74412R generates an 8-bit frame check sequence using the following polynomial:
C(x) = x8 + x2 + x1 + 1
This frame check sequence is added to the end of the data-word, and the 32-bit data-word is sent to the AD74412R before taking the SYNC high pin.
The user must supply a frame 32 bits wide containing the 24 data bits and 8 CRC bits. If the CRC check is valid, the data is written to the selected register. If the CRC check fails, the data is ignored, the SPI_CRC_ERR status bit in the ALERT_STATUS register is asserted, and the ALERT pin goes low.

It looks like the FastCRC is for BYTES and this device is using bits.

Am i wrong and can i use your lib for BITs?

Lib don't work on ESP8266 Arduio

Dear Frank,

Would you please make possible to use you great lib on ESP82266 also?

I propose it could be done by changing header file from
#include <avr/pgmspace.h>
to something like this:
#ifdef AVR
#include <avr/pgmspace.h>
#elif defined(ESP8266)
#include <pgmspace.h>
#endif

Thanks in advance!

SAM3X8E

Does the Arduino DUE (SAM3X8E) have whatever hardware features you are using for the hardware acceleration?

Or to put it another way, can your hardware CRC library be tweaked to run on the DUE?

MODBUS CRC does not seem to deliver correct value

Dear Frank,

thank you for your great work. I tried to use your library to calculate a CRC for MODBUS use. However, when I compare the output of your library for FastCRC16 MODBUS with the CRC Calculator https://crccalc.com/, then the output doesn´t match.
For other CRC methods, the outputs are identical.

For example belowmodified example of yours delivers "0x25B4" as a result, while CRCCalc delivers "0x2590". REsults in case of KERMIT or CCITT are identical for your library and CRCCalc. Is there anything I do wrong, or is there an issue with the library?

/*
FastCRC-Example
(c) Frank Boesing 2014
*/
#include <Arduino.h>
#include <FastCRC.h>

FastCRC16 CRC16;

uint8_t buf[5] = {0x12, 0x34, 0x56, 0x78, 0x09 };

void setup() {

delay(1500);
Serial.begin(115200);

Serial.println("CRC Example");
Serial.println();

Serial.print("MODBUS-CRC of "");

for (unsigned int i = 0; i < sizeof(buf); i++) {
Serial.print((char) buf[i]);
}

Serial.print("" is: 0x");
Serial.println( CRC16.modbus_upd(buf, sizeof(buf)), HEX );

}

void loop() {
}

Thanks for checking,
Holger

Use with microcontroller without EEPROM

I'm trying to use this with the nRF52840 from Sparkfun. I cannot get the FastCRC to work:

In file included from C:\Users\Mariu\Documents\Arduino\libraries\FastCRC2\FastCRCsw.cpp:38:0:
C:\Users\Mariu\Documents\Arduino\libraries\FastCRC2\FastCRC_tables.h:38:23: fatal error: pgmspace.h: No such file or directory

I'm already using it on Teensy 3.6 with no problems.

Library name is already in use (PlatformIO)

When installing through PlatformIO Library Manager, the library failed to compile. When I downloaded the zip of the master branch and added manually in my project it worked. Then I noticed that, although library.json and library.properties say version is 1.31, since the commits are not tagged PlatformIO downloaded the last tagged commit/release, 1.0.

In fact, I checked again, and this problem happened because your library has the same name as another. As a consequence, when adding "FastCRC" in lib_deps (inside platformio.ini), the other library that has a smaller ID is installed instead of this one.

The other library: https://platformio.org/lib/show/3576/FastCRC
Your library: https://platformio.org/lib/show/6497/FastCRC

KINETISK defintion

I tried latest version of FastCRC on teensy K66. Benchmark hardware times were slow??
You are using __ KINETISK __ instead of KINETISK. On my copy, I fixed those, but still had to add

include "Arduino.h" to the .cpp files

Slim version

I am really keen on using this in my arduino project, but it is so large there isnt enough room for my project. I am specifically looking for a crc16 and dont care about the crc8 or crc32 stuff. Is there is good way you are aware of to easily trim down the lib a bit? Thanks!

support buffers larger than 64K

Not real critical, but I noticed I couldn't do CRC on buffer larger than 64KB, because benchmark and library uses uint16_t for datalen. It will be a bit messy to change all of those to uint32_t

whatever.

Wrong checksum by 1 - about 2s Complement to checksum

Hello, I've found that my calculated checksum (needed for machine) is "2s Complement", so your script is not 100% accurate without it - can we easily fix it? And do you know how to?
Your script checksum value: 0x3B
Expected checksum value: 0x3A - 2s Complement

Issue on Due

I get an error with the pgmspace.h included in FastCRC_tables.h. There is no such file for the Due. Your library works great on the Mega, but when I switched to a Due, it failed there. I just commented that line out (# 37), and everything is working fine. Otherwise, thanks for the great library!

Any way of doing multiple simultaneous calculations on Kinetis/Teensy?

Firstly a huge thank you for the library! I've been using it for some time now and it works really well on both Teensy and AVR based boards.

I've come across a scenario where I need to have multiple CRC calculations happening in parallel as they each await data to come in over serial. I can create 2 instances of FastCRC32 and continually call crc32_upd() which works fine on AVR, but on Teensy boards it will fail due to it trying to use the same hardware for both calculations.

As far as I can see there is no way of forcing software calculation on Teensy boards due to the whole sw file being wrapped in a #if !defined(KINETISK) check?

I understand this is a fairly niche requirement, but I thought I'd check if there's anything I'm missing that might allow this to work.
Thanks again for all your work on this!

seed is not initialized if only calling updates

Hi,

I had a use case where I was iterating through data in a loop and wanted to start by using the update method immediately. This produced incorrect CRC values because the member variable seed wasn't initialized. See the following simple example using the kermit CRC16 model:

FastCRC16 CRC16;
unsigned short crc = 0x0000;

for (int i=0; i<data_len; i++)
{
    byte data = get_next_byte();
    crc = CRC16.kermit_upd(&data, 1);
}

In my case, get_next_byte() was the equivalent of getting the next byte of data from EEPROM and I didn't want to copy it into ram first. I am working with an Arduino Uno, so it is using the SW implementation.

Given the way you have grouped the different models into classes by CRC length, I don't see an obvious way to address this. Here are some suggestions:

  • Separate CRC models into their own classes and initialize seed in the constructor.
  • Add a member variable to keep track of whether it has been initialized or not.
  • At a minimum, add a note to the readme indicating that the model method must be called before its *_upd method.

As a workaround, I could call the kermit method on the first byte and continue iterating through the rest with the kermit_upd method, but that seems unnecessarily messy.

Thanks for taking a look at this.

Results does not match?

Hello,
I've got a little stuck with this library.

I have a buffer of:

00 01 01 33 01 00 00 e9 41 20 59 ad

to CRC but I'm having hard time getting proper results. Lets get [3] element from the array 0x33 which is 51. While this:

Serial.println( CRC16.ccitt("51", 2), HEX );

gave me correct result of 0xC11D i cant for the love of God make it out of my buffer. I've tried casting all the types back and forth - with whole bunch of different results but never the correct one: 0xC11D.
Could you please advice?

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.