Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: FastCRC on Teensy 4.0 - Change CRC init value?

  1. #1
    Junior Member
    Join Date
    Mar 2018
    Posts
    15

    FastCRC on Teensy 4.0 - Change CRC init value?

    Hi there,

    Hoping to get the attention of the FastCRC library creator, Frank B.

    I've got a project I'm trying to transition from Teensy 3.2 to Teensy 4.0. It uses FastCRC to create a 16-bit CRC, but it requires a CRC init that is neither 0x0000 or 0xFFFF. I've been using the generic function as a result, and this has been terrific. I realise hardware CRC support isn't yet enabled for the Teensy 4.0 on the FastCRC library, so I've been trying the kermit or mcrf4xx functions with a modified init value in FastCRCsw.cpp, but this does not yield the same (correct) result that the generic function did on the T3.2. Do the tables only support 0x0000 or 0xFFFF ?

    This is what worked on the T3.2:

    CRC16.generic(0x1021, 0xabcd, CRC_FLAG_REFLECT, datainput, 14);

    Any thoughts?

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,920
    Quote Originally Posted by quiver View Post
    Any thoughts?
    Yes The Teensy 4 has a different CRC Hardware that can not be used.

    The Teensy 3 uses a register to store the seed, the software-variant uses a variable:
    Code:
    class FastCRC16
    {
     ...
    private:
    #if CRC_SW
      uint16_t seed;
    ...
    #endif
    ...
    
    
    uint16_t FastCRC16::mcrf4xx(const uint8_t *data,const uint16_t datalen)
    {
     // poly=0x1021 init=0xffff refin=true refout=true xorout=0x0000 check=0x6f91
      seed = 0xffff;
      return mcrf4xx_upd(data, datalen);
    }
    So either create a setter for the seed, or add a new CRC variant (Just copy the code from mcrf4xx and modify the seed, or if you don't mind to do it "hackish" just edit the seed value for mcrf4xx)

    Have fun,
    Frank.
    Last edited by Frank B; 03-23-2020 at 08:23 AM.

  3. #3
    Junior Member
    Join Date
    Mar 2018
    Posts
    15
    Hi Frank,

    Thanks for your speedy reply!

    You described exactly what I've tried though, and I don't get the correct sum.. You can replicate this by doing the above on a Teensy 3.2 and a Teensy 4.0. If you have an irregular seed, the checksum is different.. and the T3.2 is correct..

  4. #4
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,920
    Looks like you need to use it bit-reversed -> use 0xB3D5 as seed.

  5. #5
    Junior Member
    Join Date
    Mar 2018
    Posts
    15
    That does appear to work. Thanks!

  6. #6
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,920
    You're welcome.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •