Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SDMMC support. #315

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ jobs:
- { id: stm32l462, additional-features: ",stm32-usbd" }
- { id: stm32l471, additional-features: "" }
- { id: stm32l475, additional-features: "" } # USB_OTG not supported by PAC
- { id: stm32l476, additional-features: ",otg_fs" }
- { id: stm32l486, additional-features: ",otg_fs" }
- { id: stm32l496, additional-features: ",otg_fs" }
- { id: stm32l4a6, additional-features: ",otg_fs" }
- { id: stm32l476, additional-features: ",otg_fs,sdmmc,embedded-sdmmc,fatfs" }
- { id: stm32l486, additional-features: ",otg_fs,sdmmc,embedded-sdmmc,fatfs" }
- { id: stm32l496, additional-features: ",otg_fs,sdmmc,embedded-sdmmc,fatfs" }
- { id: stm32l4a6, additional-features: ",otg_fs,sdmmc,embedded-sdmmc,fatfs" }

steps:
- uses: actions/checkout@v2
Expand Down
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ embedded-dma = "0.1"
bxcan = ">=0.4, <0.7"
fugit = "0.3.5"
bitfield = "0.13.2"
sdio-host = { version = "0.7.0", optional = true }
embedded-sdmmc = { version = "0.3.0", optional = true }
fatfs = { version = "0.4.0", default-features = false, optional = true }

[dependencies.rand_core]
version = "0.6.2"
Expand Down Expand Up @@ -69,6 +72,9 @@ features = ["rt", "stm32l432", "stm32-usbd"]
rt = ["stm32l4/rt"]
unproven = ["embedded-hal/unproven"]
otg_fs = ["synopsys-usb-otg"]
sdmmc = ["dep:sdio-host"]
embedded-sdmmc = ["dep:embedded-sdmmc", "sdmmc"]
fatfs = ["dep:fatfs", "sdmmc"]

# L4x1
stm32l431 = [ "stm32l4/stm32l4x1" ]
Expand Down Expand Up @@ -203,3 +209,6 @@ required-features = ["rt"]
[[example]]
name = "adc_dma"
required-features = ["rt"]

[patch.crates-io]
fatfs = { git = "https://github.com/rafalh/rust-fatfs" }
24 changes: 23 additions & 1 deletion examples/rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::hal::prelude::*;
use crate::hal::serial::{Config, Serial};
use crate::hal::stm32;
use hal::hal::blocking::rng::Read;
use hal::rcc::Clk48Source;

macro_rules! uprint {
($serial:expr, $($arg:tt)*) => {
Expand Down Expand Up @@ -39,7 +40,28 @@ fn main() -> ! {

let clocks = rcc
.cfgr
.hsi48(true) // needed for RNG
// Needed for RNG.
.clk48_source({
#[cfg(any(
feature = "stm32l476",
feature = "stm32l486",
feature = "stm32l496",
feature = "stm32l4a6"
))]
{
Clk48Source::Hsi48
}

#[cfg(not(any(
feature = "stm32l476",
feature = "stm32l486",
feature = "stm32l496",
feature = "stm32l4a6"
)))]
{
Clk48Source::Msi
}
})
.sysclk(64.MHz())
.pclk1(32.MHz())
.freeze(&mut flash.acr, &mut pwr);
Expand Down
24 changes: 23 additions & 1 deletion examples/usb_serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
extern crate panic_semihosting;

use cortex_m_rt::entry;
use stm32l4xx_hal::rcc::Clk48Source;
use stm32l4xx_hal::usb::{Peripheral, UsbBus};
use stm32l4xx_hal::{prelude::*, stm32};
use usb_device::prelude::*;
Expand Down Expand Up @@ -43,7 +44,28 @@ fn main() -> ! {

let _clocks = rcc
.cfgr
.hsi48(true)
// Needed for USB.
.clk48_source({
#[cfg(any(
feature = "stm32l476",
feature = "stm32l486",
feature = "stm32l496",
feature = "stm32l4a6"
))]
{
Clk48Source::Hsi48
}

#[cfg(not(any(
feature = "stm32l476",
feature = "stm32l486",
feature = "stm32l496",
feature = "stm32l4a6"
)))]
{
Clk48Source::Msi
}
})
.sysclk(80.MHz())
.freeze(&mut flash.acr, &mut pwr);

Expand Down
5 changes: 4 additions & 1 deletion src/dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ macro_rules! dma {
/// A singleton that represents a single DMAx channel (channel X in this case)
///
/// This singleton has exclusive access to the registers of the DMAx channel X
#[derive(Debug)]
pub struct $CX;

impl $CX {
Expand Down Expand Up @@ -594,7 +595,9 @@ macro_rules! dma {
#[inline]
pub fn listen(&mut self, event: Event) {
match event {
Event::HalfTransfer => self.ccr().modify(|_, w| w.htie().set_bit()),
Event::HalfTransfer => {
self.ccr().modify(|_, w| w.htie().set_bit())
},
Event::TransferComplete => {
self.ccr().modify(|_, w| w.tcie().set_bit())
}
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ pub mod qspi;
pub mod rcc;
pub mod rng;
pub mod rtc;
pub mod sdmmc;
pub mod serial;
pub mod signature;
pub mod spi;
Expand Down
Loading