aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32f4-examples
diff options
context:
space:
mode:
authorxoviat <[email protected]>2021-01-04 12:52:00 -0600
committerxoviat <[email protected]>2021-01-04 12:52:00 -0600
commitf3676e1eabc4f3079003d8a006d45db7d3afc742 (patch)
treea148703627ee398e49fa37b8bc160e5b8fe9a794 /embassy-stm32f4-examples
parentbe541b94aaac92049a9283a44e715322a7653fcf (diff)
rename examples
Diffstat (limited to 'embassy-stm32f4-examples')
-rw-r--r--embassy-stm32f4-examples/Cargo.toml39
-rw-r--r--embassy-stm32f4-examples/src/serial.rs64
2 files changed, 103 insertions, 0 deletions
diff --git a/embassy-stm32f4-examples/Cargo.toml b/embassy-stm32f4-examples/Cargo.toml
new file mode 100644
index 000000000..6502a77a5
--- /dev/null
+++ b/embassy-stm32f4-examples/Cargo.toml
@@ -0,0 +1,39 @@
1[package]
2authors = ["Dario Nieuwenhuis <[email protected]>"]
3edition = "2018"
4name = "embassy-stm32f4-examples"
5version = "0.1.0"
6
7[features]
8default = [
9 "defmt-default",
10]
11defmt-default = []
12defmt-trace = []
13defmt-debug = []
14defmt-info = []
15defmt-warn = []
16defmt-error = []
17
18
19[dependencies]
20embassy = { version = "0.1.0", path = "../embassy", features = ["defmt", "defmt-trace"] }
21embassy-stm32f4 = { version = "*", path = "../embassy-stm32f4", features = ["stm32f405"] }
22
23defmt = "0.1.3"
24defmt-rtt = "0.1.0"
25
26cortex-m = { version = "0.6.3" }
27cortex-m-rt = "0.6.13"
28embedded-hal = { version = "0.2.4" }
29panic-probe = "0.1.0"
30stm32f4xx-hal = { version = "0.8.3", features = ["rt", "stm32f405"], git = "https://github.com/stm32-rs/stm32f4xx-hal.git"}
31futures = { version = "0.3.8", default-features = false, features = ["async-await"] }
32cortex-m-rtic = "0.5"
33rtt-target = { version = "0.3", features = ["cortex-m"] }
34
35
36
37[[bin]]
38name = "serial"
39path = "src/serial.rs" \ No newline at end of file
diff --git a/embassy-stm32f4-examples/src/serial.rs b/embassy-stm32f4-examples/src/serial.rs
new file mode 100644
index 000000000..6c757dd2f
--- /dev/null
+++ b/embassy-stm32f4-examples/src/serial.rs
@@ -0,0 +1,64 @@
1#![no_std]
2#![no_main]
3#![feature(trait_alias)]
4#![feature(type_alias_impl_trait)]
5
6// extern crate panic_halt;
7
8use cortex_m::singleton;
9use cortex_m_rt::entry;
10use embassy::executor::{task, Executor};
11use embassy::util::Forever;
12use embassy_stm32f4::interrupt;
13use embassy_stm32f4::serial;
14use stm32f4xx_hal::stm32;
15use stm32f4xx_hal::{prelude::*, serial::config};
16
17#[task]
18async fn run(dp: stm32::Peripherals, cp: cortex_m::Peripherals) {
19 // https://gist.github.com/thalesfragoso/a07340c5df6eee3b04c42fdc69ecdcb1
20 let gpioa = dp.GPIOA.split();
21 let rcc = dp.RCC.constrain();
22
23 let clocks = rcc
24 .cfgr
25 .use_hse(16.mhz())
26 .sysclk(48.mhz())
27 .pclk1(24.mhz())
28 .freeze();
29
30 let mut serial = serial::Serial::new(
31 gpioa.pa9.into_alternate_af7(),
32 gpioa.pa10.into_alternate_af7(),
33 interrupt::take!(DMA2_STREAM2),
34 interrupt::take!(DMA2_STREAM7),
35 interrupt::take!(USART1),
36 dp.DMA2,
37 dp.USART1,
38 config::Parity::ParityNone,
39 9600.bps(),
40 clocks,
41 );
42
43 let buf = singleton!(: [u8; 30] = [0; 30]).unwrap();
44
45 buf[5] = 0x01;
46
47 serial.send(buf).await;
48}
49
50static EXECUTOR: Forever<Executor> = Forever::new();
51
52#[entry]
53fn main() -> ! {
54 let dp = stm32::Peripherals::take().unwrap();
55 let cp = cortex_m::peripheral::Peripherals::take().unwrap();
56
57 let executor = EXECUTOR.put(Executor::new(cortex_m::asm::sev));
58 executor.spawn(run(dp, cp));
59
60 loop {
61 executor.run();
62 cortex_m::asm::wfe();
63 }
64}