aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-11-01 08:48:54 +0000
committerGitHub <[email protected]>2022-11-01 08:48:54 +0000
commit05968bf0f37bcb05b2ba065ef55eebd9755c6f88 (patch)
tree307c79b65002272f34be471a8cae1b971a559ab2
parentea702b37190d1c6ef4296a8de37259077502406f (diff)
parentfc086fd4ba5679cae1bacb0556e503afd6e8894a (diff)
Merge #1037
1037: Add uart async task example r=miathedev a=miathedev Dear Embassy Team, here i propose an additional async uart pass-through example for the STM32WL. Because im quite new to Rust, is there something like **interfaces**? The code: ``` mut usart1: Uart< 'static, embassy_stm32::peripherals::USART1, embassy_stm32::peripherals::DMA1_CH3, embassy_stm32::peripherals::DMA1_CH4, >, mut usart2: Uart< 'static, embassy_stm32::peripherals::LPUART1, embassy_stm32::peripherals::DMA1_CH5, embassy_stm32::peripherals::DMA1_CH6, >, ``` is quite ugly in my opinion. I would like to allow any Type of DMA and USART/UART as argument. Is this possible somehow? Im open to any feedback. With love, Mia Co-authored-by: miathedev <[email protected]>
-rw-r--r--examples/stm32wl/src/bin/uart_async.rs60
1 files changed, 60 insertions, 0 deletions
diff --git a/examples/stm32wl/src/bin/uart_async.rs b/examples/stm32wl/src/bin/uart_async.rs
new file mode 100644
index 000000000..f12fec4c8
--- /dev/null
+++ b/examples/stm32wl/src/bin/uart_async.rs
@@ -0,0 +1,60 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::*;
6use embassy_executor::Spawner;
7use embassy_stm32::interrupt;
8use embassy_stm32::usart::{Config, Uart};
9use {defmt_rtt as _, panic_probe as _};
10
11/*
12Pass Incoming data from LPUART1 to USART1
13Example is written for the LoRa-E5 mini v1.0,
14but can be surely changed for your needs.
15*/
16#[embassy_executor::main]
17async fn main(_spawner: Spawner) {
18 let mut config = embassy_stm32::Config::default();
19 config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSE32;
20 let p = embassy_stm32::init(config);
21
22 defmt::info!("Starting system");
23
24 let mut config1 = Config::default();
25 config1.baudrate = 9600;
26
27 let mut config2 = Config::default();
28 config2.baudrate = 9600;
29
30 //RX/TX connected to USB/UART Bridge on LoRa-E5 mini v1.0
31 let irq = interrupt::take!(USART1);
32 let mut usart1 = Uart::new(p.USART1, p.PB7, p.PB6, irq, p.DMA1_CH3, p.DMA1_CH4, config1);
33
34 //RX1/TX1 (LPUART) on LoRa-E5 mini v1.0
35 let irq = interrupt::take!(LPUART1);
36 let mut usart2 = Uart::new(p.LPUART1, p.PC0, p.PC1, irq, p.DMA1_CH5, p.DMA1_CH6, config2);
37
38 unwrap!(usart1.write(b"Hello Embassy World!\r\n").await);
39 unwrap!(usart2.write(b"Hello Embassy World!\r\n").await);
40
41 let mut buf = [0u8; 300];
42 loop {
43 let result = usart2.read_until_idle(&mut buf).await;
44 match result {
45 Ok(size) => {
46 match usart1.write(&buf[0..size]).await {
47 Ok(()) => {
48 //Write suc.
49 }
50 Err(..) => {
51 //Wasnt able to write
52 }
53 }
54 }
55 Err(_err) => {
56 //Ignore eg. framing errors
57 }
58 }
59 }
60}