Skip to content

Commit f6cc259

Browse files
committed
Added handle for byte addressed SDSC cards
1 parent e6e9383 commit f6cc259

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/sdio.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,15 @@ impl Sdio {
314314

315315
/// Read a block from the card
316316
pub fn read_block(&mut self, blockaddr: u32, block: &mut [u8; 512]) -> Result<(), Error> {
317-
let _card = self.card()?;
317+
let card = self.card()?;
318318

319+
// Always write 1 block of 512 bytes
320+
// SDSC cards are byte addressed hence the blockaddress is in multiples of 512 bytes
321+
let blockaddr = match card.capacity {
322+
CardCapacity::SDSC => blockaddr * 512,
323+
_ => blockaddr,
324+
};
325+
319326
self.cmd(cmd::set_block_length(512))?;
320327
self.start_datapath_transfer(512, 9, true);
321328
self.cmd(cmd::read_single_block(blockaddr))?;
@@ -350,7 +357,14 @@ impl Sdio {
350357

351358
/// Write a block to card
352359
pub fn write_block(&mut self, blockaddr: u32, block: &[u8; 512]) -> Result<(), Error> {
353-
let _card = self.card()?;
360+
let card = self.card()?;
361+
362+
// Always write 1 block of 512 bytes
363+
// SDSC cards are byte addressed hence the blockaddress is in multiples of 512 bytes
364+
let blockaddr = match card.capacity {
365+
CardCapacity::SDSC => blockaddr * 512,
366+
_ => blockaddr,
367+
};
354368

355369
self.cmd(cmd::set_block_length(512))?;
356370
self.start_datapath_transfer(512, 9, false);

0 commit comments

Comments
 (0)