diff options
| author | Peter Krull <[email protected]> | 2024-09-19 18:14:09 +0200 |
|---|---|---|
| committer | Peter Krull <[email protected]> | 2024-09-19 18:14:09 +0200 |
| commit | 907d55ea82ac09b507afdc7ccb4d5997f827a748 (patch) | |
| tree | 37d6433cbefb8c1b6c677304f2791614d04794ec | |
| parent | d7780fcf83a8a35d7b09e5df7b62dd8218436715 (diff) | |
stm32: Added request_pause to DMA, and use it for RingBufferedUartRx
| -rw-r--r-- | embassy-stm32/src/dma/dma_bdma.rs | 54 | ||||
| -rw-r--r-- | embassy-stm32/src/usart/ringbuffered.rs | 2 |
2 files changed, 53 insertions, 3 deletions
diff --git a/embassy-stm32/src/dma/dma_bdma.rs b/embassy-stm32/src/dma/dma_bdma.rs index df041c4e9..2887536c3 100644 --- a/embassy-stm32/src/dma/dma_bdma.rs +++ b/embassy-stm32/src/dma/dma_bdma.rs | |||
| @@ -493,6 +493,26 @@ impl AnyChannel { | |||
| 493 | } | 493 | } |
| 494 | } | 494 | } |
| 495 | 495 | ||
| 496 | fn request_pause(&self) { | ||
| 497 | let info = self.info(); | ||
| 498 | match self.info().dma { | ||
| 499 | #[cfg(dma)] | ||
| 500 | DmaInfo::Dma(r) => { | ||
| 501 | r.st(info.num).cr().modify(|w| { | ||
| 502 | // Disable the channel without overwriting the existing configuration | ||
| 503 | w.set_en(false); | ||
| 504 | }); | ||
| 505 | } | ||
| 506 | #[cfg(bdma)] | ||
| 507 | DmaInfo::Bdma(r) => { | ||
| 508 | r.ch(info.num).cr().modify(|w| { | ||
| 509 | // Disable the channel without overwriting the existing configuration | ||
| 510 | w.set_en(false); | ||
| 511 | }); | ||
| 512 | } | ||
| 513 | } | ||
| 514 | } | ||
| 515 | |||
| 496 | fn is_running(&self) -> bool { | 516 | fn is_running(&self) -> bool { |
| 497 | let info = self.info(); | 517 | let info = self.info(); |
| 498 | match self.info().dma { | 518 | match self.info().dma { |
| @@ -667,12 +687,22 @@ impl<'a> Transfer<'a> { | |||
| 667 | } | 687 | } |
| 668 | 688 | ||
| 669 | /// Request the transfer to stop. | 689 | /// Request the transfer to stop. |
| 690 | /// The configuration for this channel will **not be preserved**. If you need to restart the transfer | ||
| 691 | /// at a later point with the same configuration, see [`request_pause`](Self::request_pause) instead. | ||
| 670 | /// | 692 | /// |
| 671 | /// This doesn't immediately stop the transfer, you have to wait until [`is_running`](Self::is_running) returns false. | 693 | /// This doesn't immediately stop the transfer, you have to wait until [`is_running`](Self::is_running) returns false. |
| 672 | pub fn request_stop(&mut self) { | 694 | pub fn request_stop(&mut self) { |
| 673 | self.channel.request_stop() | 695 | self.channel.request_stop() |
| 674 | } | 696 | } |
| 675 | 697 | ||
| 698 | /// Request the transfer to pause, keeping the existing configuration for this channel. | ||
| 699 | /// To restart the transfer, call [`start`](Self::start) again. | ||
| 700 | /// | ||
| 701 | /// This doesn't immediately stop the transfer, you have to wait until [`is_running`](Self::is_running) returns false. | ||
| 702 | pub fn request_pause(&mut self) { | ||
| 703 | self.channel.request_pause() | ||
| 704 | } | ||
| 705 | |||
| 676 | /// Return whether this transfer is still running. | 706 | /// Return whether this transfer is still running. |
| 677 | /// | 707 | /// |
| 678 | /// If this returns `false`, it can be because either the transfer finished, or | 708 | /// If this returns `false`, it can be because either the transfer finished, or |
| @@ -846,13 +876,23 @@ impl<'a, W: Word> ReadableRingBuffer<'a, W> { | |||
| 846 | DmaCtrlImpl(self.channel.reborrow()).set_waker(waker); | 876 | DmaCtrlImpl(self.channel.reborrow()).set_waker(waker); |
| 847 | } | 877 | } |
| 848 | 878 | ||
| 849 | /// Request DMA to stop. | 879 | /// Request the DMA to stop. |
| 880 | /// The configuration for this channel will **not be preserved**. If you need to restart the transfer | ||
| 881 | /// at a later point with the same configuration, see [`request_pause`](Self::request_pause) instead. | ||
| 850 | /// | 882 | /// |
| 851 | /// This doesn't immediately stop the transfer, you have to wait until [`is_running`](Self::is_running) returns false. | 883 | /// This doesn't immediately stop the transfer, you have to wait until [`is_running`](Self::is_running) returns false. |
| 852 | pub fn request_stop(&mut self) { | 884 | pub fn request_stop(&mut self) { |
| 853 | self.channel.request_stop() | 885 | self.channel.request_stop() |
| 854 | } | 886 | } |
| 855 | 887 | ||
| 888 | /// Request the transfer to pause, keeping the existing configuration for this channel. | ||
| 889 | /// To restart the transfer, call [`start`](Self::start) again. | ||
| 890 | /// | ||
| 891 | /// This doesn't immediately stop the transfer, you have to wait until [`is_running`](Self::is_running) returns false. | ||
| 892 | pub fn request_pause(&mut self) { | ||
| 893 | self.channel.request_pause() | ||
| 894 | } | ||
| 895 | |||
| 856 | /// Return whether DMA is still running. | 896 | /// Return whether DMA is still running. |
| 857 | /// | 897 | /// |
| 858 | /// If this returns `false`, it can be because either the transfer finished, or | 898 | /// If this returns `false`, it can be because either the transfer finished, or |
| @@ -977,13 +1017,23 @@ impl<'a, W: Word> WritableRingBuffer<'a, W> { | |||
| 977 | DmaCtrlImpl(self.channel.reborrow()).set_waker(waker); | 1017 | DmaCtrlImpl(self.channel.reborrow()).set_waker(waker); |
| 978 | } | 1018 | } |
| 979 | 1019 | ||
| 980 | /// Request DMA to stop. | 1020 | /// Request the DMA to stop. |
| 1021 | /// The configuration for this channel will **not be preserved**. If you need to restart the transfer | ||
| 1022 | /// at a later point with the same configuration, see [`request_pause`](Self::request_pause) instead. | ||
| 981 | /// | 1023 | /// |
| 982 | /// This doesn't immediately stop the transfer, you have to wait until [`is_running`](Self::is_running) returns false. | 1024 | /// This doesn't immediately stop the transfer, you have to wait until [`is_running`](Self::is_running) returns false. |
| 983 | pub fn request_stop(&mut self) { | 1025 | pub fn request_stop(&mut self) { |
| 984 | self.channel.request_stop() | 1026 | self.channel.request_stop() |
| 985 | } | 1027 | } |
| 986 | 1028 | ||
| 1029 | /// Request the transfer to pause, keeping the existing configuration for this channel. | ||
| 1030 | /// To restart the transfer, call [`start`](Self::start) again. | ||
| 1031 | /// | ||
| 1032 | /// This doesn't immediately stop the transfer, you have to wait until [`is_running`](Self::is_running) returns false. | ||
| 1033 | pub fn request_pause(&mut self) { | ||
| 1034 | self.channel.request_pause() | ||
| 1035 | } | ||
| 1036 | |||
| 987 | /// Return whether DMA is still running. | 1037 | /// Return whether DMA is still running. |
| 988 | /// | 1038 | /// |
| 989 | /// If this returns `false`, it can be because either the transfer finished, or | 1039 | /// If this returns `false`, it can be because either the transfer finished, or |
diff --git a/embassy-stm32/src/usart/ringbuffered.rs b/embassy-stm32/src/usart/ringbuffered.rs index b0652046c..bb95af966 100644 --- a/embassy-stm32/src/usart/ringbuffered.rs +++ b/embassy-stm32/src/usart/ringbuffered.rs | |||
| @@ -120,7 +120,7 @@ impl<'d> RingBufferedUartRx<'d> { | |||
| 120 | 120 | ||
| 121 | /// Stop uart background receive | 121 | /// Stop uart background receive |
| 122 | fn teardown_uart(&mut self) { | 122 | fn teardown_uart(&mut self) { |
| 123 | self.ring_buf.request_stop(); | 123 | self.ring_buf.request_pause(); |
| 124 | 124 | ||
| 125 | let r = self.info.regs; | 125 | let r = self.info.regs; |
| 126 | // clear all interrupts and DMA Rx Request | 126 | // clear all interrupts and DMA Rx Request |
