Jump to main content

##

# 3.33.9 Device Service Unit (DSU)

The DSU unit provides support for calculating a cyclic redundancy check (CRC32) value for a memory area. A cyclic redundancy check (CRC) is an error detection technique used to find accidental errors in data. It is commonly used to determine whether the data during a transmission, or data present in data and program memories has been corrupted or not.

A CRC takes a data stream or a block of data as input and generates a 32-bit output that can be appended to the data and used as a checksum. When the same data are later received or read, the device or application repeats the calculation. If the new CRC result does not match the one calculated earlier, the block contains a data error. The application will then detect this and may take a corrective action, such as requesting the data to be sent again or simply not using the incorrect data.

## Using The Library

CRC32 calculation for a memory range is started after writing the start address into the Address register (ADDR) and the size of the memory range into the Length register (LENGTH). Both must be word aligned. The initial seed value used for the CRC32 calculation must be written to the Data register (DATA). This value will usually be 0xFFFFFFFF, but can be, for example, the result of a previous CRC32 calculation if generating a common CRC32 of separate memory blocks.

Once completed, the calculated CRC32 value can be read out of the Data register. The read value must be complemented to match standard CRC32 implementations or kept non-inverted if used as starting point for subsequent CRC32 calculations.

The example code below demonstrates how to compute CRC.

    #define CRC_DATA_LENGTH         16          // in bytes
    #define CRC_SEED                0xFFFFFFFF

    /* Random generated data */
    const uint8_t crc_data[CRC_DATA_LENGTH] = {0xf0, 0x7f, 0x00, 0x20, 0x19, 0x0c, 0x00, 0x00, 0x39, 0x0e, 0x00, 0x00, 0x3b, 0x0e, 0x00, 0x00}

    int main ( void )
    {
        uint32_t hw_crc32   = 0;

        PAC_PeripheralProtectSetup (PAC_PERIPHERAL_DSU, PAC_PROTECTION_CLEAR);

        DSU_CRCCalculate((uint32_t)&crc_data, CRC_DATA_LENGTH, CRC_SEED, &hw_crc32);

        PAC_PeripheralProtectSetup (PAC_PERIPHERAL_DSU, PAC_PROTECTION_SET);
    }

## Library Interface

Device Service Unit peripheral library provides the following interfaces:

Functions

Name | Description
--- | ---
DSU_CRCCalculate | Calculates the CRC Value for the specified address range