diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-09-28 19:20:23 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-09-28 19:20:23 +0200 |
| commit | b6f84efd90b3c2751e6fe03183229d1a7d456091 (patch) | |
| tree | f63888ee828322334669e3534fa4c7909e529248 /examples | |
| parent | 1650983e463e5f237d68957b0de1537f807cbc63 (diff) | |
| parent | d14e555ee76a842809c7f76f8b111003f70ab064 (diff) | |
Merge pull request #406 from mryndzionek/stm32f1_support
Basic STM32F1 support
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32f1/.cargo/config.toml | 18 | ||||
| -rw-r--r-- | examples/stm32f1/Cargo.toml | 35 | ||||
| -rw-r--r-- | examples/stm32f1/src/bin/blinky.rs | 29 | ||||
| -rw-r--r-- | examples/stm32f1/src/bin/hello.rs | 27 | ||||
| -rw-r--r-- | examples/stm32f1/src/example_common.rs | 17 |
5 files changed, 126 insertions, 0 deletions
diff --git a/examples/stm32f1/.cargo/config.toml b/examples/stm32f1/.cargo/config.toml new file mode 100644 index 000000000..28df61383 --- /dev/null +++ b/examples/stm32f1/.cargo/config.toml | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] | ||
| 2 | # replace STM32F103C8 with your chip as listed in `probe-run --list-chips` | ||
| 3 | runner = "probe-run --chip STM32F103C8" | ||
| 4 | |||
| 5 | rustflags = [ | ||
| 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] | ||
| 18 | target = "thumbv7m-none-eabi" | ||
diff --git a/examples/stm32f1/Cargo.toml b/examples/stm32f1/Cargo.toml new file mode 100644 index 000000000..9b4e831ef --- /dev/null +++ b/examples/stm32f1/Cargo.toml | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | [package] | ||
| 2 | authors = ["Dario Nieuwenhuis <[email protected]>"] | ||
| 3 | edition = "2018" | ||
| 4 | name = "embassy-stm32f1-examples" | ||
| 5 | version = "0.1.0" | ||
| 6 | resolver = "2" | ||
| 7 | |||
| 8 | [features] | ||
| 9 | default = [ | ||
| 10 | "defmt-default", | ||
| 11 | ] | ||
| 12 | defmt-default = [] | ||
| 13 | defmt-trace = [] | ||
| 14 | defmt-debug = [] | ||
| 15 | defmt-info = [] | ||
| 16 | defmt-warn = [] | ||
| 17 | defmt-error = [] | ||
| 18 | |||
| 19 | [dependencies] | ||
| 20 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] } | ||
| 21 | embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } | ||
| 22 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "stm32f103c8", "unstable-pac", "memory-x", "time-driver-tim2"] } | ||
| 23 | embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } | ||
| 24 | |||
| 25 | defmt = "0.2.3" | ||
| 26 | defmt-rtt = "0.2.0" | ||
| 27 | |||
| 28 | cortex-m = "0.7.3" | ||
| 29 | cortex-m-rt = "0.7.0" | ||
| 30 | embedded-hal = "0.2.6" | ||
| 31 | panic-probe = { version = "0.2.0", features = ["print-defmt"] } | ||
| 32 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | ||
| 33 | rtt-target = { version = "0.3.1", features = ["cortex-m"] } | ||
| 34 | heapless = { version = "0.7.5", default-features = false } | ||
| 35 | nb = "1.0.0" | ||
diff --git a/examples/stm32f1/src/bin/blinky.rs b/examples/stm32f1/src/bin/blinky.rs new file mode 100644 index 000000000..1e4f2deec --- /dev/null +++ b/examples/stm32f1/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"] | ||
| 6 | mod example_common; | ||
| 7 | use embassy::executor::Spawner; | ||
| 8 | use embassy::time::{Duration, Timer}; | ||
| 9 | use embassy_stm32::gpio::{Level, Output, Speed}; | ||
| 10 | use embassy_stm32::Peripherals; | ||
| 11 | use embedded_hal::digital::v2::OutputPin; | ||
| 12 | use example_common::*; | ||
| 13 | |||
| 14 | #[embassy::main] | ||
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 16 | info!("Hello World!"); | ||
| 17 | |||
| 18 | let mut led = Output::new(p.PC13, 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/stm32f1/src/bin/hello.rs b/examples/stm32f1/src/bin/hello.rs new file mode 100644 index 000000000..efcb9a244 --- /dev/null +++ b/examples/stm32f1/src/bin/hello.rs | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt::info; | ||
| 6 | use embassy::executor::Spawner; | ||
| 7 | use embassy::time::{Duration, Timer}; | ||
| 8 | use embassy_stm32::time::Hertz; | ||
| 9 | use embassy_stm32::Config; | ||
| 10 | use embassy_stm32::Peripherals; | ||
| 11 | |||
| 12 | #[path = "../example_common.rs"] | ||
| 13 | mod example_common; | ||
| 14 | |||
| 15 | fn config() -> Config { | ||
| 16 | let mut config = Config::default(); | ||
| 17 | config.rcc.sys_ck = Some(Hertz(36_000_000)); | ||
| 18 | config | ||
| 19 | } | ||
| 20 | |||
| 21 | #[embassy::main(config = "config()")] | ||
| 22 | async 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/stm32f1/src/example_common.rs b/examples/stm32f1/src/example_common.rs new file mode 100644 index 000000000..54d633837 --- /dev/null +++ b/examples/stm32f1/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 | } | ||
