Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ The format is based on [Keep a Changelog] and this project adheres to [Semantic
- Renamed `delete_file_in_dir` to `delete_entry_in_dir` because it can now delete empty directories (breaking change)
- Added `open_long_name_file_in_dir` API, to open files using their Long File Name
- Updated directory iterator callback, to allow bailing out early (breaking change)
- `crc7` function now returns the actual CRC7 value without left-shifting by and XOR-ing by/with 1.

### Added

- Added `CsdV3` data structure.
- `Csd::new` constructor which creates the CSD from a raw `&[u8; 16]` and also performs a CRC7
check.
- Added `verify_crc7` function on CSD structures.

## [Version 0.9.0] - 2025-06-08

Expand Down
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ byteorder = {version = "1", default-features = false}
defmt = {version = "1.0.1", optional = true}
embedded-hal = "1.0.0"
embedded-io = "0.6.1"
bitbybit = "2"
arbitrary-int = "2"
bitflags = "2"
heapless = "0.9.1"
log = {version = "0.4", default-features = false, optional = true}
thiserror = {version="2", default-features = false}

[dev-dependencies]
chrono = "0.4"
Expand All @@ -31,6 +35,6 @@ sha2 = "0.10"

[features]
default = ["log"]
defmt-log = ["dep:defmt"]
defmt-log = ["dep:defmt", "arbitrary-int/defmt"]
log = ["dep:log"]

14 changes: 8 additions & 6 deletions src/sdcard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ where
let num_blocks = match csd {
Csd::V1(ref contents) => contents.card_capacity_blocks(),
Csd::V2(ref contents) => contents.card_capacity_blocks(),
Csd::V3(ref contents) => contents.card_capacity_blocks(),
};
Ok(BlockCount(num_blocks))
}
Expand All @@ -289,6 +290,7 @@ where
match csd {
Csd::V1(ref contents) => Ok(contents.card_capacity_bytes()),
Csd::V2(ref contents) => Ok(contents.card_capacity_bytes()),
Csd::V3(ref contents) => Ok(contents.card_capacity_bytes()),
}
}

Expand All @@ -298,27 +300,27 @@ where
match csd {
Csd::V1(ref contents) => Ok(contents.erase_single_block_enabled()),
Csd::V2(ref contents) => Ok(contents.erase_single_block_enabled()),
Csd::V3(ref contents) => Ok(contents.erase_single_block_enabled()),
}
}

/// Read the 'card specific data' block.
fn read_csd(&mut self) -> Result<Csd, Error> {
let mut csd_raw: [u8; 16] = [0; 16];
match self.card_type {
Some(CardType::SD1) => {
let mut csd = CsdV1::new();
if self.card_command(CMD9, 0)? != 0 {
return Err(Error::RegisterReadError);
}
self.read_data(&mut csd.data)?;
Ok(Csd::V1(csd))
self.read_data(&mut csd_raw)?;
Ok(Csd::V1(CsdV1::from_be_bytes(&csd_raw)))
}
Some(CardType::SD2 | CardType::SDHC) => {
let mut csd = CsdV2::new();
if self.card_command(CMD9, 0)? != 0 {
return Err(Error::RegisterReadError);
}
self.read_data(&mut csd.data)?;
Ok(Csd::V2(csd))
self.read_data(&mut csd_raw)?;
Ok(Csd::V2(CsdV2::from_be_bytes(&csd_raw)))
}
None => Err(Error::CardNotFound),
}
Expand Down
Loading