This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF8002 - CRC calculation for configuration file

Hi,

i have a question relative to the configuration tool File Format.

I'd like to modify (automatically) the configuration file in order to change the "Device Name" field and customize it for each product before to record configuration in OTP.

I tried to do this with a basic text editor and then flash the configuration file. However, in that case the CRC calculation falls into error...

Is it possible to detail the CRC calculation made in order to generate a new valid CRC after file modification ??

Best Regards,

  • The nRF8002 uses CRC-16-CCITT, this covers the packet header and data.

    A Command Frame is built up like this:
    Name, Size, Description
    Header
    Length, 1, Packet length excluding itself
    SeqNo, 1, Sequence number
    Data
    CfgData, 0..60, Serialized configuration data
    CRC
    CRC, 2, CRC-16-CCITT covering header and data

    uint16_t crcproduct = 0x0000, data_len = 0x0000;
    uint16_t crc = 0xffff;
    
    uint16_t crc_16_ccitt(uint16_t crc, uint8_t * data_in, uint16_t data_len)
    {
      uint16_t i;
    
      for(i = 0; i < data_len; i++)
      {
        crc  = (unsigned char)(crc >> 8) | (crc << 8);
        crc ^= data_in[i];
        crc ^= (unsigned char)(crc & 0xff) >> 4;
        crc ^= (crc << 8) << 4;
        crc ^= ((crc & 0xff) << 4) << 1;
      }
      return crc;
    }
    
    data_len = sizeof setup1; //remember to remove the old CRC
    crcproduct = crc_16_ccitt(crc, &setup1 [0], data_len);
    
  • Hi Runar,

    thanks for your answer, i tried your code on a config file (made of 436 bytes), and applied the calculation from bytes 1 to 435 (excluding Crc). The result i obtained if 0x05 instead of 0x6f. Do you have an idea what is wrong ? i used the default configuration of Nrf Gostudio

    Best Regards

  • Runar, sorry it's ok now i've understand your answer. Regards

Related