m95320

Crates.iom95320
lib.rsm95320
version1.3.0
sourcesrc
created_at2022-09-27 19:27:02.946471
updated_at2024-01-11 06:09:12.51904
descriptionDriver for STMicroelectronics M95320 32-Kbit serial SPI bus EEPROM
homepage
repositoryhttps://github.com/jonahss/m95320.git
max_upload_size
id675130
size32,282
Jonah (Jonahss)

documentation

https://docs.rs/m95320/

README

m95320

crates.io docs.rs

embedded-hal Rust driver for STMicroelectronics M95320 32-Kbit serial SPI bus EEPROM

some features not yet implemented, basic read and write is working

This create is mostly ripped-off from the spi-memory crate: https://github.com/jonas-schievink/spi-memory

Usage

Add an entry to your Cargo.toml:

[dependencies]
m95320 = "1.0.2"

Example

Using rppal on a Raspberry Pi:

use rppal::gpio::Gpio;
use rppal::spi::{Bus, Mode, SlaveSelect, Spi};

use m95320::prelude::*;
use m95320::m95320::Flash;

const GPIO_MEMORY_CHIP_SELECT: u8 = 27;

fn main() {
    let gpio = Gpio::new().unwrap();
    let cs = gpio.get(GPIO_MEMORY_CHIP_SELECT).unwrap().into_output();
    let spi = Spi::new(Bus::Spi0, SlaveSelect::Ss0, 10_000_000, Mode::Mode0).unwrap();

    let mut flash = Flash::init(spi, cs).unwrap();

    let status = flash.read_status().expect("get status");
    println!("status registers: {:?}", status);

    let mut page_buffer: [u8; 32] = [0x0; 32];

    flash.erase_sectors(0, 2).expect("erase");

    let hello = String::from("hello memory!");
    for (i, byte) in hello.as_bytes().into_iter().enumerate() {
        page_buffer[i] = byte.clone();
    }

    flash.write_bytes(0, &mut page_buffer).expect("write");
    
    flash.read(0, &mut page_buffer).expect("read");
    println!("bytes read: {:?}", page_buffer);
}

Check the API Documentation for how to use the crate's functionality.

Commit count: 38

cargo fmt