diff options
| -rw-r--r-- | .github/workflows/rust.yml | 2 | ||||
| -rw-r--r-- | examples/stm32f0/.cargo/config.toml | 10 | ||||
| -rw-r--r-- | examples/stm32f0/Cargo.toml | 29 | ||||
| -rw-r--r-- | examples/stm32f0/build.rs | 31 | ||||
| -rw-r--r-- | examples/stm32f0/memory.x | 6 | ||||
| -rw-r--r-- | examples/stm32f0/src/bin/hello.rs | 23 | ||||
| -rw-r--r-- | examples/stm32f0/src/example_common.rs | 17 |
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] | ||
| 2 | runner = 'probe-run --chip STM32F030F4Px' | ||
| 3 | rustflags = [ | ||
| 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] | ||
| 10 | target = "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] | ||
| 2 | name = "embassy-stm32f0-examples" | ||
| 3 | version = "0.1.0" | ||
| 4 | authors = ["Thales Fragoso <[email protected]>"] | ||
| 5 | edition = "2018" | ||
| 6 | resolver = "2" | ||
| 7 | |||
| 8 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
| 9 | |||
| 10 | [dependencies] | ||
| 11 | cortex-m = { version = "0.7.1", features = ["inline-asm"] } | ||
| 12 | cortex-m-rt = "0.6.13" | ||
| 13 | defmt = "0.2.0" | ||
| 14 | defmt-rtt = "0.2.0" | ||
| 15 | panic-probe = { version = "0.2.0" } | ||
| 16 | rtt-target = { version = "0.3", features = ["cortex-m"] } | ||
| 17 | embassy = { path = "../../embassy", features = ["defmt"] } | ||
| 18 | embassy-stm32 = { path = "../../embassy-stm32", features = ["defmt", "stm32f030f4"] } | ||
| 19 | |||
| 20 | [features] | ||
| 21 | default = [ | ||
| 22 | "defmt-default", | ||
| 23 | ] | ||
| 24 | defmt-default = [] | ||
| 25 | defmt-trace = [] | ||
| 26 | defmt-debug = [] | ||
| 27 | defmt-info = [] | ||
| 28 | defmt-warn = [] | ||
| 29 | defmt-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 | |||
| 11 | use std::env; | ||
| 12 | use std::fs::File; | ||
| 13 | use std::io::Write; | ||
| 14 | use std::path::PathBuf; | ||
| 15 | |||
| 16 | fn 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 @@ | |||
| 1 | MEMORY | ||
| 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 | |||
| 8 | use defmt::info; | ||
| 9 | |||
| 10 | use embassy::executor::Spawner; | ||
| 11 | use embassy::time::{Duration, Timer}; | ||
| 12 | use embassy_stm32::Peripherals; | ||
| 13 | |||
| 14 | #[path = "../example_common.rs"] | ||
| 15 | mod example_common; | ||
| 16 | |||
| 17 | #[embassy::main] | ||
| 18 | async 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 | |||
| 3 | use defmt_rtt as _; // global logger | ||
| 4 | use panic_probe as _; | ||
| 5 | |||
| 6 | pub use defmt::*; | ||
| 7 | |||
| 8 | use core::sync::atomic::{AtomicUsize, Ordering}; | ||
| 9 | |||
| 10 | defmt::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 | } | ||
