aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-03-27 17:18:30 +0000
committerGitHub <[email protected]>2022-03-27 17:18:30 +0000
commita211003021dee1cf1035557706e2e55d2c3608c9 (patch)
treed841b2c4d87e851fa2951e3b7039b72c305e1244 /examples
parent5c68f0bae7c4091ad34fb2a671e08a614d9beb9a (diff)
parent55a9bf98c56e3a03cdd79e9607fc964e78badf62 (diff)
Merge #678
678: Add minimal F2 family support r=Dirbaio a=Gekkio Here's the bare minimum to support F2 family (207/217/205/215). A lot is missing in RCC (e.g. PLL support), but this is enough to have a working blinky example. The example is set up for a NUCLEO-F207ZG board which I don't have, but I've tested it on my custom board with a F215 and different pinout :sweat_smile: After looking at other RCC implementation, I noticed there's two main API styles: a "low-level" API (e.g. L0) where the `Config` struct has dividers and other low-level "knobs", and a "high-level" API (e.g. F0) where it has desired clock frequencies and the RCC implementation figures out how to achieve them. Which one is preferred? Personally I like the low-level API slightly more, because it gives you the most control and it would be easy to also provide some functions to calculate the required parameters based on desired clock frequencies. F2 has a nasty errata: a delay or DSB instruction must be added after every RCC peripheral clock enable. I've added this workaround to build.rs, but am not sure if this is the best approach. Any comments? I'm planning to add PLL support too once I know which kind of API is preferred. Would you prefer a separate pull request for that, or should I continue working on this one? Co-authored-by: Joonas Javanainen <[email protected]>
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32f2/.cargo/config6
-rw-r--r--examples/stm32f2/Cargo.toml21
-rw-r--r--examples/stm32f2/build.rs5
-rw-r--r--examples/stm32f2/src/bin/blinky.rs29
-rw-r--r--examples/stm32f2/src/example_common.rs19
5 files changed, 80 insertions, 0 deletions
diff --git a/examples/stm32f2/.cargo/config b/examples/stm32f2/.cargo/config
new file mode 100644
index 000000000..30b6d1909
--- /dev/null
+++ b/examples/stm32f2/.cargo/config
@@ -0,0 +1,6 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace STM32F207ZGTx with your chip as listed in `probe-run --list-chips`
3runner = "probe-run --chip STM32F207ZGTx"
4
5[build]
6target = "thumbv7m-none-eabi"
diff --git a/examples/stm32f2/Cargo.toml b/examples/stm32f2/Cargo.toml
new file mode 100644
index 000000000..ee1d7ce2b
--- /dev/null
+++ b/examples/stm32f2/Cargo.toml
@@ -0,0 +1,21 @@
1[package]
2authors = ["Dario Nieuwenhuis <[email protected]>"]
3edition = "2018"
4name = "embassy-stm32f2-examples"
5version = "0.1.0"
6resolver = "2"
7
8[dependencies]
9embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
10embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "defmt", "stm32f207zg", "unstable-pac", "memory-x", "time-driver-any", "exti"] }
11
12defmt = "0.3"
13defmt-rtt = "0.3"
14
15cortex-m = "0.7.3"
16cortex-m-rt = "0.7.0"
17embedded-hal = "0.2.6"
18panic-probe = { version = "0.3", features = ["print-defmt"] }
19futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
20heapless = { version = "0.7.5", default-features = false }
21nb = "1.0.0"
diff --git a/examples/stm32f2/build.rs b/examples/stm32f2/build.rs
new file mode 100644
index 000000000..8cd32d7ed
--- /dev/null
+++ b/examples/stm32f2/build.rs
@@ -0,0 +1,5 @@
1fn main() {
2 println!("cargo:rustc-link-arg-bins=--nmagic");
3 println!("cargo:rustc-link-arg-bins=-Tlink.x");
4 println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
5}
diff --git a/examples/stm32f2/src/bin/blinky.rs b/examples/stm32f2/src/bin/blinky.rs
new file mode 100644
index 000000000..637c2f4fd
--- /dev/null
+++ b/examples/stm32f2/src/bin/blinky.rs
@@ -0,0 +1,29 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5#[path = "../example_common.rs"]
6mod example_common;
7
8use embassy::executor::Spawner;
9use embassy::time::{Duration, Timer};
10use embassy_stm32::gpio::{Level, Output, Speed};
11use embassy_stm32::Peripherals;
12use example_common::*;
13
14#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) {
16 info!("Hello World!");
17
18 let mut led = Output::new(p.PB14, Level::High, Speed::Low);
19
20 loop {
21 info!("high");
22 led.set_high();
23 Timer::after(Duration::from_millis(1000)).await;
24
25 info!("low");
26 led.set_low();
27 Timer::after(Duration::from_millis(1000)).await;
28 }
29}
diff --git a/examples/stm32f2/src/example_common.rs b/examples/stm32f2/src/example_common.rs
new file mode 100644
index 000000000..e14517033
--- /dev/null
+++ b/examples/stm32f2/src/example_common.rs
@@ -0,0 +1,19 @@
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! {
11 "{=u64}",
12 {
13 static COUNT: AtomicUsize = AtomicUsize::new(0);
14 // NOTE(no-CAS) `timestamps` runs with interrupts disabled
15 let n = COUNT.load(Ordering::Relaxed);
16 COUNT.store(n + 1, Ordering::Relaxed);
17 n as u64
18 }
19}