Skip to content

Commit 0fbfaf4

Browse files
committed
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 0fbfaf4

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

src/sdmmc.rs

+28-6
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,21 @@ 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 {
116+
require_crc: true,
117+
}
118+
}
119+
}
120+
106121
impl<SPI, CS> SdMmcSpi<SPI, CS>
107122
where
108123
SPI: embedded_hal::blocking::spi::Transfer<u8>,
@@ -139,6 +154,16 @@ where
139154
/// This routine must be performed with an SPI clock speed of around 100 - 400 kHz.
140155
/// Afterwards you may increase the SPI clock speed.
141156
pub fn init(&mut self) -> Result<(), Error> {
157+
self.init_with_opts(Default::default())
158+
}
159+
160+
/// De-init the card so it can't be used
161+
pub fn deinit(&mut self) {
162+
self.state = State::NoInit;
163+
}
164+
165+
/// Initializes the card into a known state
166+
pub fn init_with_opts(&mut self, options: AcquireOpts) -> Result<(), Error> {
142167
let f = |s: &mut Self| {
143168
// Assume it hasn't worked
144169
s.state = State::Error;
@@ -172,7 +197,9 @@ where
172197
return Err(Error::CardNotFound);
173198
}
174199
// Enable CRC
175-
if s.card_command(CMD59, 1)? != R1_IDLE_STATE {
200+
if s.card_command(CMD59, 1)? != R1_IDLE_STATE
201+
&& options.require_crc
202+
{
176203
return Err(Error::CantEnableCRC);
177204
}
178205
// Check card version
@@ -224,11 +251,6 @@ where
224251
result
225252
}
226253

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

0 commit comments

Comments
 (0)