---
title: "CRC"
canonical_url: https://developer.repebble.com/pebbleos/docs/samples/subsys/crc/checksums/
last_updated: 2026-11-18
sdk_version: 4.44
---
# CRC

Source: https://developer.repebble.com/pebbleos/docs/samples/subsys/crc/checksums/

This sample computes the [CRC](https://developer.repebble.com/pebbleos/docs/subsystems/crc.md)-8 and CRC-32 of the usual check string, `123456789`, then the CRC-32 again in two chunks: the running value carries over from one call to the next.

A receiver checks a frame that carries its own CRC-32 without splitting it: the CRC-32 of the message and its little-endian CRC appended is the constant `PBL_CRC32_RESIDUE` when nothing changed. The last check is the legacy checksum of older on-flash formats, which keeps partial words between updates.

Run:

`pbl samples samples/subsys/crc/checksums`

Boards:

every board

## Sources

src/main.c

```
#include \<stdint.h\>#include \<stdio.h\>#include \<string.h\>#include \<pbl/crc/crc.h\>static const char s\_check[] = "123456789";int main(void) {uint8\_t frame[64];size\_t len = strlen(s\_check);uint32\_t crc;printf("crc: CRC-8 of \"%s\": 0x%02x\n", s\_check, pbl\_crc8(0, s\_check, len));crc = pbl\_crc32(0, s\_check, len);printf("crc: CRC-32 of \"%s\": 0x%08x\n", s\_check, (unsigned int)crc);/\* The running value carries over, so data can come in pieces. \*/crc = pbl\_crc32(0, s\_check, 4);crc = pbl\_crc32(crc, &s\_check[4], len - 4);printf("crc: CRC-32 in chunks: 0x%08x\n", (unsigned int)crc);/\* A receiver checks a frame that carries its CRC-32, little-endian, without splitting it. \*/memcpy(frame, s\_check, len);for (int i = 0; i \< 4; i++) {frame[len + i] = (uint8\_t)(crc \>\> (8 \* i));}printf("crc: message with its CRC-32 appended is intact: %s\n",pbl\_crc32(0, frame, len + 4) == PBL\_CRC32\_RESIDUE ? "yes" : "no");frame[2] ^= 0x10;printf("crc: after flipping a bit: %s\n",pbl\_crc32(0, frame, len + 4) == PBL\_CRC32\_RESIDUE ? "yes" : "no");/\* The checksum of older on-flash formats keeps partial words between updates. \*/struct pbl\_crc32\_legacy ctx;uint32\_t legacy = pbl\_crc32\_legacy(s\_check, len);pbl\_crc32\_legacy\_init(&ctx);pbl\_crc32\_legacy\_update(&ctx, s\_check, 3);pbl\_crc32\_legacy\_update(&ctx, &s\_check[3], len - 3);printf("crc: legacy checksum: 0x%08x, in chunks: %s\n", (unsigned int)legacy,pbl\_crc32\_legacy\_finish(&ctx) == legacy ? "the same" : "different");printf("Sample done\n");return 0;}
```

## Output

```
crc: CRC-8 of "123456789": 0x3e
crc: CRC-32 of "123456789": 0xcbf43926
crc: CRC-32 in chunks: 0xcbf43926
crc: message with its CRC-32 appended is intact: yes
crc: after flipping a bit: no
crc: legacy checksum: 0x[0-9a-f]{8}, in chunks: the same
Sample done
```

Generated from PebbleOS [7753e801d](https://github.com/coredevices/pebbleos/commit/7753e801d93d20f2d37534ce2fa69d9952015237). This page is maintained in the pebbleos repository: [docs/samples/subsys/crc/checksums.md](https://github.com/coredevices/pebbleos/blob/7753e801d93d20f2d37534ce2fa69d9952015237/docs/samples/subsys/crc/checksums.md).
