diff options
| author | xoviat <[email protected]> | 2025-12-08 08:19:24 -0600 |
|---|---|---|
| committer | xoviat <[email protected]> | 2025-12-08 08:19:24 -0600 |
| commit | c93da8fc6d76cd6978c0cfbfb3ab42b0285af8d8 (patch) | |
| tree | e745116af2890bdd54821eeb44aed44a3cffff3b /embassy-stm32/src/sdmmc/mod.rs | |
| parent | 2a738c147111569e4f0968020eec6fb5d5d4e754 (diff) | |
low-power: use scoped block stop
Co-authored-by: hjeldin <[email protected]>
Diffstat (limited to 'embassy-stm32/src/sdmmc/mod.rs')
| -rw-r--r-- | embassy-stm32/src/sdmmc/mod.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs index e05131040..37ef7099f 100644 --- a/embassy-stm32/src/sdmmc/mod.rs +++ b/embassy-stm32/src/sdmmc/mod.rs | |||
| @@ -675,7 +675,7 @@ impl<'d, T: Instance> Sdmmc<'d, T> { | |||
| 675 | d7: Option<Peri<'d, AnyPin>>, | 675 | d7: Option<Peri<'d, AnyPin>>, |
| 676 | config: Config, | 676 | config: Config, |
| 677 | ) -> Self { | 677 | ) -> Self { |
| 678 | rcc::enable_and_reset::<T>(); | 678 | rcc::enable_and_reset_without_stop::<T>(); |
| 679 | 679 | ||
| 680 | T::Interrupt::unpend(); | 680 | T::Interrupt::unpend(); |
| 681 | unsafe { T::Interrupt::enable() }; | 681 | unsafe { T::Interrupt::enable() }; |
| @@ -1075,6 +1075,7 @@ impl<'d, T: Instance> Sdmmc<'d, T> { | |||
| 1075 | /// Read a data block. | 1075 | /// Read a data block. |
| 1076 | #[inline] | 1076 | #[inline] |
| 1077 | pub async fn read_block(&mut self, block_idx: u32, buffer: &mut DataBlock) -> Result<(), Error> { | 1077 | pub async fn read_block(&mut self, block_idx: u32, buffer: &mut DataBlock) -> Result<(), Error> { |
| 1078 | let _scoped_block_stop = T::RCC_INFO.block_stop(); | ||
| 1078 | let card_capacity = self.card()?.get_capacity(); | 1079 | let card_capacity = self.card()?.get_capacity(); |
| 1079 | 1080 | ||
| 1080 | // NOTE(unsafe) DataBlock uses align 4 | 1081 | // NOTE(unsafe) DataBlock uses align 4 |
| @@ -1114,6 +1115,7 @@ impl<'d, T: Instance> Sdmmc<'d, T> { | |||
| 1114 | /// Read multiple data blocks. | 1115 | /// Read multiple data blocks. |
| 1115 | #[inline] | 1116 | #[inline] |
| 1116 | pub async fn read_blocks(&mut self, block_idx: u32, blocks: &mut [DataBlock]) -> Result<(), Error> { | 1117 | pub async fn read_blocks(&mut self, block_idx: u32, blocks: &mut [DataBlock]) -> Result<(), Error> { |
| 1118 | let _scoped_block_stop = T::RCC_INFO.block_stop(); | ||
| 1117 | let card_capacity = self.card()?.get_capacity(); | 1119 | let card_capacity = self.card()?.get_capacity(); |
| 1118 | 1120 | ||
| 1119 | // NOTE(unsafe) reinterpret buffer as &mut [u32] | 1121 | // NOTE(unsafe) reinterpret buffer as &mut [u32] |
| @@ -1160,6 +1162,7 @@ impl<'d, T: Instance> Sdmmc<'d, T> { | |||
| 1160 | 1162 | ||
| 1161 | /// Write a data block. | 1163 | /// Write a data block. |
| 1162 | pub async fn write_block(&mut self, block_idx: u32, buffer: &DataBlock) -> Result<(), Error> { | 1164 | pub async fn write_block(&mut self, block_idx: u32, buffer: &DataBlock) -> Result<(), Error> { |
| 1165 | let _scoped_block_stop = T::RCC_INFO.block_stop(); | ||
| 1163 | let card = self.card.as_mut().ok_or(Error::NoCard)?; | 1166 | let card = self.card.as_mut().ok_or(Error::NoCard)?; |
| 1164 | 1167 | ||
| 1165 | // NOTE(unsafe) DataBlock uses align 4 | 1168 | // NOTE(unsafe) DataBlock uses align 4 |
| @@ -1216,6 +1219,7 @@ impl<'d, T: Instance> Sdmmc<'d, T> { | |||
| 1216 | 1219 | ||
| 1217 | /// Write multiple data blocks. | 1220 | /// Write multiple data blocks. |
| 1218 | pub async fn write_blocks(&mut self, block_idx: u32, blocks: &[DataBlock]) -> Result<(), Error> { | 1221 | pub async fn write_blocks(&mut self, block_idx: u32, blocks: &[DataBlock]) -> Result<(), Error> { |
| 1222 | let _scoped_block_stop = T::RCC_INFO.block_stop(); | ||
| 1219 | let card = self.card.as_mut().ok_or(Error::NoCard)?; | 1223 | let card = self.card.as_mut().ok_or(Error::NoCard)?; |
| 1220 | 1224 | ||
| 1221 | // NOTE(unsafe) reinterpret buffer as &[u32] | 1225 | // NOTE(unsafe) reinterpret buffer as &[u32] |
| @@ -1542,6 +1546,8 @@ impl<'d, T: Instance> Sdmmc<'d, T> { | |||
| 1542 | /// | 1546 | /// |
| 1543 | /// SD only. | 1547 | /// SD only. |
| 1544 | pub async fn init_sd_card(&mut self, freq: Hertz) -> Result<(), Error> { | 1548 | pub async fn init_sd_card(&mut self, freq: Hertz) -> Result<(), Error> { |
| 1549 | let _scoped_block_stop = T::RCC_INFO.block_stop(); | ||
| 1550 | |||
| 1545 | self.init_internal(freq, SdmmcPeripheral::SdCard(Card::default())).await | 1551 | self.init_internal(freq, SdmmcPeripheral::SdCard(Card::default())).await |
| 1546 | } | 1552 | } |
| 1547 | 1553 | ||
| @@ -1711,6 +1717,8 @@ impl<'d, T: Instance> Sdmmc<'d, T> { | |||
| 1711 | /// | 1717 | /// |
| 1712 | /// eMMC only. | 1718 | /// eMMC only. |
| 1713 | pub async fn init_emmc(&mut self, freq: Hertz) -> Result<(), Error> { | 1719 | pub async fn init_emmc(&mut self, freq: Hertz) -> Result<(), Error> { |
| 1720 | let _scoped_block_stop = T::RCC_INFO.block_stop(); | ||
| 1721 | |||
| 1714 | self.init_internal(freq, SdmmcPeripheral::Emmc(Emmc::default())).await | 1722 | self.init_internal(freq, SdmmcPeripheral::Emmc(Emmc::default())).await |
| 1715 | } | 1723 | } |
| 1716 | 1724 | ||
| @@ -1845,6 +1853,7 @@ impl<'d, T: Instance> block_device_driver::BlockDevice<512> for Sdmmc<'d, T> { | |||
| 1845 | block_address: u32, | 1853 | block_address: u32, |
| 1846 | buf: &mut [aligned::Aligned<Self::Align, [u8; 512]>], | 1854 | buf: &mut [aligned::Aligned<Self::Align, [u8; 512]>], |
| 1847 | ) -> Result<(), Self::Error> { | 1855 | ) -> Result<(), Self::Error> { |
| 1856 | let _scoped_block_stop = T::RCC_INFO.block_stop(); | ||
| 1848 | // TODO: I think block_address needs to be adjusted by the partition start offset | 1857 | // TODO: I think block_address needs to be adjusted by the partition start offset |
| 1849 | if buf.len() == 1 { | 1858 | if buf.len() == 1 { |
| 1850 | let block = unsafe { &mut *(&mut buf[0] as *mut _ as *mut crate::sdmmc::DataBlock) }; | 1859 | let block = unsafe { &mut *(&mut buf[0] as *mut _ as *mut crate::sdmmc::DataBlock) }; |
| @@ -1862,6 +1871,7 @@ impl<'d, T: Instance> block_device_driver::BlockDevice<512> for Sdmmc<'d, T> { | |||
| 1862 | block_address: u32, | 1871 | block_address: u32, |
| 1863 | buf: &[aligned::Aligned<Self::Align, [u8; 512]>], | 1872 | buf: &[aligned::Aligned<Self::Align, [u8; 512]>], |
| 1864 | ) -> Result<(), Self::Error> { | 1873 | ) -> Result<(), Self::Error> { |
| 1874 | let _scoped_block_stop = T::RCC_INFO.block_stop(); | ||
| 1865 | // TODO: I think block_address needs to be adjusted by the partition start offset | 1875 | // TODO: I think block_address needs to be adjusted by the partition start offset |
| 1866 | if buf.len() == 1 { | 1876 | if buf.len() == 1 { |
| 1867 | let block = unsafe { &*(&buf[0] as *const _ as *const crate::sdmmc::DataBlock) }; | 1877 | let block = unsafe { &*(&buf[0] as *const _ as *const crate::sdmmc::DataBlock) }; |
