aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2021-08-16 17:16:49 +0200
committerGitHub <[email protected]>2021-08-16 17:16:49 +0200
commitcbff0398bb8d59f881e6649e2b3776d9e00af671 (patch)
tree826f554074a11a9bf818eb3f6c6e66644790aba2 /examples
parentc310f18aaf6b42da232d678c38d6199596675840 (diff)
Add IRQ-driven buffered USART implementation for STM32 v2 usart (#356)
* Add IRQ-driven buffered USART implementation for STM32 v2 usart * Implementation based on nRF UARTE, but simplified to not use DMA to avoid complex interaction between DMA and USART. * Implementation of AsyncBufRead and AsyncWrite traits * Some unit tests to ring buffer * Update polyfill version * Update sub module to get usart IRQ fix
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32l0/Cargo.toml1
-rw-r--r--examples/stm32l0/src/bin/usart_irq.rs51
2 files changed, 52 insertions, 0 deletions
diff --git a/examples/stm32l0/Cargo.toml b/examples/stm32l0/Cargo.toml
index 6c594df66..9b3166154 100644
--- a/examples/stm32l0/Cargo.toml
+++ b/examples/stm32l0/Cargo.toml
@@ -21,6 +21,7 @@ embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "def
21embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } 21embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
22embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "stm32l072cz", "time-driver-tim3"] } 22embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "stm32l072cz", "time-driver-tim3"] }
23embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } 23embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" }
24embassy-macros = { path = "../../embassy-macros" }
24 25
25defmt = "0.2.0" 26defmt = "0.2.0"
26defmt-rtt = "0.2.0" 27defmt-rtt = "0.2.0"
diff --git a/examples/stm32l0/src/bin/usart_irq.rs b/examples/stm32l0/src/bin/usart_irq.rs
new file mode 100644
index 000000000..5c79d0671
--- /dev/null
+++ b/examples/stm32l0/src/bin/usart_irq.rs
@@ -0,0 +1,51 @@
1#![no_std]
2#![no_main]
3#![feature(trait_alias)]
4#![feature(type_alias_impl_trait)]
5#![allow(incomplete_features)]
6
7#[path = "../example_common.rs"]
8mod example_common;
9
10use example_common::*;
11
12use defmt::panic;
13use embassy::executor::Spawner;
14use embassy::io::{AsyncBufReadExt, AsyncWriteExt};
15use embassy_stm32::dma::NoDma;
16use embassy_stm32::interrupt;
17use embassy_stm32::usart::{BufferedUart, Config, State, Uart};
18use embassy_stm32::{rcc, Peripherals};
19
20#[embassy::main]
21async fn main(_spawner: Spawner, mut p: Peripherals) {
22 let mut rcc = rcc::Rcc::new(p.RCC);
23 rcc.enable_debug_wfe(&mut p.DBGMCU, true);
24
25 static mut TX_BUFFER: [u8; 8] = [0; 8];
26 static mut RX_BUFFER: [u8; 256] = [0; 256];
27
28 let mut config = Config::default();
29 config.baudrate = 9600;
30
31 let usart = Uart::new(p.USART1, p.PA10, p.PA9, NoDma, NoDma, config);
32 let mut state = State::new();
33 let mut usart = unsafe {
34 BufferedUart::new(
35 &mut state,
36 usart,
37 interrupt::take!(USART1),
38 &mut TX_BUFFER,
39 &mut RX_BUFFER,
40 )
41 };
42
43 usart.write_all(b"Hello Embassy World!\r\n").await.unwrap();
44 info!("wrote Hello, starting echo");
45
46 let mut buf = [0; 4];
47 loop {
48 usart.read_exact(&mut buf[..]).await.unwrap();
49 usart.write_all(&buf[..]).await.unwrap();
50 }
51}