aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob McWhirter <[email protected]>2021-06-08 14:47:32 -0400
committerBob McWhirter <[email protected]>2021-06-08 15:25:38 -0400
commit4f1f63f336e3b8df2e9d5672f145eac4e4ffef9d (patch)
treea0914876a6c4e3b76340d5f0caa18faffd47bed9
parent8f8914a7892bf871175ad473066cd5bbfdc422e9 (diff)
Initial swag at h7 examples.
-rw-r--r--.github/workflows/rust.yml2
-rw-r--r--examples/stm32h7/Cargo.toml41
-rw-r--r--examples/stm32h7/memory.x5
-rw-r--r--examples/stm32h7/src/bin/blinky.rs75
-rw-r--r--examples/stm32h7/src/example_common.rs17
5 files changed, 140 insertions, 0 deletions
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
index c73c6c7e3..d95c388f3 100644
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -82,6 +82,8 @@ jobs:
82 target: thumbv7em-none-eabi 82 target: thumbv7em-none-eabi
83 - package: examples/stm32l4 83 - package: examples/stm32l4
84 target: thumbv7em-none-eabi 84 target: thumbv7em-none-eabi
85 - package: examples/stm32h7
86 target: thumbv7em-none-eabi
85 87
86 steps: 88 steps:
87 - uses: actions/checkout@v2 89 - uses: actions/checkout@v2
diff --git a/examples/stm32h7/Cargo.toml b/examples/stm32h7/Cargo.toml
new file mode 100644
index 000000000..23874a565
--- /dev/null
+++ b/examples/stm32h7/Cargo.toml
@@ -0,0 +1,41 @@
1[package]
2authors = ["Dario Nieuwenhuis <[email protected]>"]
3edition = "2018"
4name = "embassy-stm32h4-examples"
5version = "0.1.0"
6resolver = "2"
7
8[features]
9default = [
10 "defmt-default",
11]
12defmt-default = []
13defmt-trace = []
14defmt-debug = []
15defmt-info = []
16defmt-warn = []
17defmt-error = []
18
19[dependencies]
20embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] }
21embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
22embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "stm32h743zi"] }
23embassy-extras = {version = "0.1.0", path = "../../embassy-extras" }
24stm32h7 = { version = "0.13", features = ["stm32h743"]}
25stm32h7xx-hal = { version = "0.9.0", features = ["stm32h743"] }
26#stm32l4 = { version = "0.13", features = ["stm32l4x5" ] }
27#stm32l4xx-hal = { version = "0.6.0", features = ["stm32l4x5"] }
28
29defmt = "0.2.0"
30defmt-rtt = "0.2.0"
31
32cortex-m = "0.7.1"
33cortex-m-rt = "0.6.14"
34embedded-hal = { version = "0.2.4" }
35panic-probe = { version = "0.2.0", features= ["print-defmt"] }
36futures = { version = "0.3.8", default-features = false, features = ["async-await"] }
37rtt-target = { version = "0.3", features = ["cortex-m"] }
38heapless = { version = "0.7.1", default-features = false }
39
40#micromath = "2.0.0"
41
diff --git a/examples/stm32h7/memory.x b/examples/stm32h7/memory.x
new file mode 100644
index 000000000..48f58e36b
--- /dev/null
+++ b/examples/stm32h7/memory.x
@@ -0,0 +1,5 @@
1MEMORY
2{
3 FLASH : ORIGIN = 0x08000000, LENGTH = 2048K
4 RAM : ORIGIN = 0x20000000, LENGTH = 128K
5}
diff --git a/examples/stm32h7/src/bin/blinky.rs b/examples/stm32h7/src/bin/blinky.rs
new file mode 100644
index 000000000..c425b7f8e
--- /dev/null
+++ b/examples/stm32h7/src/bin/blinky.rs
@@ -0,0 +1,75 @@
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 embassy_stm32::gpio::{Level, Output};
12use embedded_hal::digital::v2::OutputPin;
13use example_common::*;
14
15use cortex_m_rt::entry;
16use stm32h7::stm32h743 as pac;
17
18use stm32h7xx_hal as hal;
19use hal::prelude::*;
20
21#[entry]
22fn main() -> ! {
23 info!("Hello World!");
24
25 let pp = pac::Peripherals::take().unwrap();
26
27 let pwrcfg = pp.PWR.constrain()
28 .freeze();
29
30 let rcc = pp.RCC.constrain();
31
32 let ccdr = rcc
33 .sys_ck(96.mhz())
34 .pclk1(48.mhz())
35 .pclk2(48.mhz())
36 .pclk3(48.mhz())
37 .pclk4(48.mhz())
38 .pll1_q_ck(48.mhz())
39 .freeze(pwrcfg, &pp.SYSCFG);
40
41 let pp = unsafe { pac::Peripherals::steal() };
42
43 pp.DBGMCU.cr.modify(|_, w| {
44 w.dbgsleep_d1().set_bit();
45 w.dbgstby_d1().set_bit();
46 w.dbgstop_d1().set_bit();
47 w.d1dbgcken().set_bit();
48 w
49 });
50
51 pp.RCC.ahb4enr.modify(|_, w| {
52 w.gpioaen().set_bit();
53 w.gpioben().set_bit();
54 w.gpiocen().set_bit();
55 w.gpioden().set_bit();
56 w.gpioeen().set_bit();
57 w.gpiofen().set_bit();
58 w
59 });
60
61 let p = embassy_stm32::init(Default::default());
62
63 let mut led = Output::new(p.PB14, Level::High);
64
65 loop {
66 info!("high");
67 led.set_high().unwrap();
68 cortex_m::asm::delay(10_000_000);
69
70 info!("low");
71 led.set_low().unwrap();
72 cortex_m::asm::delay(10_000_000);
73 }
74
75}
diff --git a/examples/stm32h7/src/example_common.rs b/examples/stm32h7/src/example_common.rs
new file mode 100644
index 000000000..54d633837
--- /dev/null
+++ b/examples/stm32h7/src/example_common.rs
@@ -0,0 +1,17 @@
1#![macro_use]
2
3use defmt_rtt as _; // global logger
4use panic_probe as _;
5
6pub use defmt::*;
7
8use core::sync::atomic::{AtomicUsize, Ordering};
9
10defmt::timestamp! {"{=u64}", {
11 static COUNT: AtomicUsize = AtomicUsize::new(0);
12 // NOTE(no-CAS) `timestamps` runs with interrupts disabled
13 let n = COUNT.load(Ordering::Relaxed);
14 COUNT.store(n + 1, Ordering::Relaxed);
15 n as u64
16 }
17}