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 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::filesystem::MAX_FILE_SIZE;pub use crate::sdmmc::Error as SdMmcError;pub use crate::sdmmc::BlockSpi;pub use crate::sdmmc::SdMmcSpi;Modules
Structs
Controller wraps a block device and gives access to the volumes within it.u32, which would save two bytes at
the expense of some maths.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.