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 sdcard = embedded_sdmmc::SdCard::new(sdmmc_spi, sdmmc_cs, delayer);
println!("Card size {} bytes", sdcard.num_bytes()?);
let mut volume_mgr = VolumeManager::new(sdcard, time_source);
println!("Card size is still {} bytes", volume_mgr.device().num_bytes()?);
let mut volume0 = volume_mgr.get_volume(embedded_sdmmc::VolumeIdx(0))?;
println!("Volume 0: {:?}", volume0);
let root_dir = volume_mgr.open_root_dir(&volume0)?;
let mut my_file = volume_mgr.open_file_in_dir(
&mut volume0, &root_dir, "MY_FILE.TXT", embedded_sdmmc::Mode::ReadOnly)?;
while !my_file.eof() {
let mut buffer = [0u8; 32];
let num_read = volume_mgr.read(&volume0, &mut my_file, &mut buffer)?;
for b in &buffer[0..num_read] {
print!("{}", *b as char);
}
}
volume_mgr.close_file(&volume0, my_file)?;
volume_mgr.close_dir(&volume0, root_dir);Features
defmt-log: By turning off the default features and enabling thedefmt-logfeature 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::fat::FatVolume;pub use crate::filesystem::Attributes;pub use crate::filesystem::Cluster;pub use crate::filesystem::DirEntry;pub use crate::filesystem::Directory;pub use crate::filesystem::File;pub use crate::filesystem::FilenameError;pub use crate::filesystem::Mode;pub use crate::filesystem::ShortFileName;pub use crate::filesystem::TimeSource;pub use crate::filesystem::Timestamp;pub use crate::filesystem::MAX_FILE_SIZE;pub use crate::sdcard::Error as SdCardError;pub use crate::sdcard::SdCard;
Modules
- Block Device support
- embedded-sdmmc-rs - FAT16/FAT32 file system implementation
- embedded-sdmmc-rs - Generic File System structures
- The SD/MMC Protocol
Structs
- A
VolumeManagerwraps a block device and gives access to the volumes within it. - Represents a partition with a filesystem within it.
- A
VolumeIdxis a number which identifies a volume (or partition) on a disk.VolumeIdx(0)is the first primary partition on an MBR partitioned disk. - A
VolumeManagerwraps a block device and gives access to the volumes within it.
Enums
- Represents all the ways the functions in this crate can fail.
- This enum holds the data for the various different types of filesystems we support.