CRC API Functions

The code for this module is contained in source/stl_crc.c and source/stl_crc_s.asm, with include/stl_crc.h containing the API declarations for use by applications.

Module Details

group stl_crc

Defines

STL_CRC_INIT_CRC 0x0UL

Initial CRC Register Value.

STL_CRC_PASS 0x0U
STL_CRC_FAIL 0x1U

Typedefs

typedef STL_CRC_Obj *STL_CRC_Handle

Handle to the CRC structure.

Enums

enum STL_CRC_Parity

Parity enumeration.

The parity is used by the CRC algorithm to determine whether to begin calculations from the low byte (EVEN) or from the high byte (ODD) of the first word (16-bit) in the message.

For example, if your message had 10 bytes and started at the address 0x8000 but the first byte was at the high byte position of the first 16-bit word, the user would call the CRC function with odd parity i.e. STL_CRC_PARITY_ODD

Address: HI LO

0x8000 : B0 XX

0x8001 : B2 B1

0x8002 : B4 B3

0x8003 : B6 B5

0x8004 : B8 B7

0x8005 : XX B9

However, if the first byte was at the low byte position of the first 16-bit word, the user would call the CRC function with even parity i.e. STL_CRC_PARITY_EVEN

Address: HI LO

0x8000 : B1 B0

0x8001 : B3 B2

0x8002 : B5 B4

0x8003 : B7 B6

0x8004 : B9 B8

Values:

STL_CRC_PARITY_EVEN = 0U

Even parity, CRC starts at the low byte of the first word (16-bit)

STL_CRC_PARITY_ODD = 1U

Odd parity, CRC starts at the high byte of the first word (16-bit)

Functions

void STL_CRC_reset(void)

Workaround to the silicon issue of first VCU calculation on power up being erroneous.

Due to the internal power-up state of the VCU module, it is possible that the first CRC result will be incorrect. This condition applies to the first result from each of the eight CRC instructions. This rare condition can only occur after a power-on reset, but will not necessarily occur on every power on. A warm reset will not cause this condition to reappear.

Workaround(s): The application can reset the internal VCU CRC logic by performing a CRC calculation of a single byte in the initialization routine. This routine only needs to perform one CRC calculation and can use any of the CRC instructions.

Return

None.

void STL_CRC_calculate(const STL_CRC_Handle crcHandle)

Runs the 32-bit CRC routine using polynomial 0x04c11db7.

Calculates the 32-bit CRC using polynomial 0x04c11db7 on the VCU or VCRC. Depending on the parity chosen the CRC begins at either the low byte (STL_CRC_PARITY_EVEN) or the high byte (STL_CRC_PARITY_ODD) of the first word (16-bit).

Parameters
  • crcHandle: handle to the CRC object

Note

The size of the message (bytes) is limited to 65535 bytes.

Return

None.

void STL_CRC_calculateLowBytes(const STL_CRC_Handle crcHandle)

Runs the 32-bit CRC routine using polynomial 0x04c11db7.

Calculates the 32-bit CRC using polynomial 0x04c11db7 on the VCU or VCRC. This algorithm performs a CRC32 only on the low bytes (LSB) of each 16-bit word. The input

parity has no effect. This function works on unpacked data.
Parameters
  • crcHandle: handle to the CRC object

Note

The size of the message (bytes) is limited to 65535 bytes.

Return

None.

uint16_t STL_CRC_checkCRC(const uint32_t startAddress, const uint32_t endAddress, const uint32_t goldenCRC)

Calculates a CRC-32 value for specific memory range and compares it with the goldenCRC value.

This function performs a test of the memory range by calculating the CRC-32 value for the input memory range and comparing it with the golden CRC value.

Parameters
  • startAddress: - start address of CRC calculation.

  • endAddress: - end address of CRC calculation, inclusive.

  • goldenCRC: - golden CRC value.

Note

This function could be used with many memory types including Flash and Boot ROM.

Return

If the calculated CRC matches the golden CRC, then the function returns STL_CRC_PASS. Otherwise, it returns STL_CRC_FAIL.

struct STL_CRC_Obj
#include <stl_crc.h>

CRC structure.