CRC-8 (serial)

Catch transmission errors with a cyclic redundancy check.

When to use it

A CRC is a strong, cheap checksum: append it to a message and the receiver recomputes it to detect corruption, on a UART link, an SPI flash, or a packet bus. This is a serial CRC-8 with polynomial x^8 + x^2 + x + 1 (0x07), one message bit per clock.

How it works

It's a linear-feedback shift register. Each clock, XOR the incoming bit with the top of the register to make the feedback, shift left, and if the feedback is 1, XOR in the polynomial. After the last bit, crc is the remainder to transmit.

Gotchas

Try it

Runs on our simulator, edit the code and press Run to see the waveform.

Open & fork in the playground → Ship the verified version: lfpga add lfpga_crc

The runnable example above is a teaching version. The libfpga library ships a hardened, parameterised, CI-tested module (lfpga_crc) for production use.

Next recipe: Round-robin arbiter