aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32h7/src/bin/usart_dma.rs100
1 files changed, 100 insertions, 0 deletions
diff --git a/examples/stm32h7/src/bin/usart_dma.rs b/examples/stm32h7/src/bin/usart_dma.rs
new file mode 100644
index 000000000..fd5da8b35
--- /dev/null
+++ b/examples/stm32h7/src/bin/usart_dma.rs
@@ -0,0 +1,100 @@
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 embassy::executor::Executor;
13use embassy::time::Clock;
14use embassy::util::Forever;
15use embassy_stm32::dma::NoDma;
16use embassy_stm32::usart::{Config, Uart};
17use example_common::*;
18use embassy_traits::uart::Write as _Write;
19
20use hal::prelude::*;
21use stm32h7xx_hal as hal;
22
23use cortex_m_rt::entry;
24use stm32h7::stm32h743 as pac;
25use heapless::String;
26
27#[embassy::task]
28async fn main_task() {
29 let p = embassy_stm32::init(Default::default());
30
31 let config = Config::default();
32 let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, p.DMA1_0, NoDma, config);
33
34 for n in 0u32.. {
35 let mut s: String<128> = String::new();
36 core::write!(&mut s, "Hello DMA World {}!\r\n", n).unwrap();
37
38 usart.write(s.as_bytes()).await.ok();
39
40 info!("wrote DMA");
41 }
42
43}
44
45struct ZeroClock;
46
47impl Clock for ZeroClock {
48 fn now(&self) -> u64 {
49 0
50 }
51}
52
53static EXECUTOR: Forever<Executor> = Forever::new();
54
55#[entry]
56fn main() -> ! {
57 info!("Hello World!");
58
59 let pp = pac::Peripherals::take().unwrap();
60
61 let pwrcfg = pp.PWR.constrain().freeze();
62
63 let rcc = pp.RCC.constrain();
64
65 rcc.sys_ck(96.mhz())
66 .pclk1(48.mhz())
67 .pclk2(48.mhz())
68 .pclk3(48.mhz())
69 .pclk4(48.mhz())
70 .pll1_q_ck(48.mhz())
71 .freeze(pwrcfg, &pp.SYSCFG);
72
73 let pp = unsafe { pac::Peripherals::steal() };
74
75 pp.DBGMCU.cr.modify(|_, w| {
76 w.dbgsleep_d1().set_bit();
77 w.dbgstby_d1().set_bit();
78 w.dbgstop_d1().set_bit();
79 w.d1dbgcken().set_bit();
80 w
81 });
82
83 pp.RCC.ahb4enr.modify(|_, w| {
84 w.gpioaen().set_bit();
85 w.gpioben().set_bit();
86 w.gpiocen().set_bit();
87 w.gpioden().set_bit();
88 w.gpioeen().set_bit();
89 w.gpiofen().set_bit();
90 w
91 });
92
93 unsafe { embassy::time::set_clock(&ZeroClock) };
94
95 let executor = EXECUTOR.put(Executor::new());
96
97 executor.run(|spawner| {
98 unwrap!(spawner.spawn(main_task()));
99 })
100}