spxg/fat32

This crate has stopped updating, please use rust-fatfs

This crate has stopped updating, please use sdio_sdhc and WindowsAPI

News

This crate has stopped updating, please use rust-fatfs.

FAT32 FileSystem Library

This is FAT32 FileSystem Library, which is #![no_std] and does not use alloc.

Test passed with sdio_sdhc and WindowsAPI.

Supported Features

  • Read
  • Create File AND Dir
  • Write(OverWritten and Append)
  • Delete File AND DIR

Questions

My Device Support std, Can I Use This Crate?

Of course you can, but I don't recommend it. You should use std::fs::File OR other crates.

Why Do You Write This Crate?

In order to support devices and environment which don't have std, like

  • Embedded Device
  • Bootloader

Have More Examples?

  • Embedded Device's Bootloader

How To Test (Only Windows)

  • EDIT mount() function in lib.rs, change disk like \\\\.\\E:
  • cargo test

How To Use

You need make your library implement BlockDevice trait:

pub trait BlockDevice {
    type Error;
    fn read(&self, buf: &mut [u8], address: usize, number_of_blocks: usize) -> Result<(), Self::Error>;
    fn write(&self, buf: &[u8], address: usize, number_of_blocks: usize) -> Result<(), Self::Error>;
}

For example, I use my another library sdio_sdhc to implement:

impl BlockDevice for Card {
    type Error = CmdError;

    fn read(&self, buf: &mut [u8], address: usize, number_of_blocks: usize) -> Result<(), Self::Error> {
        if number_of_blocks == 1 {
            self.read_block(buf, address as u32)?
        } else {
            self.read_multi_blocks(buf, address as u32, number_of_blocks as u32)?
        }

        Ok(())
    }

    fn write(&self, buf: &[u8], address: usize, number_of_blocks: usize) -> Result<(), Self::Error> {
        if number_of_blocks == 1 {
            self.write_block(buf, address as u32)?
        } else {
            self.write_multi_blocks(buf, address as u32, number_of_blocks as u32)?
        }

        Ok(())
    }
}

Now sdio_sdhc library supported fat32 filesystem. Then, add fat32 library to your application

# if no feature config, the BUFFER_SIZE is 512 Bytes
fat32 = "0.2"

If your card block is other size, like 1024 Bytes

[dependencies.fat32]
version = "0.2"
default-features = false
features = ["1024"]

Then, you can do some tests

// Card from sdio_sdhc crate
let card = Card::init().unwrap();
// Volume from fat32 crate
let cont = Volume::new(card);
// cd root dir
let mut root = cont.root_dir();
// create file named test.txt
root.create_file("test.txt").unwrap();
// open file
let mut file = root.open_file("test.txt").unwrap();
// write buffer to file
file.write(&[80; 1234]).unwrap();

If all goes well, the file was created with 1234 Bytes in root dir.

Versions

Find the latest versions by id

Information - Updated Feb 17, 2022

Stars: 23
Forks: 4
Issues: 0

Repositories & Extras

rust_embedded_starter

Boilerplate für Embedded Entwicklung mit Rust mit Flash und Debug automatik

rust_embedded_starter

Embedded rust HAL (hardware abstraction layer) for the STM32WL

This is a work in progress, it is unstable, incomplete, and (mostly) untested

Embedded rust HAL (hardware abstraction layer) for the STM32WL

Embedded Rust Template

This template is based on stm32f4xx-hal

Embedded Rust Template

A Rust embedded-hal HAL for all MCUs in the STM32 F7 family

This crate is largely inspired by the awesome work done here:

A Rust embedded-hal HAL for all MCUs in the STM32 F7 family

An embedded rust no_std driver for the AHT20 temperature and humidity sensor, forked from Anthony...

An embedded rust no_std driver for the AHT20 temperature and humidity sensor, forked from Anthony Romano's docs

An embedded rust no_std driver for the AHT20 temperature and humidity sensor, forked from Anthony...

embedded-rust-H2AL

Hardware abstraction layer - abstraction layer

embedded-rust-H2AL

cargo-pio = Cargo + PlatformIO

Build Rust embedded projects with PlatformIO!

cargo-pio = Cargo + PlatformIO

Embedded rust HAL (hardware abstraction layer) for the STM32WL series

This is still in development, the code that exists today covers basic usage of:

Embedded rust HAL (hardware abstraction layer) for the STM32WL series

Microchip MCP4725 DAC Driver for Rust Embedded HAL

This is a driver crate for embedded Rust

Microchip MCP4725 DAC Driver for Rust Embedded HAL

An async embedded rust no_std driver for the QMC5883L magnetometer chip based on this driver

An async embedded rust no_std driver for the QMC5883L magnetometer chip based on embassy example

An async embedded rust no_std driver for the QMC5883L magnetometer chip based on this driver
Facebook Instagram Twitter GitHub Dribbble
Privacy