Skip to content

Commit

Permalink
Allow initializing without CRC
Browse files Browse the repository at this point in the history
A 512MB Transcend card seems to not support it but work OK otherwise:
MID: 0x00001b
OID: 0x534d
PNM: SMI
MDT: 11/2007
  • Loading branch information
dcz-self committed Aug 13, 2021
1 parent b301ac8 commit 0fbfaf4
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions src/sdmmc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,21 @@ impl Delay {
}
}

/// Options for acquiring the card.
#[derive(Debug)]
pub struct AcquireOpts {
/// Some cards don't support CRC mode. At least a 512MiB Transcend one.
pub require_crc: bool,
}

impl Default for AcquireOpts {
fn default() -> Self {
AcquireOpts {
require_crc: true,
}
}
}

impl<SPI, CS> SdMmcSpi<SPI, CS>
where
SPI: embedded_hal::blocking::spi::Transfer<u8>,
Expand Down Expand Up @@ -139,6 +154,16 @@ where
/// This routine must be performed with an SPI clock speed of around 100 - 400 kHz.
/// Afterwards you may increase the SPI clock speed.
pub fn init(&mut self) -> Result<(), Error> {
self.init_with_opts(Default::default())
}

/// De-init the card so it can't be used
pub fn deinit(&mut self) {
self.state = State::NoInit;
}

/// Initializes the card into a known state
pub fn init_with_opts(&mut self, options: AcquireOpts) -> Result<(), Error> {
let f = |s: &mut Self| {
// Assume it hasn't worked
s.state = State::Error;
Expand Down Expand Up @@ -172,7 +197,9 @@ where
return Err(Error::CardNotFound);
}
// Enable CRC
if s.card_command(CMD59, 1)? != R1_IDLE_STATE {
if s.card_command(CMD59, 1)? != R1_IDLE_STATE
&& options.require_crc
{
return Err(Error::CantEnableCRC);
}
// Check card version
Expand Down Expand Up @@ -224,11 +251,6 @@ where
result
}

/// De-init the card so it can't be used
pub fn deinit(&mut self) {
self.state = State::NoInit;
}

/// Return the usable size of this SD card in bytes.
pub fn card_size_bytes(&self) -> Result<u64, Error> {
self.check_state()?;
Expand Down

0 comments on commit 0fbfaf4

Please sign in to comment.