Module mc_sst25::device

source ·
Expand description

Non-Blocking & blocking SPI protocol abstraction

Setup

Creating a device instance requires the following peripherals:

The device can be communicated with either in blocking or non-blocking mode:

  • In the case of blocking mode, the library waits internally until the respective operation is completely finished.
  • In the case of non-blocking mode, it is up to the caller to check the busy flag of the status register. (s. Reading status register)
let mut device = Flash::new(bus, pin_en, pin_wp, pin_hold);

// Blocking mode (default)
device.set_blocking();

// Non-blocking
device.set_non_blocking();

Reading status

The device contains eight status bits, which are mapped to Status struct.

let status = device.read_status().unwrap();

assert!(!status.busy);
assert!(!status.block0_protected);
assert!(!status.write_enabled);

Writing status

The following status flags are used for (write) protecting memory segments. On device power-up all memory blocks are protected.

let mut  status = Status::default();
status.block0_protected = false;
status.block1_protected = false;
status.block2_protected = true;
status.block3_protected = true;
status.bits_read_only = false;

device.write_status(status).unwrap();

Writing single bytes

The following method is used for writing single bytes.

Note: Memory region needs to be unprotected (s. Reading status), otherwise write operation is ignored by device

// Writing byte 0x64 to address 0xc8
device.byte_program(0xc8, 0x64).unwrap();

Writing larger data

Auto-address-increment method is used for writing larger amount of data. The given buffer needs to contain an even amount of data. (e.g 2, 4, 6, 8, … bytes).

Note: Memory region needs to be unprotected (s. Reading status), otherwise write operation is ignored by device

// Writing four bytes to address 0x5, so the following data is written:
// Address 0x5 contains byte 0x1
// Address 0x6 contains byte 0x2
// ...
device.aai_program(0x5, &[0x1, 0x2, 0x3, 0x4]).unwrap();

Full chip erase

The chip supports erasing the entire memory.

Note: All memory blocks needs to be unprotected (s. Reading status), otherwise erase operation is ignored by device

device.erase_full().unwrap();

Reading memory

Reading an arbitrary amount of data starting at the given address. The data amount is determined by the generic const L.

Note: If the maximum address is within range, the chip wraps automatically and continuous at the first address.

// Reading four bytes starting at address 0x0
let data = device.read::<4>(0x0).unwrap();
assert_eq!([0xa, 0xb, 0xc, 0xd], data);

Structs

SS25* flash memory chip
Mapped status register

Enums

Error when communicating with the device

Traits

General flash memory interface