HardFOC driver
AT25040 Driver¶
A header-only C++17 driver for the Microchip AT25040B serial EEPROM (also AT25010B and AT25020B). It detects the chip safely, reads and writes it in pages and reports every result as a status, on any MCU with SPI.
The driver has no platform code. You give it a small class with one method that runs an SPI transaction; it does the rest: the instruction set, the ninth address bit, bounds and page checks, and a probe that tells a missing chip from a present one.
- Memory
- 512 x 8 bits (AT25040B); 128 x 8 (AT25010B), 256 x 8 (AT25020B); 8-byte pages
- Interface
- SPI mode 0 or 3, MSB first; 20 MHz at 4.5 V to 5.5 V, 10 MHz at 2.5 V, 5 MHz at 1.8 V
- Supply
- 1.8 V to 5.5 V; 3.5 µA maximum standby at 5 V
- Writes
- Self-timed, 5 ms maximum per page; 1,000,000 cycles, 100-year retention
- Protection
- WP pin, write-enable latch, block protection of the top ¼, top ½ or whole array
- Package
- 8-lead SOIC, TSSOP, UDFN, XDFN, 8-ball VFBGA; -40 °C to +85 °C
What you get¶
- One object per chip.
at25040::Device<YourSpi>withProbe(),Read(),Write(),WritePage(),WaitReady(), block protection and the write-enable latch. See API guide. - Safe detection.
Probe()reads the status register twice and rejects a floating bus (0xFF) and a bus that echoes the command back. See Hardware. - The ninth address bit handled. Addresses
0x100to0x1FFput A8 into the opcode for you. See Protocol. - Checks before the bus. A bad pointer, a zero length, a range past the array or a write that crosses a page
returns
Status::Argwithout touching SPI. - Zero-overhead portability. The port is a CRTP class: no virtual calls, no heap, no exceptions, no RTOS. See Porting.
- Tested without hardware. Host unit tests run the driver against a model of the chip. See Testing and CI.
Where to go next¶
-
Wire the chip, write the port, store and read back four bytes.
-
Pins, bus settings, timing, power and write protection.
-
The three layers and what each one owns.
-
Probe, read, write, wait and handle errors, task by task.
-
Implement the one-method SPI interface for your MCU.
-
Every class and constant, generated from the headers.