aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/rust.yml2
-rw-r--r--examples/stm32f0/.cargo/config.toml10
-rw-r--r--examples/stm32f0/Cargo.toml29
-rw-r--r--examples/stm32f0/build.rs31
-rw-r--r--examples/stm32f0/memory.x6
-rw-r--r--examples/stm32f0/src/bin/hello.rs23
-rw-r--r--examples/stm32f0/src/example_common.rs17
7 files changed, 118 insertions, 0 deletions
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
index 2035c96dc..118143daa 100644
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -88,6 +88,8 @@ jobs:
88 target: thumbv6m-none-eabi 88 target: thumbv6m-none-eabi
89 - package: examples/stm32wb55 89 - package: examples/stm32wb55
90 target: thumbv7em-none-eabihf 90 target: thumbv7em-none-eabihf
91 - package: examples/stm32f0
92 target: thumbv6m-none-eabi
91 93
92 steps: 94 steps:
93 - uses: actions/checkout@v2 95 - uses: actions/checkout@v2
diff --git a/examples/stm32f0/.cargo/config.toml b/examples/stm32f0/.cargo/config.toml
new file mode 100644
index 000000000..7506fa91b
--- /dev/null
+++ b/examples/stm32f0/.cargo/config.toml
@@ -0,0 +1,10 @@
1[target.thumbv6m-none-eabi]
2runner = 'probe-run --chip STM32F030F4Px'
3rustflags = [
4 # LLD (shipped with the Rust toolchain) is used as the default linker
5 "-C", "link-arg=-Tlink.x",
6 "-C", "link-arg=-Tdefmt.x",
7]
8
9[build]
10target = "thumbv6m-none-eabi"
diff --git a/examples/stm32f0/Cargo.toml b/examples/stm32f0/Cargo.toml
new file mode 100644
index 000000000..cc2c3f2b7
--- /dev/null
+++ b/examples/stm32f0/Cargo.toml
@@ -0,0 +1,29 @@
1[package]
2name = "embassy-stm32f0-examples"
3version = "0.1.0"
4authors = ["Thales Fragoso <[email protected]>"]
5edition = "2018"
6resolver = "2"
7
8# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
9
10[dependencies]
11cortex-m = { version = "0.7.1", features = ["inline-asm"] }
12cortex-m-rt = "0.6.13"
13defmt = "0.2.0"
14defmt-rtt = "0.2.0"
15panic-probe = { version = "0.2.0" }
16rtt-target = { version = "0.3", features = ["cortex-m"] }
17embassy = { path = "../../embassy", features = ["defmt"] }
18embassy-stm32 = { path = "../../embassy-stm32", features = ["defmt", "stm32f030f4"] }
19
20[features]
21default = [
22 "defmt-default",
23]
24defmt-default = []
25defmt-trace = []
26defmt-debug = []
27defmt-info = []
28defmt-warn = []
29defmt-error = []
diff --git a/examples/stm32f0/build.rs b/examples/stm32f0/build.rs
new file mode 100644
index 000000000..d534cc3df
--- /dev/null
+++ b/examples/stm32f0/build.rs
@@ -0,0 +1,31 @@
1//! This build script copies the `memory.x` file from the crate root into
2//! a directory where the linker can always find it at build time.
3//! For many projects this is optional, as the linker always searches the
4//! project root directory -- wherever `Cargo.toml` is. However, if you
5//! are using a workspace or have a more complicated build setup, this
6//! build script becomes required. Additionally, by requesting that
7//! Cargo re-run the build script whenever `memory.x` is changed,
8//! updating `memory.x` ensures a rebuild of the application with the
9//! new memory settings.
10
11use std::env;
12use std::fs::File;
13use std::io::Write;
14use std::path::PathBuf;
15
16fn main() {
17 // Put `memory.x` in our output directory and ensure it's
18 // on the linker search path.
19 let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
20 File::create(out.join("memory.x"))
21 .unwrap()
22 .write_all(include_bytes!("memory.x"))
23 .unwrap();
24 println!("cargo:rustc-link-search={}", out.display());
25
26 // By default, Cargo will re-run a build script whenever
27 // any file in the project changes. By specifying `memory.x`
28 // here, we ensure the build script is only re-run when
29 // `memory.x` is changed.
30 println!("cargo:rerun-if-changed=memory.x");
31}
diff --git a/examples/stm32f0/memory.x b/examples/stm32f0/memory.x
new file mode 100644
index 000000000..3bddaed41
--- /dev/null
+++ b/examples/stm32f0/memory.x
@@ -0,0 +1,6 @@
1MEMORY
2{
3 FLASH : ORIGIN = 0x08000000, LENGTH = 16K
4 /* DTCM */
5 RAM : ORIGIN = 0x20000000, LENGTH = 4K
6}
diff --git a/examples/stm32f0/src/bin/hello.rs b/examples/stm32f0/src/bin/hello.rs
new file mode 100644
index 000000000..a78b9892f
--- /dev/null
+++ b/examples/stm32f0/src/bin/hello.rs
@@ -0,0 +1,23 @@
1#![no_std]
2#![no_main]
3#![feature(min_type_alias_impl_trait)]
4#![feature(impl_trait_in_bindings)]
5#![feature(type_alias_impl_trait)]
6#![allow(incomplete_features)]
7
8use defmt::info;
9
10use embassy::executor::Spawner;
11use embassy::time::{Duration, Timer};
12use embassy_stm32::Peripherals;
13
14#[path = "../example_common.rs"]
15mod example_common;
16
17#[embassy::main]
18async fn main(_spawner: Spawner, _p: Peripherals) -> ! {
19 loop {
20 Timer::after(Duration::from_secs(1)).await;
21 info!("Hello");
22 }
23}
diff --git a/examples/stm32f0/src/example_common.rs b/examples/stm32f0/src/example_common.rs
new file mode 100644
index 000000000..54d633837
--- /dev/null
+++ b/examples/stm32f0/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}