aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-stm32/src/usart/mod.rs29
-rw-r--r--embassy-stm32/src/usart/v3.rs4
-rw-r--r--examples/stm32h7/src/bin/usart.rs99
m---------stm32-data0
4 files changed, 128 insertions, 4 deletions
diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs
index 41327d25f..2c011719a 100644
--- a/embassy-stm32/src/usart/mod.rs
+++ b/embassy-stm32/src/usart/mod.rs
@@ -1,7 +1,7 @@
1#![macro_use] 1#![macro_use]
2 2
3#[cfg_attr(usart_v1, path = "v1.rs")] 3//#[cfg_attr(usart_v1, path = "v1.rs")]
4#[cfg_attr(usart_v2, path = "v2.rs")] 4//#[cfg_attr(usart_v2, path = "v2.rs")]
5#[cfg_attr(usart_v3, path = "v3.rs")] 5#[cfg_attr(usart_v3, path = "v3.rs")]
6mod _version; 6mod _version;
7use crate::peripherals; 7use crate::peripherals;
@@ -140,6 +140,9 @@ macro_rules! impl_pin {
140} 140}
141 141
142crate::pac::peripheral_pins!( 142crate::pac::peripheral_pins!(
143
144 // USART
145
143 ($inst:ident, usart, USART, $pin:ident, TX, $af:expr) => { 146 ($inst:ident, usart, USART, $pin:ident, TX, $af:expr) => {
144 impl_pin!($inst, $pin, TxPin, $af); 147 impl_pin!($inst, $pin, TxPin, $af);
145 }; 148 };
@@ -159,4 +162,26 @@ crate::pac::peripheral_pins!(
159 ($inst:ident, usart, USART, $pin:ident, CK, $af:expr) => { 162 ($inst:ident, usart, USART, $pin:ident, CK, $af:expr) => {
160 impl_pin!($inst, $pin, CkPin, $af); 163 impl_pin!($inst, $pin, CkPin, $af);
161 }; 164 };
165
166 // UART
167
168 ($inst:ident, uart, UART, $pin:ident, TX, $af:expr) => {
169 impl_pin!($inst, $pin, TxPin, $af);
170 };
171
172 ($inst:ident, uart, UART, $pin:ident, RX, $af:expr) => {
173 impl_pin!($inst, $pin, RxPin, $af);
174 };
175
176 ($inst:ident, uart, UART, $pin:ident, CTS, $af:expr) => {
177 impl_pin!($inst, $pin, CtsPin, $af);
178 };
179
180 ($inst:ident, uart, UART, $pin:ident, RTS, $af:expr) => {
181 impl_pin!($inst, $pin, RtsPin, $af);
182 };
183
184 ($inst:ident, uart, UART, $pin:ident, CK, $af:expr) => {
185 impl_pin!($inst, $pin, CkPin, $af);
186 };
162); 187);
diff --git a/embassy-stm32/src/usart/v3.rs b/embassy-stm32/src/usart/v3.rs
index c45af0043..1e9051443 100644
--- a/embassy-stm32/src/usart/v3.rs
+++ b/embassy-stm32/src/usart/v3.rs
@@ -22,7 +22,7 @@ impl<'d, T: Instance> Uart<'d, T> {
22 unborrow!(inner, rx, tx); 22 unborrow!(inner, rx, tx);
23 23
24 // Uncomment once we find all of the H7's UART clocks. 24 // Uncomment once we find all of the H7's UART clocks.
25 //T::enable(); 25 T::enable();
26 let pclk_freq = T::frequency(); 26 let pclk_freq = T::frequency();
27 27
28 // TODO: better calculation, including error checking and OVER8 if possible. 28 // TODO: better calculation, including error checking and OVER8 if possible.
@@ -65,7 +65,7 @@ impl<'d, T: Instance> Uart<'d, T> {
65 }); 65 });
66 } 66 }
67 let r = self.inner.regs(); 67 let r = self.inner.regs();
68 let dst = r.dr().ptr() as *mut u8; 68 let dst = r.tdr().ptr() as *mut u8;
69 ch.transfer(buffer, dst).await; 69 ch.transfer(buffer, dst).await;
70 Ok(()) 70 Ok(())
71 } 71 }
diff --git a/examples/stm32h7/src/bin/usart.rs b/examples/stm32h7/src/bin/usart.rs
new file mode 100644
index 000000000..b8524f2c0
--- /dev/null
+++ b/examples/stm32h7/src/bin/usart.rs
@@ -0,0 +1,99 @@
1
2#![no_std]
3#![no_main]
4#![feature(trait_alias)]
5#![feature(min_type_alias_impl_trait)]
6#![feature(impl_trait_in_bindings)]
7#![feature(type_alias_impl_trait)]
8#![allow(incomplete_features)]
9
10#[path = "../example_common.rs"]
11mod example_common;
12use cortex_m::prelude::_embedded_hal_blocking_serial_Write;
13use embassy::executor::Executor;
14use embassy::time::Clock;
15use embassy::util::Forever;
16use embassy_stm32::usart::{Config, Uart};
17use example_common::*;
18
19use stm32h7xx_hal as hal;
20use hal::prelude::*;
21
22use cortex_m_rt::entry;
23use stm32h7::stm32h743 as pac;
24
25#[embassy::task]
26async fn main_task() {
27 let p = embassy_stm32::init(Default::default());
28
29 let config = Config::default();
30 let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, config);
31
32 usart.bwrite_all(b"Hello Embassy World!\r\n").unwrap();
33 info!("wrote Hello, starting echo");
34
35 let mut buf = [0u8; 1];
36 loop {
37 usart.read(&mut buf).unwrap();
38 usart.bwrite_all(&buf).unwrap();
39 }
40}
41
42struct ZeroClock;
43
44impl Clock for ZeroClock {
45 fn now(&self) -> u64 {
46 0
47 }
48}
49
50static EXECUTOR: Forever<Executor> = Forever::new();
51
52#[entry]
53fn main() -> ! {
54 info!("Hello World!");
55
56 let pp = pac::Peripherals::take().unwrap();
57
58 let pwrcfg = pp.PWR.constrain().freeze();
59
60 let rcc = pp.RCC.constrain();
61
62 let ccdr = rcc
63 .sys_ck(96.mhz())
64 .pclk1(48.mhz())
65 .pclk2(48.mhz())
66 .pclk3(48.mhz())
67 .pclk4(48.mhz())
68 .pll1_q_ck(48.mhz())
69 .freeze(pwrcfg, &pp.SYSCFG);
70
71 let pp = unsafe { pac::Peripherals::steal() };
72
73 pp.DBGMCU.cr.modify(|_, w| {
74 w.dbgsleep_d1().set_bit();
75 w.dbgstby_d1().set_bit();
76 w.dbgstop_d1().set_bit();
77 w.d1dbgcken().set_bit();
78 w
79 });
80
81 pp.RCC.ahb4enr.modify(|_, w| {
82 w.gpioaen().set_bit();
83 w.gpioben().set_bit();
84 w.gpiocen().set_bit();
85 w.gpioden().set_bit();
86 w.gpioeen().set_bit();
87 w.gpiofen().set_bit();
88 w
89 });
90
91
92 unsafe { embassy::time::set_clock(&ZeroClock) };
93
94 let executor = EXECUTOR.put(Executor::new());
95
96 executor.run(|spawner| {
97 unwrap!(spawner.spawn(main_task()));
98 })
99} \ No newline at end of file
diff --git a/stm32-data b/stm32-data
Subproject 424f96eae80015536c4df5ed62c1caad85bb531 Subproject 3cc324ef25916ff4d70acfc4e7551109f7d0290