Expand description
A no_std, async Rust driver for the ON Semiconductor CAT25040 4-Kbit SPI EEPROM,
built on embedded-hal-async traits.
Works with any platform that implements the Spi and HardwareInterface traits.
§Features
- Byte read/write with automatic write-only-if-changed optimization
- Page write (16 bytes per page, single write cycle)
- Sequential read of arbitrary length
- 9-bit addressing – handles the A8 bit encoding in opcodes automatically
- Busy polling after writes
- Software block protection – protect memory regions from accidental writes
- Power-up initialization – proper timing delays per datasheet specifications
- Optional
defmtlogging via thedefmtfeature - Extensive use of
device-driverfor:- Register definitions and field access
- Command operations (WREN, WRDI, WRSR)
- Type-safe status register access with named fields
§Device-Driver Integration
This driver leverages the device-driver crate to provide a strongly-typed API
for registers and commands. Register definitions are generated from a YAML manifest
at build time, providing compile-time guarantees and field-level access to status bits.
§Example
let mut eeprom = Cat25040::new(spi, hardware_interface);
// Initialize device after power-on (waits required tPUW = 1ms)
eeprom.init().await.unwrap();
// Read 16 bytes starting at address 0x00
let mut buf = [0u8; 16];
eeprom.read(0x00, &mut buf).await.unwrap();
// Write a single byte (skips if value already matches)
eeprom.write_byte(0xAB, 0x10).await.unwrap();
// Write a full 16-byte page (address must be page-aligned)
let page = *b"EEPROM OK!";
eeprom.write_page(&page, 0x00).await.unwrap();
// Access status register with type-safe fields
let status = eeprom.read_status().await.unwrap();
if status.busy() {
// Write in progress
}
if status.wel() {
// Write enabled
}
// Configure block protection to protect upper half (0x100-0x1FF)
eeprom.set_block_protection(BlockProtection::UpperHalf).await.unwrap();
// Check current protection level
let level = eeprom.get_block_protection().await.unwrap();
// Clear all protection
eeprom.clear_block_protection().await.unwrap();
// Use device-driver commands directly
eeprom.write_enable().await.unwrap();
eeprom.write_disable().await.unwrap();§Device Compatibility
Designed for the CAT25040 but should work with other CAT250xx family EEPROMs
that use the same SPI command set and 9-bit addressing (e.g., CAT25020).
Modules§
- spi_
device - Adapter from
embedded_hal_async::spi::SpiDeviceto this crate’sSpitrait.
Structs§
- Cat25040
- CAT25040 EEPROM driver, generic over any SPI implementation and delay provider.
- Cat25040
Device - Root block of the Cat25040Device driver
- SpiRegister
Interface - Wrapper that implements device-driver’s RegisterInterface for our SPI trait.
- Status
- Status register (Read Status opcode 0x05)
Enums§
- Block
Protection - Block protection levels for the CAT25040 (512 bytes = 0x000-0x1FF).
- Cat25040
Error - Operation
- SPI transaction operation.
Traits§
- Hardware
Interface - Hardware interface trait for delays.
- Spi
- SPI communication trait for the CAT25040 driver.