Skip to content

Commit bb214b6

Browse files
Merge #219
219: Add support for SCSD cards with SDIO r=therealprof a=glbsalazar Add support for SCSD cards in the SDIO interface Added the timeout since setting the bus width and frequency was timing out because the card was not ready. Co-authored-by: Gonçalo Salazar <glbsalazar@gmail.com>
2 parents 36ad03a + a2db432 commit bb214b6

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/sdio.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,7 @@ impl Sdio {
250250
let capacity = if ocr.high_capacity() {
251251
CardCapacity::SDHC
252252
} else {
253-
// Note: SDSC Not supported yet
254-
return Err(Error::UnsupportedCardType);
253+
CardCapacity::SDSC
255254
};
256255

257256
// Get CID
@@ -292,6 +291,9 @@ impl Sdio {
292291

293292
self.card.replace(card);
294293

294+
// Wait before setting the bus witdth and frequency to avoid timeouts on SDSC cards
295+
while !self.card_ready()? {}
296+
295297
self.set_bus(self.bw, freq)?;
296298
Ok(())
297299
}
@@ -312,8 +314,14 @@ impl Sdio {
312314

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

319+
// Always read 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+
};
317325
self.cmd(cmd::set_block_length(512))?;
318326
self.start_datapath_transfer(512, 9, true);
319327
self.cmd(cmd::read_single_block(blockaddr))?;
@@ -348,8 +356,14 @@ impl Sdio {
348356

349357
/// Write a block to card
350358
pub fn write_block(&mut self, blockaddr: u32, block: &[u8; 512]) -> Result<(), Error> {
351-
let _card = self.card()?;
359+
let card = self.card()?;
352360

361+
// Always write 1 block of 512 bytes
362+
// SDSC cards are byte addressed hence the blockaddress is in multiples of 512 bytes
363+
let blockaddr = match card.capacity {
364+
CardCapacity::SDSC => blockaddr * 512,
365+
_ => blockaddr,
366+
};
353367
self.cmd(cmd::set_block_length(512))?;
354368
self.start_datapath_transfer(512, 9, false);
355369
self.cmd(cmd::write_single_block(blockaddr))?;

0 commit comments

Comments
 (0)