diff options
| -rw-r--r-- | embassy-stm32f4/src/serial.rs | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/embassy-stm32f4/src/serial.rs b/embassy-stm32f4/src/serial.rs index 01348e32b..ea84a2278 100644 --- a/embassy-stm32f4/src/serial.rs +++ b/embassy-stm32f4/src/serial.rs | |||
| @@ -10,8 +10,9 @@ use core::sync::atomic::{self, Ordering}; | |||
| 10 | use core::task::{Context, Poll}; | 10 | use core::task::{Context, Poll}; |
| 11 | 11 | ||
| 12 | use embassy::interrupt::OwnedInterrupt; | 12 | use embassy::interrupt::OwnedInterrupt; |
| 13 | use embassy::uart::Uart; | ||
| 13 | use embassy::util::Signal; | 14 | use embassy::util::Signal; |
| 14 | use embedded_dma::{StaticReadBuffer, StaticWriteBuffer, WriteBuffer}; | 15 | use embedded_dma::StaticWriteBuffer; |
| 15 | 16 | ||
| 16 | use crate::hal::dma::config::DmaConfig; | 17 | use crate::hal::dma::config::DmaConfig; |
| 17 | use crate::hal::dma::traits::{PeriAddress, Stream}; | 18 | use crate::hal::dma::traits::{PeriAddress, Stream}; |
| @@ -135,16 +136,15 @@ impl Serial<USART1, Stream7<DMA2>, Stream2<DMA2>> { | |||
| 135 | 136 | ||
| 136 | STATE.rx_int.signal(()); | 137 | STATE.rx_int.signal(()); |
| 137 | } | 138 | } |
| 139 | } | ||
| 138 | 140 | ||
| 141 | impl Uart for Serial<USART1, Stream7<DMA2>, Stream2<DMA2>> { | ||
| 139 | /// Sends serial data. | 142 | /// Sends serial data. |
| 140 | /// | 143 | /// |
| 141 | /// `tx_buffer` is marked as static as per `embedded-dma` requirements. | 144 | /// `tx_buffer` is marked as static as per `embedded-dma` requirements. |
| 142 | /// It it safe to use a buffer with a non static lifetime if memory is not | 145 | /// It it safe to use a buffer with a non static lifetime if memory is not |
| 143 | /// reused until the future has finished. | 146 | /// reused until the future has finished. |
| 144 | pub fn send<'a, B: 'a>(&'a mut self, tx_buffer: B) -> impl Future<Output = ()> + 'a | 147 | fn send<'a>(&'a mut self, buf: &'a mut [u8]) -> dyn Future<Output = Result<(), Error>> { |
| 145 | where | ||
| 146 | B: StaticWriteBuffer<Word = u8>, | ||
| 147 | { | ||
| 148 | unsafe { INSTANCE = self }; | 148 | unsafe { INSTANCE = self }; |
| 149 | 149 | ||
| 150 | let tx_stream = self.tx_stream.take().unwrap(); | 150 | let tx_stream = self.tx_stream.take().unwrap(); |
| @@ -155,7 +155,7 @@ impl Serial<USART1, Stream7<DMA2>, Stream2<DMA2>> { | |||
| 155 | let mut tx_transfer = Transfer::init( | 155 | let mut tx_transfer = Transfer::init( |
| 156 | tx_stream, | 156 | tx_stream, |
| 157 | usart, | 157 | usart, |
| 158 | tx_buffer, | 158 | buf, |
| 159 | None, | 159 | None, |
| 160 | DmaConfig::default() | 160 | DmaConfig::default() |
| 161 | .transfer_complete_interrupt(true) | 161 | .transfer_complete_interrupt(true) |
| @@ -185,10 +185,7 @@ impl Serial<USART1, Stream7<DMA2>, Stream2<DMA2>> { | |||
| 185 | /// `rx_buffer` is marked as static as per `embedded-dma` requirements. | 185 | /// `rx_buffer` is marked as static as per `embedded-dma` requirements. |
| 186 | /// It it safe to use a buffer with a non static lifetime if memory is not | 186 | /// It it safe to use a buffer with a non static lifetime if memory is not |
| 187 | /// reused until the future has finished. | 187 | /// reused until the future has finished. |
| 188 | pub fn receive<'a, B: 'a>(&'a mut self, rx_buffer: B) -> impl Future<Output = B> + 'a | 188 | fn receive<'a>(&'a mut self, buf: &'a mut [u8]) -> dyn Future<Output = Result<(), Error>> { |
| 189 | where | ||
| 190 | B: StaticWriteBuffer<Word = u8> + Unpin, | ||
| 191 | { | ||
| 192 | unsafe { INSTANCE = self }; | 189 | unsafe { INSTANCE = self }; |
| 193 | 190 | ||
| 194 | let rx_stream = self.rx_stream.take().unwrap(); | 191 | let rx_stream = self.rx_stream.take().unwrap(); |
| @@ -199,7 +196,7 @@ impl Serial<USART1, Stream7<DMA2>, Stream2<DMA2>> { | |||
| 199 | let mut rx_transfer = Transfer::init( | 196 | let mut rx_transfer = Transfer::init( |
| 200 | rx_stream, | 197 | rx_stream, |
| 201 | usart, | 198 | usart, |
| 202 | rx_buffer, | 199 | buf.static_write_buffer(), |
| 203 | None, | 200 | None, |
| 204 | DmaConfig::default() | 201 | DmaConfig::default() |
| 205 | .transfer_complete_interrupt(true) | 202 | .transfer_complete_interrupt(true) |
| @@ -217,8 +214,6 @@ impl Serial<USART1, Stream7<DMA2>, Stream2<DMA2>> { | |||
| 217 | let (rx_stream, usart, buf, _) = rx_transfer.free(); | 214 | let (rx_stream, usart, buf, _) = rx_transfer.free(); |
| 218 | self.rx_stream.replace(rx_stream); | 215 | self.rx_stream.replace(rx_stream); |
| 219 | self.usart.replace(usart); | 216 | self.usart.replace(usart); |
| 220 | |||
| 221 | buf | ||
| 222 | } | 217 | } |
| 223 | } | 218 | } |
| 224 | } | 219 | } |
