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 | |
| parent | 2a738c147111569e4f0968020eec6fb5d5d4e754 (diff) | |
low-power: use scoped block stop
Co-authored-by: hjeldin <[email protected]>
| -rw-r--r-- | embassy-stm32/src/i2c/mod.rs | 2 | ||||
| -rw-r--r-- | embassy-stm32/src/i2c/v1.rs | 7 | ||||
| -rw-r--r-- | embassy-stm32/src/i2c/v2.rs | 8 | ||||
| -rw-r--r-- | embassy-stm32/src/qspi/mod.rs | 4 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/mod.rs | 10 | ||||
| -rw-r--r-- | embassy-stm32/src/sdmmc/mod.rs | 12 | ||||
| -rw-r--r-- | embassy-stm32/src/spi/mod.rs | 10 | ||||
| -rw-r--r-- | embassy-stm32/src/usart/mod.rs | 8 |
8 files changed, 53 insertions, 8 deletions
diff --git a/embassy-stm32/src/i2c/mod.rs b/embassy-stm32/src/i2c/mod.rs index ee60c3f44..0bf430ffc 100644 --- a/embassy-stm32/src/i2c/mod.rs +++ b/embassy-stm32/src/i2c/mod.rs | |||
| @@ -226,7 +226,7 @@ impl<'d, M: Mode> I2c<'d, M, Master> { | |||
| 226 | } | 226 | } |
| 227 | 227 | ||
| 228 | fn enable_and_init(&mut self, config: Config) { | 228 | fn enable_and_init(&mut self, config: Config) { |
| 229 | self.info.rcc.enable_and_reset(); | 229 | self.info.rcc.enable_and_reset_without_stop(); |
| 230 | self.init(config); | 230 | self.init(config); |
| 231 | } | 231 | } |
| 232 | } | 232 | } |
diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs index 128a58db7..81a6d74c1 100644 --- a/embassy-stm32/src/i2c/v1.rs +++ b/embassy-stm32/src/i2c/v1.rs | |||
| @@ -529,6 +529,7 @@ impl<'d, IM: MasterMode> I2c<'d, Async, IM> { | |||
| 529 | 529 | ||
| 530 | /// Write. | 530 | /// Write. |
| 531 | pub async fn write(&mut self, address: u8, write_buffer: &[u8]) -> Result<(), Error> { | 531 | pub async fn write(&mut self, address: u8, write_buffer: &[u8]) -> Result<(), Error> { |
| 532 | let _scoped_block_stop = self.info.rcc.block_stop(); | ||
| 532 | self.write_frame(address, write_buffer, FrameOptions::FirstAndLastFrame) | 533 | self.write_frame(address, write_buffer, FrameOptions::FirstAndLastFrame) |
| 533 | .await?; | 534 | .await?; |
| 534 | 535 | ||
| @@ -537,6 +538,7 @@ impl<'d, IM: MasterMode> I2c<'d, Async, IM> { | |||
| 537 | 538 | ||
| 538 | /// Read. | 539 | /// Read. |
| 539 | pub async fn read(&mut self, address: u8, read_buffer: &mut [u8]) -> Result<(), Error> { | 540 | pub async fn read(&mut self, address: u8, read_buffer: &mut [u8]) -> Result<(), Error> { |
| 541 | let _scoped_block_stop = self.info.rcc.block_stop(); | ||
| 540 | self.read_frame(address, read_buffer, FrameOptions::FirstAndLastFrame) | 542 | self.read_frame(address, read_buffer, FrameOptions::FirstAndLastFrame) |
| 541 | .await?; | 543 | .await?; |
| 542 | 544 | ||
| @@ -701,6 +703,7 @@ impl<'d, IM: MasterMode> I2c<'d, Async, IM> { | |||
| 701 | 703 | ||
| 702 | /// Write, restart, read. | 704 | /// Write, restart, read. |
| 703 | pub async fn write_read(&mut self, address: u8, write_buffer: &[u8], read_buffer: &mut [u8]) -> Result<(), Error> { | 705 | pub async fn write_read(&mut self, address: u8, write_buffer: &[u8], read_buffer: &mut [u8]) -> Result<(), Error> { |
| 706 | let _scoped_block_stop = self.info.rcc.block_stop(); | ||
| 704 | // Check empty read buffer before starting transaction. Otherwise, we would not generate the | 707 | // Check empty read buffer before starting transaction. Otherwise, we would not generate the |
| 705 | // stop condition below. | 708 | // stop condition below. |
| 706 | if read_buffer.is_empty() { | 709 | if read_buffer.is_empty() { |
| @@ -719,6 +722,7 @@ impl<'d, IM: MasterMode> I2c<'d, Async, IM> { | |||
| 719 | /// | 722 | /// |
| 720 | /// [transaction contract]: embedded_hal_1::i2c::I2c::transaction | 723 | /// [transaction contract]: embedded_hal_1::i2c::I2c::transaction |
| 721 | pub async fn transaction(&mut self, address: u8, operations: &mut [Operation<'_>]) -> Result<(), Error> { | 724 | pub async fn transaction(&mut self, address: u8, operations: &mut [Operation<'_>]) -> Result<(), Error> { |
| 725 | let _scoped_block_stop = self.info.rcc.block_stop(); | ||
| 722 | for (op, frame) in operation_frames(operations)? { | 726 | for (op, frame) in operation_frames(operations)? { |
| 723 | match op { | 727 | match op { |
| 724 | Operation::Read(read_buffer) => self.read_frame(address, read_buffer, frame).await?, | 728 | Operation::Read(read_buffer) => self.read_frame(address, read_buffer, frame).await?, |
| @@ -1357,6 +1361,7 @@ impl<'d> I2c<'d, Async, MultiMaster> { | |||
| 1357 | /// (Read/Write) and the matched address. This method will suspend until | 1361 | /// (Read/Write) and the matched address. This method will suspend until |
| 1358 | /// an address match occurs. | 1362 | /// an address match occurs. |
| 1359 | pub async fn listen(&mut self) -> Result<SlaveCommand, Error> { | 1363 | pub async fn listen(&mut self) -> Result<SlaveCommand, Error> { |
| 1364 | let _scoped_block_stop = self.info.rcc.block_stop(); | ||
| 1360 | trace!("I2C slave: starting async listen for address match"); | 1365 | trace!("I2C slave: starting async listen for address match"); |
| 1361 | let state = self.state; | 1366 | let state = self.state; |
| 1362 | let info = self.info; | 1367 | let info = self.info; |
| @@ -1421,6 +1426,7 @@ impl<'d> I2c<'d, Async, MultiMaster> { | |||
| 1421 | /// | 1426 | /// |
| 1422 | /// Returns the number of bytes stored in the buffer (not total received). | 1427 | /// Returns the number of bytes stored in the buffer (not total received). |
| 1423 | pub async fn respond_to_write(&mut self, buffer: &mut [u8]) -> Result<usize, Error> { | 1428 | pub async fn respond_to_write(&mut self, buffer: &mut [u8]) -> Result<usize, Error> { |
| 1429 | let _scoped_block_stop = self.info.rcc.block_stop(); | ||
| 1424 | trace!("I2C slave: starting respond_to_write, buffer_len={}", buffer.len()); | 1430 | trace!("I2C slave: starting respond_to_write, buffer_len={}", buffer.len()); |
| 1425 | 1431 | ||
| 1426 | if buffer.is_empty() { | 1432 | if buffer.is_empty() { |
| @@ -1454,6 +1460,7 @@ impl<'d> I2c<'d, Async, MultiMaster> { | |||
| 1454 | /// | 1460 | /// |
| 1455 | /// Returns the total number of bytes transmitted (data + padding). | 1461 | /// Returns the total number of bytes transmitted (data + padding). |
| 1456 | pub async fn respond_to_read(&mut self, data: &[u8]) -> Result<usize, Error> { | 1462 | pub async fn respond_to_read(&mut self, data: &[u8]) -> Result<usize, Error> { |
| 1463 | let _scoped_block_stop = self.info.rcc.block_stop(); | ||
| 1457 | trace!("I2C slave: starting respond_to_read, data_len={}", data.len()); | 1464 | trace!("I2C slave: starting respond_to_read, data_len={}", data.len()); |
| 1458 | 1465 | ||
| 1459 | if data.is_empty() { | 1466 | if data.is_empty() { |
diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs index 7ad9978b1..32ce83d40 100644 --- a/embassy-stm32/src/i2c/v2.rs +++ b/embassy-stm32/src/i2c/v2.rs | |||
| @@ -1075,6 +1075,7 @@ impl<'d, IM: MasterMode> I2c<'d, Async, IM> { | |||
| 1075 | 1075 | ||
| 1076 | /// Write. | 1076 | /// Write. |
| 1077 | pub async fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Error> { | 1077 | pub async fn write(&mut self, address: u8, write: &[u8]) -> Result<(), Error> { |
| 1078 | let _scoped_block_stop = self.info.rcc.block_stop(); | ||
| 1078 | let timeout = self.timeout(); | 1079 | let timeout = self.timeout(); |
| 1079 | if write.is_empty() { | 1080 | if write.is_empty() { |
| 1080 | self.write_internal(address.into(), write, true, timeout) | 1081 | self.write_internal(address.into(), write, true, timeout) |
| @@ -1089,6 +1090,7 @@ impl<'d, IM: MasterMode> I2c<'d, Async, IM> { | |||
| 1089 | /// | 1090 | /// |
| 1090 | /// The buffers are concatenated in a single write transaction. | 1091 | /// The buffers are concatenated in a single write transaction. |
| 1091 | pub async fn write_vectored(&mut self, address: Address, write: &[&[u8]]) -> Result<(), Error> { | 1092 | pub async fn write_vectored(&mut self, address: Address, write: &[&[u8]]) -> Result<(), Error> { |
| 1093 | let _scoped_block_stop = self.info.rcc.block_stop(); | ||
| 1092 | let timeout = self.timeout(); | 1094 | let timeout = self.timeout(); |
| 1093 | 1095 | ||
| 1094 | if write.is_empty() { | 1096 | if write.is_empty() { |
| @@ -1120,6 +1122,7 @@ impl<'d, IM: MasterMode> I2c<'d, Async, IM> { | |||
| 1120 | 1122 | ||
| 1121 | /// Read. | 1123 | /// Read. |
| 1122 | pub async fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Error> { | 1124 | pub async fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Error> { |
| 1125 | let _scoped_block_stop = self.info.rcc.block_stop(); | ||
| 1123 | let timeout = self.timeout(); | 1126 | let timeout = self.timeout(); |
| 1124 | 1127 | ||
| 1125 | if buffer.is_empty() { | 1128 | if buffer.is_empty() { |
| @@ -1132,6 +1135,7 @@ impl<'d, IM: MasterMode> I2c<'d, Async, IM> { | |||
| 1132 | 1135 | ||
| 1133 | /// Write, restart, read. | 1136 | /// Write, restart, read. |
| 1134 | pub async fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Error> { | 1137 | pub async fn write_read(&mut self, address: u8, write: &[u8], read: &mut [u8]) -> Result<(), Error> { |
| 1138 | let _scoped_block_stop = self.info.rcc.block_stop(); | ||
| 1135 | let timeout = self.timeout(); | 1139 | let timeout = self.timeout(); |
| 1136 | 1140 | ||
| 1137 | if write.is_empty() { | 1141 | if write.is_empty() { |
| @@ -1157,6 +1161,7 @@ impl<'d, IM: MasterMode> I2c<'d, Async, IM> { | |||
| 1157 | /// | 1161 | /// |
| 1158 | /// [transaction contract]: embedded_hal_1::i2c::I2c::transaction | 1162 | /// [transaction contract]: embedded_hal_1::i2c::I2c::transaction |
| 1159 | pub async fn transaction(&mut self, addr: u8, operations: &mut [Operation<'_>]) -> Result<(), Error> { | 1163 | pub async fn transaction(&mut self, addr: u8, operations: &mut [Operation<'_>]) -> Result<(), Error> { |
| 1164 | let _scoped_block_stop = self.info.rcc.block_stop(); | ||
| 1160 | if operations.is_empty() { | 1165 | if operations.is_empty() { |
| 1161 | return Err(Error::ZeroLengthTransfer); | 1166 | return Err(Error::ZeroLengthTransfer); |
| 1162 | } | 1167 | } |
| @@ -1677,6 +1682,7 @@ impl<'d, M: Mode> I2c<'d, M, MultiMaster> { | |||
| 1677 | /// | 1682 | /// |
| 1678 | /// The listen method is an asynchronous method but it does not require DMA to be asynchronous. | 1683 | /// The listen method is an asynchronous method but it does not require DMA to be asynchronous. |
| 1679 | pub async fn listen(&mut self) -> Result<SlaveCommand, Error> { | 1684 | pub async fn listen(&mut self) -> Result<SlaveCommand, Error> { |
| 1685 | let _scoped_block_stop = self.info.rcc.block_stop(); | ||
| 1680 | let state = self.state; | 1686 | let state = self.state; |
| 1681 | self.info.regs.cr1().modify(|reg| { | 1687 | self.info.regs.cr1().modify(|reg| { |
| 1682 | reg.set_addrie(true); | 1688 | reg.set_addrie(true); |
| @@ -1733,12 +1739,14 @@ impl<'d> I2c<'d, Async, MultiMaster> { | |||
| 1733 | /// | 1739 | /// |
| 1734 | /// Returns the total number of bytes received. | 1740 | /// Returns the total number of bytes received. |
| 1735 | pub async fn respond_to_write(&mut self, buffer: &mut [u8]) -> Result<usize, Error> { | 1741 | pub async fn respond_to_write(&mut self, buffer: &mut [u8]) -> Result<usize, Error> { |
| 1742 | let _scoped_block_stop = self.info.rcc.block_stop(); | ||
| 1736 | let timeout = self.timeout(); | 1743 | let timeout = self.timeout(); |
| 1737 | timeout.with(self.read_dma_internal_slave(buffer, timeout)).await | 1744 | timeout.with(self.read_dma_internal_slave(buffer, timeout)).await |
| 1738 | } | 1745 | } |
| 1739 | 1746 | ||
| 1740 | /// Respond to a read request from an I2C master. | 1747 | /// Respond to a read request from an I2C master. |
| 1741 | pub async fn respond_to_read(&mut self, write: &[u8]) -> Result<SendStatus, Error> { | 1748 | pub async fn respond_to_read(&mut self, write: &[u8]) -> Result<SendStatus, Error> { |
| 1749 | let _scoped_block_stop = self.info.rcc.block_stop(); | ||
| 1742 | let timeout = self.timeout(); | 1750 | let timeout = self.timeout(); |
| 1743 | timeout.with(self.write_dma_internal_slave(write, timeout)).await | 1751 | timeout.with(self.write_dma_internal_slave(write, timeout)).await |
| 1744 | } | 1752 | } |
diff --git a/embassy-stm32/src/qspi/mod.rs b/embassy-stm32/src/qspi/mod.rs index bb4f4f1d0..1f47f4845 100644 --- a/embassy-stm32/src/qspi/mod.rs +++ b/embassy-stm32/src/qspi/mod.rs | |||
| @@ -111,7 +111,7 @@ impl<'d, T: Instance, M: PeriMode> Qspi<'d, T, M> { | |||
| 111 | config: Config, | 111 | config: Config, |
| 112 | fsel: FlashSelection, | 112 | fsel: FlashSelection, |
| 113 | ) -> Self { | 113 | ) -> Self { |
| 114 | rcc::enable_and_reset::<T>(); | 114 | rcc::enable_and_reset_without_stop::<T>(); |
| 115 | 115 | ||
| 116 | while T::REGS.sr().read().busy() {} | 116 | while T::REGS.sr().read().busy() {} |
| 117 | 117 | ||
| @@ -403,6 +403,7 @@ impl<'d, T: Instance> Qspi<'d, T, Async> { | |||
| 403 | 403 | ||
| 404 | /// Async read data, using DMA. | 404 | /// Async read data, using DMA. |
| 405 | pub async fn read_dma(&mut self, buf: &mut [u8], transaction: TransferConfig) { | 405 | pub async fn read_dma(&mut self, buf: &mut [u8], transaction: TransferConfig) { |
| 406 | let _scoped_block_stop = T::RCC_INFO.block_stop(); | ||
| 406 | let transfer = self.start_read_transfer(transaction, buf); | 407 | let transfer = self.start_read_transfer(transaction, buf); |
| 407 | transfer.await; | 408 | transfer.await; |
| 408 | } | 409 | } |
| @@ -443,6 +444,7 @@ impl<'d, T: Instance> Qspi<'d, T, Async> { | |||
| 443 | 444 | ||
| 444 | /// Async write data, using DMA. | 445 | /// Async write data, using DMA. |
| 445 | pub async fn write_dma(&mut self, buf: &[u8], transaction: TransferConfig) { | 446 | pub async fn write_dma(&mut self, buf: &[u8], transaction: TransferConfig) { |
| 447 | let _scoped_block_stop = T::RCC_INFO.block_stop(); | ||
| 446 | let transfer = self.start_write_transfer(transaction, buf); | 448 | let transfer = self.start_write_transfer(transaction, buf); |
| 447 | transfer.await; | 449 | transfer.await; |
| 448 | } | 450 | } |
diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs index a33ec5d7d..2a9a1595a 100644 --- a/embassy-stm32/src/rcc/mod.rs +++ b/embassy-stm32/src/rcc/mod.rs | |||
| @@ -498,6 +498,16 @@ pub fn enable_and_reset<T: RccPeripheral>() { | |||
| 498 | T::RCC_INFO.enable_and_reset(); | 498 | T::RCC_INFO.enable_and_reset(); |
| 499 | } | 499 | } |
| 500 | 500 | ||
| 501 | /// Enables and resets peripheral `T` without incrementing the stop refcount. | ||
| 502 | /// | ||
| 503 | /// # Safety | ||
| 504 | /// | ||
| 505 | /// Peripheral must not be in use. | ||
| 506 | // TODO: should this be `unsafe`? | ||
| 507 | pub fn enable_and_reset_without_stop<T: RccPeripheral>() { | ||
| 508 | T::RCC_INFO.enable_and_reset_without_stop(); | ||
| 509 | } | ||
| 510 | |||
| 501 | /// Disables peripheral `T`. | 511 | /// Disables peripheral `T`. |
| 502 | /// | 512 | /// |
| 503 | /// # Safety | 513 | /// # Safety |
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) }; |
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index 3b39fd2fb..c90e0cef4 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs | |||
| @@ -230,7 +230,7 @@ impl<'d, M: PeriMode, CM: CommunicationMode> Spi<'d, M, CM> { | |||
| 230 | let cpol = config.raw_polarity(); | 230 | let cpol = config.raw_polarity(); |
| 231 | let lsbfirst = config.raw_byte_order(); | 231 | let lsbfirst = config.raw_byte_order(); |
| 232 | 232 | ||
| 233 | self.info.rcc.enable_and_reset(); | 233 | self.info.rcc.enable_and_reset_without_stop(); |
| 234 | 234 | ||
| 235 | /* | 235 | /* |
| 236 | - Software NSS management (SSM = 1) | 236 | - Software NSS management (SSM = 1) |
| @@ -848,6 +848,7 @@ impl<'d> Spi<'d, Async, Master> { | |||
| 848 | impl<'d, CM: CommunicationMode> Spi<'d, Async, CM> { | 848 | impl<'d, CM: CommunicationMode> Spi<'d, Async, CM> { |
| 849 | /// SPI write, using DMA. | 849 | /// SPI write, using DMA. |
| 850 | pub async fn write<W: Word>(&mut self, data: &[W]) -> Result<(), Error> { | 850 | pub async fn write<W: Word>(&mut self, data: &[W]) -> Result<(), Error> { |
| 851 | let _scoped_block_stop = self.info.rcc.block_stop(); | ||
| 851 | if data.is_empty() { | 852 | if data.is_empty() { |
| 852 | return Ok(()); | 853 | return Ok(()); |
| 853 | } | 854 | } |
| @@ -879,6 +880,7 @@ impl<'d, CM: CommunicationMode> Spi<'d, Async, CM> { | |||
| 879 | /// SPI read, using DMA. | 880 | /// SPI read, using DMA. |
| 880 | #[cfg(any(spi_v4, spi_v5, spi_v6))] | 881 | #[cfg(any(spi_v4, spi_v5, spi_v6))] |
| 881 | pub async fn read<W: Word>(&mut self, data: &mut [W]) -> Result<(), Error> { | 882 | pub async fn read<W: Word>(&mut self, data: &mut [W]) -> Result<(), Error> { |
| 883 | let _scoped_block_stop = self.info.rcc.block_stop(); | ||
| 882 | if data.is_empty() { | 884 | if data.is_empty() { |
| 883 | return Ok(()); | 885 | return Ok(()); |
| 884 | } | 886 | } |
| @@ -966,6 +968,7 @@ impl<'d, CM: CommunicationMode> Spi<'d, Async, CM> { | |||
| 966 | /// SPI read, using DMA. | 968 | /// SPI read, using DMA. |
| 967 | #[cfg(any(spi_v1, spi_v2, spi_v3))] | 969 | #[cfg(any(spi_v1, spi_v2, spi_v3))] |
| 968 | pub async fn read<W: Word>(&mut self, data: &mut [W]) -> Result<(), Error> { | 970 | pub async fn read<W: Word>(&mut self, data: &mut [W]) -> Result<(), Error> { |
| 971 | let _scoped_block_stop = self.info.rcc.block_stop(); | ||
| 969 | if data.is_empty() { | 972 | if data.is_empty() { |
| 970 | return Ok(()); | 973 | return Ok(()); |
| 971 | } | 974 | } |
| @@ -1013,6 +1016,7 @@ impl<'d, CM: CommunicationMode> Spi<'d, Async, CM> { | |||
| 1013 | } | 1016 | } |
| 1014 | 1017 | ||
| 1015 | async fn transfer_inner<W: Word>(&mut self, read: *mut [W], write: *const [W]) -> Result<(), Error> { | 1018 | async fn transfer_inner<W: Word>(&mut self, read: *mut [W], write: *const [W]) -> Result<(), Error> { |
| 1019 | let _scoped_block_stop = self.info.rcc.block_stop(); | ||
| 1016 | assert_eq!(read.len(), write.len()); | 1020 | assert_eq!(read.len(), write.len()); |
| 1017 | if read.len() == 0 { | 1021 | if read.len() == 0 { |
| 1018 | return Ok(()); | 1022 | return Ok(()); |
| @@ -1064,6 +1068,8 @@ impl<'d, CM: CommunicationMode> Spi<'d, Async, CM> { | |||
| 1064 | /// The transfer runs for `max(read.len(), write.len())` bytes. If `read` is shorter extra bytes are ignored. | 1068 | /// The transfer runs for `max(read.len(), write.len())` bytes. If `read` is shorter extra bytes are ignored. |
| 1065 | /// If `write` is shorter it is padded with zero bytes. | 1069 | /// If `write` is shorter it is padded with zero bytes. |
| 1066 | pub async fn transfer<W: Word>(&mut self, read: &mut [W], write: &[W]) -> Result<(), Error> { | 1070 | pub async fn transfer<W: Word>(&mut self, read: &mut [W], write: &[W]) -> Result<(), Error> { |
| 1071 | let _scoped_block_stop = self.info.rcc.block_stop(); | ||
| 1072 | |||
| 1067 | self.transfer_inner(read, write).await | 1073 | self.transfer_inner(read, write).await |
| 1068 | } | 1074 | } |
| 1069 | 1075 | ||
| @@ -1071,6 +1077,8 @@ impl<'d, CM: CommunicationMode> Spi<'d, Async, CM> { | |||
| 1071 | /// | 1077 | /// |
| 1072 | /// This writes the contents of `data` on MOSI, and puts the received data on MISO in `data`, at the same time. | 1078 | /// This writes the contents of `data` on MOSI, and puts the received data on MISO in `data`, at the same time. |
| 1073 | pub async fn transfer_in_place<W: Word>(&mut self, data: &mut [W]) -> Result<(), Error> { | 1079 | pub async fn transfer_in_place<W: Word>(&mut self, data: &mut [W]) -> Result<(), Error> { |
| 1080 | let _scoped_block_stop = self.info.rcc.block_stop(); | ||
| 1081 | |||
| 1074 | self.transfer_inner(data, data).await | 1082 | self.transfer_inner(data, data).await |
| 1075 | } | 1083 | } |
| 1076 | } | 1084 | } |
diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index 8047d6005..d2c361c61 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs | |||
| @@ -491,7 +491,7 @@ impl<'d> UartTx<'d, Async> { | |||
| 491 | 491 | ||
| 492 | /// Initiate an asynchronous UART write | 492 | /// Initiate an asynchronous UART write |
| 493 | pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error> { | 493 | pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error> { |
| 494 | let _ = self.info.rcc.block_stop(); | 494 | let _scoped_block_stop = self.info.rcc.block_stop(); |
| 495 | 495 | ||
| 496 | let r = self.info.regs; | 496 | let r = self.info.regs; |
| 497 | 497 | ||
| @@ -510,7 +510,7 @@ impl<'d> UartTx<'d, Async> { | |||
| 510 | 510 | ||
| 511 | /// Wait until transmission complete | 511 | /// Wait until transmission complete |
| 512 | pub async fn flush(&mut self) -> Result<(), Error> { | 512 | pub async fn flush(&mut self) -> Result<(), Error> { |
| 513 | let _ = self.info.rcc.block_stop(); | 513 | let _scoped_block_stop = self.info.rcc.block_stop(); |
| 514 | 514 | ||
| 515 | flush(&self.info, &self.state).await | 515 | flush(&self.info, &self.state).await |
| 516 | } | 516 | } |
| @@ -730,7 +730,7 @@ impl<'d> UartRx<'d, Async> { | |||
| 730 | 730 | ||
| 731 | /// Initiate an asynchronous UART read | 731 | /// Initiate an asynchronous UART read |
| 732 | pub async fn read(&mut self, buffer: &mut [u8]) -> Result<(), Error> { | 732 | pub async fn read(&mut self, buffer: &mut [u8]) -> Result<(), Error> { |
| 733 | let _ = self.info.rcc.block_stop(); | 733 | let _scoped_block_stop = self.info.rcc.block_stop(); |
| 734 | 734 | ||
| 735 | self.inner_read(buffer, false).await?; | 735 | self.inner_read(buffer, false).await?; |
| 736 | 736 | ||
| @@ -739,7 +739,7 @@ impl<'d> UartRx<'d, Async> { | |||
| 739 | 739 | ||
| 740 | /// Initiate an asynchronous read with idle line detection enabled | 740 | /// Initiate an asynchronous read with idle line detection enabled |
| 741 | pub async fn read_until_idle(&mut self, buffer: &mut [u8]) -> Result<usize, Error> { | 741 | pub async fn read_until_idle(&mut self, buffer: &mut [u8]) -> Result<usize, Error> { |
| 742 | let _ = self.info.rcc.block_stop(); | 742 | let _scoped_block_stop = self.info.rcc.block_stop(); |
| 743 | 743 | ||
| 744 | self.inner_read(buffer, true).await | 744 | self.inner_read(buffer, true).await |
| 745 | } | 745 | } |
