Skip to content

Commit 5dcbbdf

Browse files
bors[bot]plorefice
andauthored
Merge #163
163: Make SDIO bus frequency selectable r=therealprof a=plorefice There are cases in which the bus cannot run at 24MHz, for example due to PCB layout issues. This PR makes the bus frequency selection a part of the public API, allowing the user to run the SDIO bus at a lower frequency, if necessary. Co-authored-by: Pietro Lorefice <[email protected]> Co-authored-by: Pietro Lorefice <[email protected]>
2 parents f46baa8 + 401a344 commit 5dcbbdf

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
- Allow specifying the desired SDIO bus speed during initialization
11+
1012
## [v0.8.1] - 2020-05-10
1113

1214
### Added

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-5
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ enum PowerCtrl {
115115
On = 0b11,
116116
}
117117

118-
#[allow(dead_code)]
119-
enum ClockFreq {
118+
/// Clock frequency of a SDIO bus.
119+
pub enum ClockFreq {
120120
F24Mhz = 0,
121121
F16Mhz = 1,
122122
F12Mhz = 2,
@@ -285,8 +285,8 @@ impl Sdio {
285285
}
286286
}
287287

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

362362
self.get_scr(&mut card)?;
363363

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

366366
self.card.replace(card);
367367
self.read_card_status()?;

0 commit comments

Comments
 (0)