diff options
| author | huntc <[email protected]> | 2021-12-12 17:47:38 +1100 |
|---|---|---|
| committer | huntc <[email protected]> | 2021-12-12 17:52:17 +1100 |
| commit | dc3469b297be766382550c5ff031751c6dc2d47d (patch) | |
| tree | a81f00e45d5bc3d78fa5ca238f92f386294c1e59 | |
| parent | dce3f8c47df611b51c47559ba8f4c301eb86af95 (diff) | |
Documents the nRF BufferedUarte problem
Please see https://github.com/embassy-rs/embassy/issues/536 for the rationale.
| -rw-r--r-- | embassy-nrf/src/buffered_uarte.rs | 13 | ||||
| -rw-r--r-- | embassy-nrf/src/uarte.rs | 6 | ||||
| -rw-r--r-- | examples/nrf/src/bin/buffered_uart.rs | 6 |
3 files changed, 18 insertions, 7 deletions
diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs index e3ca74384..45e8afc4b 100644 --- a/embassy-nrf/src/buffered_uarte.rs +++ b/embassy-nrf/src/buffered_uarte.rs | |||
| @@ -1,6 +1,17 @@ | |||
| 1 | //! Async buffered UART | 1 | //! Async buffered UART |
| 2 | //! | 2 | //! |
| 3 | //! Please ee [uarte] to understand when [BufferedUarte] should be used. | 3 | //! WARNING!!! The functionality provided here is intended to be used only |
| 4 | //! in situations where hardware flow control are available i.e. CTS and RTS. | ||
| 5 | //! This is a problem that should be addressed at a later stage and can be | ||
| 6 | //! fully explained at https://github.com/embassy-rs/embassy/issues/536. | ||
| 7 | //! | ||
| 8 | //! Note that discarding a future from a read or write operation may lead to losing | ||
| 9 | //! data. For example, when using `futures_util::future::select` and completion occurs | ||
| 10 | //! on the "other" future, you should capture the incomplete future and continue to use | ||
| 11 | //! it for the next read or write. This pattern is a consideration for all IO, and not | ||
| 12 | //! just serial communications. | ||
| 13 | //! | ||
| 14 | //! Please also see [crate::uarte] to understand when [BufferedUarte] should be used. | ||
| 4 | 15 | ||
| 5 | use core::cmp::min; | 16 | use core::cmp::min; |
| 6 | use core::marker::PhantomData; | 17 | use core::marker::PhantomData; |
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs index 72dcd41b2..ff781cabd 100644 --- a/embassy-nrf/src/uarte.rs +++ b/embassy-nrf/src/uarte.rs | |||
| @@ -2,14 +2,14 @@ | |||
| 2 | 2 | ||
| 3 | //! Async UART | 3 | //! Async UART |
| 4 | //! | 4 | //! |
| 5 | //! Async UART is provided in two flavors - this one and also [buffered_uarte::BufferedUarte]. | 5 | //! Async UART is provided in two flavors - this one and also [crate::buffered_uarte::BufferedUarte]. |
| 6 | //! The [Uarte] here is useful for those use-cases where reading the UARTE peripheral is | 6 | //! The [Uarte] here is useful for those use-cases where reading the UARTE peripheral is |
| 7 | //! exclusively awaited on. If the [Uarte] is required to be awaited on with some other future, | 7 | //! exclusively awaited on. If the [Uarte] is required to be awaited on with some other future, |
| 8 | //! for example when using `futures_util::future::select`, then you should consider | 8 | //! for example when using `futures_util::future::select`, then you should consider |
| 9 | //! [buffered_uarte::BufferedUarte] so that reads may continue while processing these | 9 | //! [crate::buffered_uarte::BufferedUarte] so that reads may continue while processing these |
| 10 | //! other futures. If you do not then you may lose data between reads. | 10 | //! other futures. If you do not then you may lose data between reads. |
| 11 | //! | 11 | //! |
| 12 | //! An advantage of the [Uarte] has over [buffered_uarte::BufferedUarte] is that less | 12 | //! An advantage of the [Uarte] has over [crate::buffered_uarte::BufferedUarte] is that less |
| 13 | //! memory may be used given that buffers are passed in directly to its read and write | 13 | //! memory may be used given that buffers are passed in directly to its read and write |
| 14 | //! methods. | 14 | //! methods. |
| 15 | 15 | ||
diff --git a/examples/nrf/src/bin/buffered_uart.rs b/examples/nrf/src/bin/buffered_uart.rs index c3e07e44a..a2602ea6c 100644 --- a/examples/nrf/src/bin/buffered_uart.rs +++ b/examples/nrf/src/bin/buffered_uart.rs | |||
| @@ -8,7 +8,6 @@ mod example_common; | |||
| 8 | use embassy::executor::Spawner; | 8 | use embassy::executor::Spawner; |
| 9 | use embassy::io::{AsyncBufReadExt, AsyncWriteExt}; | 9 | use embassy::io::{AsyncBufReadExt, AsyncWriteExt}; |
| 10 | use embassy_nrf::buffered_uarte::State; | 10 | use embassy_nrf::buffered_uarte::State; |
| 11 | use embassy_nrf::gpio::NoPin; | ||
| 12 | use embassy_nrf::{buffered_uarte::BufferedUarte, interrupt, uarte, Peripherals}; | 11 | use embassy_nrf::{buffered_uarte::BufferedUarte, interrupt, uarte, Peripherals}; |
| 13 | use example_common::*; | 12 | use example_common::*; |
| 14 | use futures::pin_mut; | 13 | use futures::pin_mut; |
| @@ -24,6 +23,7 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 24 | 23 | ||
| 25 | let irq = interrupt::take!(UARTE0_UART0); | 24 | let irq = interrupt::take!(UARTE0_UART0); |
| 26 | let mut state = State::new(); | 25 | let mut state = State::new(); |
| 26 | // Please note - important to have hardware flow control (https://github.com/embassy-rs/embassy/issues/536) | ||
| 27 | let u = BufferedUarte::new( | 27 | let u = BufferedUarte::new( |
| 28 | &mut state, | 28 | &mut state, |
| 29 | p.UARTE0, | 29 | p.UARTE0, |
| @@ -33,8 +33,8 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 33 | irq, | 33 | irq, |
| 34 | p.P0_08, | 34 | p.P0_08, |
| 35 | p.P0_06, | 35 | p.P0_06, |
| 36 | NoPin, | 36 | p.P0_07, |
| 37 | NoPin, | 37 | p.P0_05, |
| 38 | config, | 38 | config, |
| 39 | &mut rx_buffer, | 39 | &mut rx_buffer, |
| 40 | &mut tx_buffer, | 40 | &mut tx_buffer, |
