Jump to main content

##

# 3.2.7 Cyclic Redundancy Check (CRC)

The 32-Bit Programmable Cyclic Redundancy Check (CRC) module is a software-configurable CRC generator. The module provides a hardware implemented method of quickly generating checksums for various communication and security applications. The CRC engine calculates the CRC checksum without CPU intervention; moreover, it is much faster than the software implementation.

## Using The Library

CRC calculation for a memory range can be started after setting up the CRC engine using the CRC_CRCSetup() function. The initial seed value used for the CRC calculation must be passed to CRC_CRCCalculate() function along with the buffer and length of buffer on which CRC has to be calculated. This value will usually be 0xFFFFFFFF, but can be, for example, the result of a previous CRC calculation if generating a common CRC of separate memory blocks. Once completed, the calculated CRC value is returned.

Here is an example code to calculate a 32-Bit CRC

    #define BUFFER_SIZE 9

    const uint8_t srcBuffer[BUFFER_SIZE] = {'1', '2', '3', '4', '5', '6', '7', '8', '9'};

    CRC_SETUP crcSetup = {0};

    crcSetup.reverse_crc_input = true;
    crcSetup.polynomial_length = 32;
    crcSetup.polynomial = 0x04C11DB7;
    crcSetup.reverse_crc_output = true;
    crcSetup.final_xor_value = 0xFFFFFFFF;

    CRC_CRCSetup(crcSetup);

    // Expected CRC32 with above configurations and Input String - 0xCBF43926

    crc_32 = CRC_CRCCalculate((void *)srcBuffer, BUFFER_SIZE, 0xFFFFFFFF);

## Library Interface

Cyclic Redundancy Check peripheral library provides the following interfaces:

Functions

Name | Description
--- | ---
CRC_CRCSetup | CRC setup and enable function
CRC_CRCCalculate | Function to calculate CRC
CRC_CRCEnable | CRC enable function

Data types and constants

Name | Type | Description
--- | --- | ---
CRC_SETUP | Struct | Fundamental data object that represents CRC setup parameters