Skip to content

Commit fc63dc1

Browse files
committed
sdio: make bus frequency selectable
1 parent f46baa8 commit fc63dc1

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

examples/sd.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ use cortex_m_rt::entry;
55
use cortex_m_semihosting::{hprint, hprintln};
66
use panic_semihosting as _;
77

8-
use stm32f4xx_hal::{delay, prelude::*, sdio::Sdio, stm32};
8+
use stm32f4xx_hal::{
9+
delay,
10+
prelude::*,
11+
sdio::{ClockFreq, Sdio},
12+
stm32,
13+
};
914

1015
#[entry]
1116
fn main() -> ! {
@@ -42,7 +47,7 @@ fn main() -> ! {
4247

4348
// Wait for card to be ready
4449
loop {
45-
match sdio.init_card() {
50+
match sdio.init_card(ClockFreq::F24Mhz) {
4651
Ok(_) => break,
4752
Err(_err) => (),
4853
}

src/sdio.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ enum PowerCtrl {
115115
On = 0b11,
116116
}
117117

118+
/// Clock frequency of a SDIO bus.
118119
#[allow(dead_code)]
119-
enum ClockFreq {
120+
pub enum ClockFreq {
120121
F24Mhz = 0,
121122
F16Mhz = 1,
122123
F12Mhz = 2,
@@ -285,8 +286,8 @@ impl Sdio {
285286
}
286287
}
287288

288-
/// initialize card
289-
pub fn init_card(&mut self) -> Result<(), Error> {
289+
/// Initializes card (if present) and sets the bus at the specified frequency.
290+
pub fn init_card(&mut self, freq: ClockFreq) -> Result<(), Error> {
290291
// Enable power to card
291292
self.sdio
292293
.power
@@ -361,7 +362,7 @@ impl Sdio {
361362

362363
self.get_scr(&mut card)?;
363364

364-
self.set_bus(self.bw, ClockFreq::F24Mhz, &card)?;
365+
self.set_bus(self.bw, freq, &card)?;
365366

366367
self.card.replace(card);
367368
self.read_card_status()?;

0 commit comments

Comments
 (0)