Error Detection And Correction for flash pages
  • Python 98.3%
  • C 1.7%
Find a file
Stephan I. Böttcher 55612f3934 fix bch4369_fini() args
2026-03-25 11:38:01 +01:00
.gitignore fix_page() raise BCHError 2026-02-09 08:59:37 +01:00
bch4369.c fix bch4369_fini() args 2026-03-25 11:38:01 +01:00
bch4369.h bch4369 implementations for AVR and python 2026-02-08 15:04:02 +01:00
bch4369.py fix_page() raise BCHError 2026-02-09 08:59:37 +01:00
LICENSE add LICENSE 2026-02-09 10:14:26 +01:00
README.md README typo 2026-02-09 10:12:23 +01:00

BCH 4369 code for flash page EDAC

A flash chip like AT45DB161E provides pages of nonvolatile memory á 528 bytes. The chip can be configured to use 512 bytes pages, but why? This code makes use of the extra 16 bytes for Error Detection And Correction.

It turns out there is a Bose-Chaudhuri-Hocquenghem code that fits. The codeword has 4369 bits, including 128 bits parity. With messages of 4096 bits there are 145 bits of padding.

The python module galois by Matt Hostetter implements this code as

  • galois.BCH(4369, 4369-128, extension_field=galois.GF(2**16))

This code can correct up to 8 bit errors.

AVR

Here you find space efficient code for an AVR µC, in C and assembler.

Python

The python implementation can encode and check the parity without module galois. The data format is bytes(). It boils down to a simple numpy matrix multiplication. The galois module is only loaded when error correction is attempted.

Salt

The default .salt is b'\x01', i.e., the message length is 4097 bits with the leading bit set. A codeword off all zeros will see a correctable error in the salt. A real message of all zeros has nontrival parity. The python code can handle salts up to 18 bytes, 144 bits. The AVR could support longer salts by replacing bch5369_init by a memcpy. I do not know how usefull a salt is. I though it might be good to have nontrivial parity for an all zeros message.