Skip to content

Commit 7f8ac31

Browse files
dcz-selfeldruin
authored andcommitted
Allow initializing without CRC
A 512MB Transcend card seems to not support it but work OK otherwise: MID: 0x00001b OID: 0x534d PNM: SMI MDT: 11/2007
1 parent b301ac8 commit 7f8ac31

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/sdmmc.rs

+24-6
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@ impl Delay {
103103
}
104104
}
105105

106+
/// Options for acquiring the card.
107+
#[derive(Debug)]
108+
pub struct AcquireOpts {
109+
/// Some cards don't support CRC mode. At least a 512MiB Transcend one.
110+
pub require_crc: bool,
111+
}
112+
113+
impl Default for AcquireOpts {
114+
fn default() -> Self {
115+
AcquireOpts { require_crc: true }
116+
}
117+
}
118+
106119
impl<SPI, CS> SdMmcSpi<SPI, CS>
107120
where
108121
SPI: embedded_hal::blocking::spi::Transfer<u8>,
@@ -139,6 +152,16 @@ where
139152
/// This routine must be performed with an SPI clock speed of around 100 - 400 kHz.
140153
/// Afterwards you may increase the SPI clock speed.
141154
pub fn init(&mut self) -> Result<(), Error> {
155+
self.init_with_opts(Default::default())
156+
}
157+
158+
/// De-init the card so it can't be used
159+
pub fn deinit(&mut self) {
160+
self.state = State::NoInit;
161+
}
162+
163+
/// Initializes the card into a known state
164+
pub fn init_with_opts(&mut self, options: AcquireOpts) -> Result<(), Error> {
142165
let f = |s: &mut Self| {
143166
// Assume it hasn't worked
144167
s.state = State::Error;
@@ -172,7 +195,7 @@ where
172195
return Err(Error::CardNotFound);
173196
}
174197
// Enable CRC
175-
if s.card_command(CMD59, 1)? != R1_IDLE_STATE {
198+
if s.card_command(CMD59, 1)? != R1_IDLE_STATE && options.require_crc {
176199
return Err(Error::CantEnableCRC);
177200
}
178201
// Check card version
@@ -224,11 +247,6 @@ where
224247
result
225248
}
226249

227-
/// De-init the card so it can't be used
228-
pub fn deinit(&mut self) {
229-
self.state = State::NoInit;
230-
}
231-
232250
/// Return the usable size of this SD card in bytes.
233251
pub fn card_size_bytes(&self) -> Result<u64, Error> {
234252
self.check_state()?;

0 commit comments

Comments
 (0)