Skip to content

Commit

Permalink
Bugfix: sdmmc_card_t needs to be boxed, because ESP IDF takes long li…
Browse files Browse the repository at this point in the history
…ving references to it in the VFS layer
  • Loading branch information
ivmarkov committed Aug 5, 2024
1 parent 71e7e87 commit b186a3b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub mod prelude;
pub mod reset;
pub mod rmt;
pub mod rom;
#[cfg(feature = "experimental")]
#[cfg(all(feature = "experimental", feature = "alloc"))]
pub mod sd;
pub mod spi;
pub mod sys;
Expand Down
8 changes: 5 additions & 3 deletions src/sd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use spi::SdSpiHostDriver;
pub mod mmc;
pub mod spi;

extern crate alloc;

const _SDMMC_HOST_FLAG_SPI: u32 = 1 << 3;
const _SDMMC_HOST_FLAG_DDR: u32 = 1 << 4;
const _SDMMC_HOST_FLAG_DEINIT_ARG: u32 = 1 << 5;
Expand Down Expand Up @@ -138,7 +140,7 @@ pub mod config {
/// Currently, all interaction with the SD-Card driver is via the native, unsafe `sys::sdmmc_*` functions.
pub struct SdCardDriver<T> {
_host: T,
card: sdmmc_card_t,
card: alloc::boxed::Box<sdmmc_card_t>,
}

impl<T> SdCardDriver<T> {
Expand Down Expand Up @@ -218,9 +220,9 @@ where
pwr_ctrl_handle: core::ptr::null_mut() as _,
};

let mut card: sdmmc_card_t = Default::default();
let mut card: sdmmc_card_t = alloc::boxed::Box::new(Default::default());

esp!(unsafe { sdmmc_card_init(&configuration, &mut card) })?;
esp!(unsafe { sdmmc_card_init(&configuration, &mut *card) })?;

Ok(Self { _host: host, card })
}
Expand Down

0 comments on commit b186a3b

Please sign in to comment.