aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32l4/src/bin/usart_dma.rs96
1 files changed, 96 insertions, 0 deletions
diff --git a/examples/stm32l4/src/bin/usart_dma.rs b/examples/stm32l4/src/bin/usart_dma.rs
new file mode 100644
index 000000000..cc630e0df
--- /dev/null
+++ b/examples/stm32l4/src/bin/usart_dma.rs
@@ -0,0 +1,96 @@
1#![no_std]
2#![no_main]
3#![feature(trait_alias)]
4#![feature(min_type_alias_impl_trait)]
5#![feature(impl_trait_in_bindings)]
6#![feature(type_alias_impl_trait)]
7#![allow(incomplete_features)]
8
9#[path = "../example_common.rs"]
10mod example_common;
11use core::fmt::Write;
12use cortex_m_rt::entry;
13use embassy::executor::Executor;
14use embassy::time::Clock;
15use embassy::util::Forever;
16use embassy_stm32::usart::{Config, Uart};
17use example_common::*;
18use heapless::String;
19use stm32l4::stm32l4x5 as pac;
20
21#[embassy::task]
22async fn main_task() {
23 let mut p = embassy_stm32::init(Default::default());
24
25 let config = Config::default();
26 let mut usart = Uart::new(p.UART4, p.PA1, p.PA0, config);
27
28 for n in 0u32.. {
29 let mut s: String<128> = String::new();
30 core::write!(&mut s, "Hello DMA World {}!\r\n", n).unwrap();
31
32 usart
33 .write_dma(&mut p.DMA1_3, s.as_bytes())
34 .await
35 .unwrap();
36 info!("wrote DMA");
37 }
38}
39
40struct ZeroClock;
41
42impl Clock for ZeroClock {
43 fn now(&self) -> u64 {
44 0
45 }
46}
47
48static EXECUTOR: Forever<Executor> = Forever::new();
49
50#[entry]
51fn main() -> ! {
52 info!("Hello World!");
53
54 let pp = pac::Peripherals::take().unwrap();
55
56 pp.DBGMCU.cr.modify(|_, w| {
57 w.dbg_sleep().set_bit();
58 w.dbg_standby().set_bit();
59 w.dbg_stop().set_bit()
60 });
61
62 pp.RCC.ahb1enr.modify(|_, w| {
63 unsafe {
64 w.bits( 0x07 );
65 }
66 w
67 //w.dmamuxen().set_bit();
68 //w.dma1en().set_bit();
69 //w.dma2en().set_bit();
70 //w
71 });
72
73 pp.RCC.ahb2enr.modify(|_, w| {
74 w.gpioaen().set_bit();
75 w.gpioben().set_bit();
76 w.gpiocen().set_bit();
77 w.gpioden().set_bit();
78 w.gpioeen().set_bit();
79 w.gpiofen().set_bit();
80 w
81 });
82
83 pp.RCC.apb2enr.modify(|_, w| {
84 w.syscfgen().set_bit();
85 w
86 });
87
88
89 unsafe { embassy::time::set_clock(&ZeroClock) };
90
91 let executor = EXECUTOR.put(Executor::new());
92
93 executor.run(|spawner| {
94 unwrap!(spawner.spawn(main_task()));
95 })
96}