Crate embedded_sdmmc

source ·
Expand description

embedded-sdmmc

An SD/MMC Library written in Embedded Rust

This crate is intended to allow you to read/write files on a FAT formatted SD card on your Rust Embedded device, as easily as using the SdFat Arduino library. It is written in pure-Rust, is #![no_std] and does not use alloc or collections to keep the memory footprint low. In the first instance it is designed for readability and simplicity over performance.

Using the crate

You will need something that implements the BlockDevice trait, which can read and write the 512-byte blocks (or sectors) from your card. If you were to implement this over USB Mass Storage, there’s no reason this crate couldn’t work with a USB Thumb Drive, but we only supply a BlockDevice suitable for reading SD and SDHC cards over SPI.

let mut spi_dev = embedded_sdmmc::SdMmcSpi::new(sdmmc_spi, sdmmc_cs);
write!(uart, "Init SD card...").unwrap();
match spi_dev.acquire() {
    Ok(block) => {
        let mut cont: Controller<
            embedded_sdmmc::BlockSpi<DummySpi, DummyCsPin>,
            DummyTimeSource,
            4,
            4,
        > = Controller::new(block, time_source);
        write!(uart, "OK!\nCard size...").unwrap();
        match cont.device().card_size_bytes() {
            Ok(size) => writeln!(uart, "{}", size).unwrap(),
            Err(e) => writeln!(uart, "Err: {:?}", e).unwrap(),
        }
        write!(uart, "Volume 0...").unwrap();
        match cont.get_volume(embedded_sdmmc::VolumeIdx(0)) {
            Ok(v) => writeln!(uart, "{:?}", v).unwrap(),
            Err(e) => writeln!(uart, "Err: {:?}", e).unwrap(),
        }
    }
    Err(e) => writeln!(uart, "{:?}!", e).unwrap(),
};

Features

  • defmt-log: By turning off the default features and enabling the defmt-log feature you can configure this crate to log messages over defmt instead.

Make sure that either the log feature or the defmt-log feature is enabled.

Re-exports

pub use crate::blockdevice::Block;
pub use crate::blockdevice::BlockCount;
pub use crate::blockdevice::BlockDevice;
pub use crate::blockdevice::BlockIdx;
pub use crate::filesystem::MAX_FILE_SIZE;
pub use crate::sdmmc::Error as SdMmcError;
pub use crate::sdmmc::BlockSpi;
pub use crate::sdmmc::SdMmcSpi;

Modules

embedded-sdmmc-rs - Block Device support
embedded-sdmmc-rs - FAT16/FAT32 file system implementation
embedded-sdmmc-rs - Generic File System structures
embedded-sdmmc-rs - SDMMC Protocol
embedded-sdmmc-rs - Constants from the SD Specifications

Structs

Indicates whether a directory entry is read-only, a directory, a volume label, etc.
Represents a cluster on disk.
A Controller wraps a block device and gives access to the volumes within it.
Represents a directory entry, which tells you about other files and directories.
Represents an open directory on disk.
Identifies a FAT16 Volume on the disk.
Represents an open file on disk.
An MS-DOS 8.3 filename. 7-bit ASCII only. All lower-case is converted to upper-case by default.
Represents an instant in time, in the local time zone. TODO: Consider replacing this with POSIX time as a u32, which would save two bytes at the expense of some maths.
Represents a partition with a filesystem within it.
A VolumeIdx is a number which identifies a volume (or partition) on a disk. VolumeIdx(0) is the first primary partition on an MBR partitioned disk.

Enums

Represents all the ways the functions in this crate can fail.
Various filename related errors that can occur.
The different ways we can open a file.
This enum holds the data for the various different types of filesystems we support.

Traits

Things that impl this can tell you the current time.