aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-10-26 15:37:04 +0000
committerGitHub <[email protected]>2021-10-26 15:37:04 +0000
commita6fe031d34d27ffb4ad9365ec226674347ba277f (patch)
tree94dea9fe0c4a9720dca825e0a6bd64d60d91f7f0 /examples
parent7cb34760c4bd4d98f38437c36769c54c56047a10 (diff)
parent0fc92866b0457362494e5c9ca91587d0d80b0c9e (diff)
Merge #437
437: Initial support for STM32F767ZI. r=Dirbaio a=matoushybl This PR adds support for the STM32F767ZI, it adds examples and RCC setup. It is greatly based on the F4 source code and the f7-hal. This PR is based on the pending PR in stm32-data: https://github.com/embassy-rs/stm32-data/pull/92 I am looking forward to your feedback on improving it and adding support for more peripherals and devices in the F7 family. Co-authored-by: Matous Hybl <[email protected]> Co-authored-by: Dario Nieuwenhuis <[email protected]>
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32f7/.cargo/config.toml18
-rw-r--r--examples/stm32f7/Cargo.toml35
-rw-r--r--examples/stm32f7/build.rs39
-rw-r--r--examples/stm32f7/memory.x12
-rw-r--r--examples/stm32f7/src/bin/blinky.rs29
-rw-r--r--examples/stm32f7/src/bin/button.rs34
-rw-r--r--examples/stm32f7/src/bin/button_exti.rs29
-rw-r--r--examples/stm32f7/src/bin/hello.rs27
-rw-r--r--examples/stm32f7/src/example_common.rs17
9 files changed, 240 insertions, 0 deletions
diff --git a/examples/stm32f7/.cargo/config.toml b/examples/stm32f7/.cargo/config.toml
new file mode 100644
index 000000000..632e81541
--- /dev/null
+++ b/examples/stm32f7/.cargo/config.toml
@@ -0,0 +1,18 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2# replace STM32F429ZITx with your chip as listed in `probe-run --list-chips`
3runner = "probe-run --chip STM32F767ZITx"
4
5rustflags = [
6 # LLD (shipped with the Rust toolchain) is used as the default linker
7 "-C", "link-arg=--nmagic",
8 "-C", "link-arg=-Tlink.x",
9 "-C", "link-arg=-Tdefmt.x",
10
11 # Code-size optimizations.
12 "-Z", "trap-unreachable=no",
13 "-C", "inline-threshold=5",
14 "-C", "no-vectorize-loops",
15]
16
17[build]
18target = "thumbv7em-none-eabihf"
diff --git a/examples/stm32f7/Cargo.toml b/examples/stm32f7/Cargo.toml
new file mode 100644
index 000000000..cda2d7778
--- /dev/null
+++ b/examples/stm32f7/Cargo.toml
@@ -0,0 +1,35 @@
1[package]
2authors = ["Dario Nieuwenhuis <[email protected]>"]
3edition = "2018"
4name = "embassy-stm32f7-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", "stm32f767zi", "unstable-pac", "time-driver-tim2"] }
23embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" }
24
25defmt = "0.2.3"
26defmt-rtt = "0.2.0"
27
28cortex-m = "0.7.3"
29cortex-m-rt = "0.7.0"
30embedded-hal = "0.2.6"
31panic-probe = { version = "0.2.0", features = ["print-defmt"] }
32futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
33rtt-target = { version = "0.3.1", features = ["cortex-m"] }
34heapless = { version = "0.7.5", default-features = false }
35nb = "1.0.0"
diff --git a/examples/stm32f7/build.rs b/examples/stm32f7/build.rs
new file mode 100644
index 000000000..b81f6b6e1
--- /dev/null
+++ b/examples/stm32f7/build.rs
@@ -0,0 +1,39 @@
1//! adapted from https://github.com/stm32-rs/stm32f7xx-hal/blob/master/build.rs
2use std::env;
3use std::fs::File;
4use std::io::{self, prelude::*};
5use std::path::PathBuf;
6
7#[derive(Debug)]
8enum Error {
9 Env(env::VarError),
10 Io(io::Error),
11}
12
13impl From<env::VarError> for Error {
14 fn from(error: env::VarError) -> Self {
15 Self::Env(error)
16 }
17}
18
19impl From<io::Error> for Error {
20 fn from(error: io::Error) -> Self {
21 Self::Io(error)
22 }
23}
24
25fn main() -> Result<(), Error> {
26 println!("cargo:rerun-if-changed=build.rs");
27 println!("cargo:rerun-if-changed=memory.x");
28
29 let out_dir = env::var("OUT_DIR")?;
30 let out_dir = PathBuf::from(out_dir);
31
32 let memory_x = include_bytes!("memory.x").as_ref();
33 File::create(out_dir.join("memory.x"))?.write_all(memory_x)?;
34
35 // Tell Cargo where to find the file.
36 println!("cargo:rustc-link-search={}", out_dir.display());
37
38 Ok(())
39}
diff --git a/examples/stm32f7/memory.x b/examples/stm32f7/memory.x
new file mode 100644
index 000000000..899f7a4b8
--- /dev/null
+++ b/examples/stm32f7/memory.x
@@ -0,0 +1,12 @@
1/* For STM32F765,767,768,769,777,778,779 devices */
2MEMORY
3{
4 /* NOTE K = KiBi = 1024 bytes */
5 FLASH : ORIGIN = 0x08000000, LENGTH = 2M
6 RAM : ORIGIN = 0x20000000, LENGTH = 368K + 16K
7}
8
9/* This is where the call stack will be allocated. */
10/* The stack is of the full descending type. */
11/* NOTE Do NOT modify `_stack_start` unless you know what you are doing */
12_stack_start = ORIGIN(RAM) + LENGTH(RAM);
diff --git a/examples/stm32f7/src/bin/blinky.rs b/examples/stm32f7/src/bin/blinky.rs
new file mode 100644
index 000000000..c4857195f
--- /dev/null
+++ b/examples/stm32f7/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;
7use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::{Level, Output, Speed};
10use embassy_stm32::Peripherals;
11use embedded_hal::digital::v2::OutputPin;
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.PB7, Level::High, Speed::Low);
19
20 loop {
21 info!("high");
22 unwrap!(led.set_high());
23 Timer::after(Duration::from_millis(300)).await;
24
25 info!("low");
26 unwrap!(led.set_low());
27 Timer::after(Duration::from_millis(300)).await;
28 }
29}
diff --git a/examples/stm32f7/src/bin/button.rs b/examples/stm32f7/src/bin/button.rs
new file mode 100644
index 000000000..95dee7c74
--- /dev/null
+++ b/examples/stm32f7/src/bin/button.rs
@@ -0,0 +1,34 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5#[path = "../example_common.rs"]
6mod example_common;
7use cortex_m_rt::entry;
8use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
9use embedded_hal::digital::v2::{InputPin, OutputPin};
10use example_common::*;
11
12#[entry]
13fn main() -> ! {
14 info!("Hello World!");
15
16 let p = embassy_stm32::init(Default::default());
17
18 let button = Input::new(p.PC13, Pull::Down);
19 let mut led1 = Output::new(p.PB0, Level::High, Speed::Low);
20 let _led2 = Output::new(p.PB7, Level::High, Speed::Low);
21 let mut led3 = Output::new(p.PB14, Level::High, Speed::Low);
22
23 loop {
24 if unwrap!(button.is_high()) {
25 info!("high");
26 unwrap!(led1.set_high());
27 unwrap!(led3.set_low());
28 } else {
29 info!("low");
30 unwrap!(led1.set_low());
31 unwrap!(led3.set_high());
32 }
33 }
34}
diff --git a/examples/stm32f7/src/bin/button_exti.rs b/examples/stm32f7/src/bin/button_exti.rs
new file mode 100644
index 000000000..2c4318d64
--- /dev/null
+++ b/examples/stm32f7/src/bin/button_exti.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;
7use embassy::executor::Spawner;
8use embassy_stm32::exti::ExtiInput;
9use embassy_stm32::gpio::{Input, Pull};
10use embassy_stm32::Peripherals;
11use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
12use example_common::*;
13
14#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) {
16 info!("Hello World!");
17
18 let button = Input::new(p.PC13, Pull::Down);
19 let mut button = ExtiInput::new(button, p.EXTI13);
20
21 info!("Press the USER button...");
22
23 loop {
24 button.wait_for_rising_edge().await;
25 info!("Pressed!");
26 button.wait_for_falling_edge().await;
27 info!("Released!");
28 }
29}
diff --git a/examples/stm32f7/src/bin/hello.rs b/examples/stm32f7/src/bin/hello.rs
new file mode 100644
index 000000000..56eb67bf3
--- /dev/null
+++ b/examples/stm32f7/src/bin/hello.rs
@@ -0,0 +1,27 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::info;
6use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer};
8use embassy_stm32::time::Hertz;
9use embassy_stm32::Config;
10use embassy_stm32::Peripherals;
11
12#[path = "../example_common.rs"]
13mod example_common;
14
15fn config() -> Config {
16 let mut config = Config::default();
17 config.rcc.sys_ck = Some(Hertz(84_000_000));
18 config
19}
20
21#[embassy::main(config = "config()")]
22async fn main(_spawner: Spawner, _p: Peripherals) -> ! {
23 loop {
24 info!("Hello World!");
25 Timer::after(Duration::from_secs(1)).await;
26 }
27}
diff --git a/examples/stm32f7/src/example_common.rs b/examples/stm32f7/src/example_common.rs
new file mode 100644
index 000000000..54d633837
--- /dev/null
+++ b/examples/stm32f7/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}