Merge pull request #1166 from embassy-rs/sdmmc-fix
fix embedded-sdmmc integration.
This commit is contained in:
		
						commit
						6ad2bcf97a
					
				
							
								
								
									
										2
									
								
								ci.sh
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								ci.sh
									
									
									
									
									
								
							@ -63,7 +63,7 @@ cargo batch  \
 | 
			
		||||
    --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features nightly,intrinsics \
 | 
			
		||||
    --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f410tb,defmt,exti,time-driver-any,unstable-traits \
 | 
			
		||||
    --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f411ce,defmt,exti,time-driver-any,unstable-traits \
 | 
			
		||||
    --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f429zi,log,exti,time-driver-any,unstable-traits \
 | 
			
		||||
    --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f429zi,log,exti,time-driver-any,unstable-traits,embedded-sdmmc \
 | 
			
		||||
    --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32h755zi-cm7,defmt,exti,time-driver-any,unstable-traits \
 | 
			
		||||
    --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32h7b3ai,defmt,exti,time-driver-any,unstable-traits \
 | 
			
		||||
    --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32l476vg,defmt,exti,time-driver-any,unstable-traits \
 | 
			
		||||
 | 
			
		||||
@ -58,7 +58,7 @@ cortex-m = "0.7.6"
 | 
			
		||||
futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
 | 
			
		||||
rand_core = "0.6.3"
 | 
			
		||||
sdio-host = "0.5.0"
 | 
			
		||||
embedded-sdmmc = { git = "https://github.com/thalesfragoso/embedded-sdmmc-rs", branch = "async", optional = true }
 | 
			
		||||
embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "46d1b1c2ff13e31e282ec1e352421721694f126a", optional = true }
 | 
			
		||||
critical-section = "1.1"
 | 
			
		||||
atomic-polyfill = "1.0.1"
 | 
			
		||||
stm32-metapac = { version = "0.1.0", path = "../stm32-metapac", features = ["rt"] }
 | 
			
		||||
@ -77,7 +77,6 @@ stm32-metapac = { version = "0.1.0", path = "../stm32-metapac", default-features
 | 
			
		||||
 | 
			
		||||
[features]
 | 
			
		||||
defmt = ["dep:defmt", "bxcan/unstable-defmt", "embassy-sync/defmt", "embassy-executor/defmt", "embassy-embedded-hal/defmt", "embassy-hal-common/defmt", "embedded-io?/defmt", "embassy-usb-driver?/defmt", "embassy-net-driver/defmt"]
 | 
			
		||||
sdmmc-rs = ["embedded-sdmmc"]
 | 
			
		||||
memory-x = ["stm32-metapac/memory-x"]
 | 
			
		||||
subghz = []
 | 
			
		||||
exti = []
 | 
			
		||||
 | 
			
		||||
@ -1532,7 +1532,7 @@ foreach_peripheral!(
 | 
			
		||||
    };
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
#[cfg(feature = "sdmmc-rs")]
 | 
			
		||||
#[cfg(feature = "embedded-sdmmc")]
 | 
			
		||||
mod sdmmc_rs {
 | 
			
		||||
    use core::future::Future;
 | 
			
		||||
 | 
			
		||||
@ -1540,7 +1540,7 @@ mod sdmmc_rs {
 | 
			
		||||
 | 
			
		||||
    use super::*;
 | 
			
		||||
 | 
			
		||||
    impl<'d, T: Instance, P: Pins<T>> BlockDevice for Sdmmc<'d, T, P> {
 | 
			
		||||
    impl<'d, T: Instance, Dma: SdmmcDma<T>> BlockDevice for Sdmmc<'d, T, Dma> {
 | 
			
		||||
        type Error = Error;
 | 
			
		||||
 | 
			
		||||
        type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a
 | 
			
		||||
@ -1558,19 +1558,14 @@ mod sdmmc_rs {
 | 
			
		||||
            _reason: &str,
 | 
			
		||||
        ) -> Self::ReadFuture<'a> {
 | 
			
		||||
            async move {
 | 
			
		||||
                let card_capacity = self.card()?.card_type;
 | 
			
		||||
                let inner = T::inner();
 | 
			
		||||
                let state = T::state();
 | 
			
		||||
                let mut address = start_block_idx.0;
 | 
			
		||||
 | 
			
		||||
                for block in blocks.iter_mut() {
 | 
			
		||||
                    let block: &mut [u8; 512] = &mut block.contents;
 | 
			
		||||
 | 
			
		||||
                    // NOTE(unsafe) Block uses align(4)
 | 
			
		||||
                    let buf = unsafe { &mut *(block as *mut [u8; 512] as *mut [u32; 128]) };
 | 
			
		||||
                    inner
 | 
			
		||||
                        .read_block(address, buf, card_capacity, state, self.config.data_transfer_timeout)
 | 
			
		||||
                        .await?;
 | 
			
		||||
                    let block = unsafe { &mut *(block as *mut _ as *mut DataBlock) };
 | 
			
		||||
                    self.read_block(address, block).await?;
 | 
			
		||||
                    address += 1;
 | 
			
		||||
                }
 | 
			
		||||
                Ok(())
 | 
			
		||||
@ -1579,19 +1574,14 @@ mod sdmmc_rs {
 | 
			
		||||
 | 
			
		||||
        fn write<'a>(&'a mut self, blocks: &'a [Block], start_block_idx: BlockIdx) -> Self::WriteFuture<'a> {
 | 
			
		||||
            async move {
 | 
			
		||||
                let card = self.card.as_mut().ok_or(Error::NoCard)?;
 | 
			
		||||
                let inner = T::inner();
 | 
			
		||||
                let state = T::state();
 | 
			
		||||
                let mut address = start_block_idx.0;
 | 
			
		||||
 | 
			
		||||
                for block in blocks.iter() {
 | 
			
		||||
                    let block: &[u8; 512] = &block.contents;
 | 
			
		||||
 | 
			
		||||
                    // NOTE(unsafe) DataBlock uses align 4
 | 
			
		||||
                    let buf = unsafe { &*(block as *const [u8; 512] as *const [u32; 128]) };
 | 
			
		||||
                    inner
 | 
			
		||||
                        .write_block(address, buf, card, state, self.config.data_transfer_timeout)
 | 
			
		||||
                        .await?;
 | 
			
		||||
                    let block = unsafe { &*(block as *const _ as *const DataBlock) };
 | 
			
		||||
                    self.write_block(address, block).await?;
 | 
			
		||||
                    address += 1;
 | 
			
		||||
                }
 | 
			
		||||
                Ok(())
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user