CRC calculation on nRF52840

Hi,

I am using nrf52840 and SDK17.1.0.

I need to calculate CRC16 for communication with an another module. I found that we have an API for that. I would like to know what CRC calculation method the function sys_crc_t sys_crc_calc (const uint8_t * p_data, size_t length) uses. Does it use the same one as CRC16 compute, which is "CRC-16-CCITT (polynomial 0x1021) with 0xFFFF initial value". If not what does it use and does it have any advantages in terms of memory usage, speed, configuration or anything else?

Best,

D

Parents
  • Hi,

    Both of the functions you mention does CRC calculations from a given array of data.

    crc16_compute() uses CRC-16-CCITT (polynomial 0x1021, that is x^16 + x^12 + x^5 + 1) with initial value of 0xFFFF (default) or the value you provide (via value pointed to by non-null p_crc).

    The above CRC calculation is also described in the Bluetooth Core Specification, then described as the "CCITT generator polynomial g(D) = D^16 + D^12 + D^5 + 1 (i.e. 210041 in octal representation)".

    The function is found in the HCI transport library of the SDK, which indicates it is used by Bluetooth Host Controller Interface (HCI).

    sys_crc_calc() uses CRC-16-ANSI (polynomial 0x8005, that is x^16 + x^15 + x^2 + 1,) with 0x0000 initial value.

    The function is found as part of the 802.15.4 stack API, which is a precompiled library distributed as part of the nRF5 SDK. It has been used for samples and testing, but is currently not used from anywhere within the nRF5 SDK. (I was not able to find any internal uses within the 802.15.4 library either.)

    To answer your questions:

    Does it use the same one as CRC16 compute

    No, the polynomials differ.

    If not what does it use and does it have any advantages in terms of memory usage, speed, configuration or anything else?

    I am afraid we do not have any clear answer to this, apart from what polynomials and initial values are used, but with that knowledge I am sure there is extensive litterature to be found describing drawbacks and advantages for each of them.

    As for the implementations used in the SDK, one uses more operations but consistent branching while the other uses fewer operations but includes an if/else statement. It is hard to tell which one has the better performance (if there is a noticeable difference at all), but I suggest you to do some testing if this is important to you.

    Regards,
    Terje

Reply
  • Hi,

    Both of the functions you mention does CRC calculations from a given array of data.

    crc16_compute() uses CRC-16-CCITT (polynomial 0x1021, that is x^16 + x^12 + x^5 + 1) with initial value of 0xFFFF (default) or the value you provide (via value pointed to by non-null p_crc).

    The above CRC calculation is also described in the Bluetooth Core Specification, then described as the "CCITT generator polynomial g(D) = D^16 + D^12 + D^5 + 1 (i.e. 210041 in octal representation)".

    The function is found in the HCI transport library of the SDK, which indicates it is used by Bluetooth Host Controller Interface (HCI).

    sys_crc_calc() uses CRC-16-ANSI (polynomial 0x8005, that is x^16 + x^15 + x^2 + 1,) with 0x0000 initial value.

    The function is found as part of the 802.15.4 stack API, which is a precompiled library distributed as part of the nRF5 SDK. It has been used for samples and testing, but is currently not used from anywhere within the nRF5 SDK. (I was not able to find any internal uses within the 802.15.4 library either.)

    To answer your questions:

    Does it use the same one as CRC16 compute

    No, the polynomials differ.

    If not what does it use and does it have any advantages in terms of memory usage, speed, configuration or anything else?

    I am afraid we do not have any clear answer to this, apart from what polynomials and initial values are used, but with that knowledge I am sure there is extensive litterature to be found describing drawbacks and advantages for each of them.

    As for the implementations used in the SDK, one uses more operations but consistent branching while the other uses fewer operations but includes an if/else statement. It is hard to tell which one has the better performance (if there is a noticeable difference at all), but I suggest you to do some testing if this is important to you.

    Regards,
    Terje

Children
Related