Cyclic Redundancy Check (CRC)¶
lbuild module: modm:platform:crc
The CRC unit computes CRCs in hardware. Crc::crc32() computes the CRC-32 of
zlib, same as modm::math::crc32().
Crc::enable();
const uint32_t crc = Crc::crc32(data, length);
The unit holds the state of one calculation and crc32() computes the whole
buffer without yielding, so fibers can share it. If it is also used from an
interrupt, protect it with a lock or mutex of your choice.
Other CRCs are described by modm::math::CrcParameters in the Rocksoft model of
the CRC catalogue. The common
ones are predefined in modm::math, the defaults are the CRC-32 of zlib, so
for others only the differing parameters must be given:
Crc::crc<modm::math::Crc16Modbus>(data, length);
// CRC-32/JAMCRC
Crc::crc<modm::math::CrcParameters{.xorout = 0}>(data, length);
Units with a programmable polynomial support any odd polynomial of 7, 8, 16 or 32 bits, the others only the 32-bit polynomial 0x04C11DB7, with any initial value, reflection and final XOR.
Units with bit reversal (most families) feed words bit-reversed by word and
single bytes by byte, or words byte-swapped with REV for CRCs that are not
reflected. Units without it (F1, F2, F4, L1) take 32-bit words only: their
input is bit-reversed with RBIT or byte-swapped with REV, and the bytes
before the first and after the last aligned word are computed in software.
This module is only available for stm32.
Dependencies¶
Limited availability: Check with 'lbuild discover' if this module is available for your target!