aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob McWhirter <[email protected]>2021-06-08 16:26:46 -0400
committerGitHub <[email protected]>2021-06-08 16:26:46 -0400
commit9d2f95c82f0b312760f4c95e5da035f164789b85 (patch)
tree024c04d0822e15cc21fba897e534f42eef0a2946
parent8f8914a7892bf871175ad473066cd5bbfdc422e9 (diff)
parent62955894673b17aad1edba6e34855d5f3a5e8438 (diff)
Merge pull request #236 from bobmcwhirter/h7-examples
Initial swag at h7 examples.
-rw-r--r--.github/workflows/rust.yml2
-rw-r--r--examples/stm32h7/Cargo.toml39
-rw-r--r--examples/stm32h7/memory.x5
-rw-r--r--examples/stm32h7/src/bin/blinky.rs75
-rw-r--r--examples/stm32h7/src/bin/dac.rs92
-rw-r--r--examples/stm32h7/src/example_common.rs17
m---------stm32-data0
7 files changed, 230 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..d7288e4c7
--- /dev/null
+++ b/examples/stm32h7/Cargo.toml
@@ -0,0 +1,39 @@
1[package]
2authors = ["Dario Nieuwenhuis <[email protected]>"]
3edition = "2018"
4name = "embassy-stm32h7-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
27defmt = "0.2.0"
28defmt-rtt = "0.2.0"
29
30cortex-m = "0.7.1"
31cortex-m-rt = "0.6.14"
32embedded-hal = { version = "0.2.4" }
33panic-probe = { version = "0.2.0", features= ["print-defmt"] }
34futures = { version = "0.3.8", default-features = false, features = ["async-await"] }
35rtt-target = { version = "0.3", features = ["cortex-m"] }
36heapless = { version = "0.7.1", default-features = false }
37
38micromath = "2.0.0"
39
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/bin/dac.rs b/examples/stm32h7/src/bin/dac.rs
new file mode 100644
index 000000000..c6f3de7b6
--- /dev/null
+++ b/examples/stm32h7/src/bin/dac.rs
@@ -0,0 +1,92 @@
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
8#[path = "../example_common.rs"]
9mod example_common;
10
11use embassy_stm32::gpio::{Level, Output, Input, Pull, NoPin};
12use embedded_hal::digital::v2::{OutputPin, InputPin};
13use example_common::*;
14
15use cortex_m_rt::entry;
16use stm32h7::stm32h743 as pac;
17use embassy_stm32::spi::{Spi, MODE_0, ByteOrder, Config};
18use embassy_stm32::time::Hertz;
19use embedded_hal::blocking::spi::Transfer;
20use stm32h7xx_hal::{rcc, prelude::*};
21use embassy_stm32::dac::{Dac, Value, Channel};
22
23#[entry]
24fn main() -> ! {
25 info!("Hello World, dude!");
26
27 let pp = pac::Peripherals::take().unwrap();
28
29 let pwrcfg = pp.PWR.constrain()
30 .freeze();
31
32 let rcc = pp.RCC.constrain();
33
34 let ccdr = rcc
35 .sys_ck(96.mhz())
36 .pclk1(48.mhz())
37 .pclk2(48.mhz())
38 .pclk3(48.mhz())
39 .pclk4(48.mhz())
40 .pll1_q_ck(48.mhz())
41 .freeze(pwrcfg, &pp.SYSCFG);
42
43 let pp = unsafe { pac::Peripherals::steal() };
44
45 pp.DBGMCU.cr.modify(|_, w| {
46 w.dbgsleep_d1().set_bit();
47 w.dbgstby_d1().set_bit();
48 w.dbgstop_d1().set_bit();
49 w.d1dbgcken().set_bit();
50 w
51 });
52
53 pp.RCC.apb1lenr.modify(|_, w|{
54 w.dac12en().set_bit();
55 w
56 });
57
58 pp.RCC.ahb4enr.modify(|_, w| {
59 w.gpioaen().set_bit();
60 w.gpioben().set_bit();
61 w.gpiocen().set_bit();
62 w.gpioden().set_bit();
63 w.gpioeen().set_bit();
64 w.gpiofen().set_bit();
65 w
66 });
67
68 let p = embassy_stm32::init(Default::default());
69
70 let mut dac = Dac::new(p.DAC1, p.PA4, NoPin);
71
72 loop {
73 for v in 0..=255 {
74 dac.set(Channel::Ch1, Value::Bit8(to_sine_wave(v)));
75 dac.trigger( Channel::Ch1 );
76 }
77 }
78}
79
80use micromath::F32Ext;
81
82fn to_sine_wave(v: u8) -> u8 {
83 if v >= 128 {
84 // top half
85 let r = 3.14 * ( (v-128) as f32/ 128.0) ;
86 (r.sin() * 128.0 + 127.0) as u8
87 } else {
88 // bottom half
89 let r = 3.14 + 3.14 * (v as f32/ 128.0);
90 (r.sin() * 128.0 + 127.0) as u8
91 }
92}
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}
diff --git a/stm32-data b/stm32-data
Subproject 4bb1b178cd1c555cfedaea31ad0be3c6a7b9956 Subproject f07c793bbe81b01b2f3668177648f024ec1c8fb