Peripheral features
The cyclic redundancy check (CRC) module generates 16/32-bit CRC code for error detection.
Features
- The CRC module provides a programmable polynomial and other parameters required to implement a 16-bit or 32-bit CRC standard.
- Hardware CRC generator circuit using a 16-bit or 32-bit programmable shift register.
- Programmable initial seed value and polynomial.
- 32-bit CPU register programming interface.
- In 16-bit and 32-bit CRC modes, data values can be programmed 8 bits, 16 bits, or 32 bits at a time, provided all bytes are contiguous.
- Option to transpose input data or output data (the CRC result) bitwise or bytewise.
- This option is required for certain CRC standards. A bytewise transpose operation is not possible when accessing the CRC data register via 8-bit accesses. In this case, the user's software must perform the bytewise transpose function.
- Option for inversion of final CRC result.
- Various MCU modes affect the CRC module's functionality.
- Run mode is the basic mode of operation.
- Any CRC calculation in progress stops when the MCU enters a low-power mode (Wait or Stop) that disables the module clock. It resumes after the clock is enabled or via the system reset for exiting the low-power mode. Clock gating for this module is dependent on the MCU.
How this driver is designed to make this peripheral work
This driver provides multiple definitions/functions to enable and configure the CRC peripheral module. The CRC_Init() function takes the argument in type of crc_config_t, which contains all CRC features. After all the necessary configuration is completed, the data for error detection can be written, then the CRC checksum value will be stored in the CRC data register.The APIs this driver provides can be classified in 3 API groups:
- Initialization and De-initialization Interfaces
- Functions to initialize or de-initialize the CRC module.
- Configure the CRC to certain state with all feature covered.
- CRC Configuration Interfaces
- The APIs in this function group can be used to separately configure the CRC polynomial and other parameters required for the CRC calculation.
- CRC Write/Read Data Interfaces
- The CRC Data register contains the value of the seed, data, and checksum. The APIs in this function group can be used to write the value of the seed and the data for error detection, reads the 16-bit/32-bit checksum from the CRC module.
How to use this driver
- Initialize the CRC module with expected polynomial and other parameters required.
- Provides the configuration of commonly used CRC protocols in CRC_GetDefaultConfig() function. refer to _crc_protocol_type to use expected CRC protocol.
- Configure the CRC polynomial and other parameters required for the CRC calculation.
- Just use when expecting to change the parameters separately.
- Write the data for error detection.
- Get the 16-bit or 32-bit checksum.
Typical Use Case
- CRC Initialization:
- Change CRC module configuration:
- Write data to the CRC module:
char testData[] = "123456789";
CRC_WriteData(CRC, (uint8_t *)&testData[0],
sizeof(testData) - 1);
*
- Read the 16-bit checksum from the CRC module: