aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-12-12 20:35:43 +0000
committerGitHub <[email protected]>2021-12-12 20:35:43 +0000
commit052abc918a987acb35d44dcd91d9db8a8aaf8ece (patch)
tree5885d77d86041469135aee417f819c9f978457b7
parent8e25ecb68eff5604b3af5c0c8f734e631e8e2950 (diff)
parentdc3469b297be766382550c5ff031751c6dc2d47d (diff)
Merge #537
537: Documents the nRF BufferedUarte problem r=Dirbaio a=huntc Please see https://github.com/embassy-rs/embassy/issues/536 for the rationale. Co-authored-by: huntc <[email protected]>
-rw-r--r--embassy-nrf/src/buffered_uarte.rs13
-rw-r--r--embassy-nrf/src/uarte.rs6
-rw-r--r--examples/nrf/src/bin/buffered_uart.rs6
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
5use core::cmp::min; 16use core::cmp::min;
6use core::marker::PhantomData; 17use 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;
8use embassy::executor::Spawner; 8use embassy::executor::Spawner;
9use embassy::io::{AsyncBufReadExt, AsyncWriteExt}; 9use embassy::io::{AsyncBufReadExt, AsyncWriteExt};
10use embassy_nrf::buffered_uarte::State; 10use embassy_nrf::buffered_uarte::State;
11use embassy_nrf::gpio::NoPin;
12use embassy_nrf::{buffered_uarte::BufferedUarte, interrupt, uarte, Peripherals}; 11use embassy_nrf::{buffered_uarte::BufferedUarte, interrupt, uarte, Peripherals};
13use example_common::*; 12use example_common::*;
14use futures::pin_mut; 13use 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,