diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-11-27 01:44:23 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-11-27 01:44:23 +0000 |
| commit | 793f4b1f7d6d1452d665fc7ec70bddd3ac7a69b9 (patch) | |
| tree | a74fe2a9024167880d4ee4c7ac4f748ce5415f76 /examples | |
| parent | c7d97290284d2637c1eb89f65ff18f913342a71b (diff) | |
| parent | 88d4b0c00d5164f2fe6307bacce74887b3f8d4da (diff) | |
Merge #505
505: stm32: add stm32g4 support. r=Dirbaio a=Dirbaio
Co-authored-by: Dario Nieuwenhuis <[email protected]>
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32g0/Cargo.toml | 2 | ||||
| -rw-r--r-- | examples/stm32g4/.cargo/config.toml | 6 | ||||
| -rw-r--r-- | examples/stm32g4/Cargo.toml | 22 | ||||
| -rw-r--r-- | examples/stm32g4/build.rs | 5 | ||||
| -rw-r--r-- | examples/stm32g4/src/bin/blinky.rs | 29 | ||||
| -rw-r--r-- | examples/stm32g4/src/bin/button.rs | 27 | ||||
| -rw-r--r-- | examples/stm32g4/src/bin/button_exti.rs | 29 | ||||
| -rw-r--r-- | examples/stm32g4/src/example_common.rs | 17 |
8 files changed, 136 insertions, 1 deletions
diff --git a/examples/stm32g0/Cargo.toml b/examples/stm32g0/Cargo.toml index 203cdad99..731116c32 100644 --- a/examples/stm32g0/Cargo.toml +++ b/examples/stm32g0/Cargo.toml | |||
| @@ -8,7 +8,7 @@ resolver = "2" | |||
| 8 | [dependencies] | 8 | [dependencies] |
| 9 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } | 9 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } |
| 10 | embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } | 10 | embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } |
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "time-driver-tim2", "stm32g071rb", "unstable-pac"] } | 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "time-driver-tim2", "stm32g071rb", "memory-x", "unstable-pac"] } |
| 12 | embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } | 12 | embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } |
| 13 | 13 | ||
| 14 | defmt = "0.3" | 14 | defmt = "0.3" |
diff --git a/examples/stm32g4/.cargo/config.toml b/examples/stm32g4/.cargo/config.toml new file mode 100644 index 000000000..62003c2a4 --- /dev/null +++ b/examples/stm32g4/.cargo/config.toml | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] | ||
| 2 | # replace STM32G071C8Rx with your chip as listed in `probe-run --list-chips` | ||
| 3 | runner = "probe-run --chip STM32G484VETx" | ||
| 4 | |||
| 5 | [build] | ||
| 6 | target = "thumbv7em-none-eabi" | ||
diff --git a/examples/stm32g4/Cargo.toml b/examples/stm32g4/Cargo.toml new file mode 100644 index 000000000..0f9d77f5e --- /dev/null +++ b/examples/stm32g4/Cargo.toml | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | [package] | ||
| 2 | authors = ["Dario Nieuwenhuis <[email protected]>", "Ben Gamari <[email protected]>"] | ||
| 3 | edition = "2018" | ||
| 4 | name = "embassy-stm32g4-examples" | ||
| 5 | version = "0.1.0" | ||
| 6 | resolver = "2" | ||
| 7 | |||
| 8 | [dependencies] | ||
| 9 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } | ||
| 10 | embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } | ||
| 11 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "time-driver-tim2", "stm32g491re", "memory-x", "unstable-pac"] } | ||
| 12 | embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } | ||
| 13 | |||
| 14 | defmt = "0.3" | ||
| 15 | defmt-rtt = "0.3" | ||
| 16 | |||
| 17 | cortex-m = "0.7.3" | ||
| 18 | cortex-m-rt = "0.7.0" | ||
| 19 | embedded-hal = "0.2.6" | ||
| 20 | panic-probe = { version = "0.3", features = ["print-defmt"] } | ||
| 21 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | ||
| 22 | heapless = { version = "0.7.5", default-features = false } | ||
diff --git a/examples/stm32g4/build.rs b/examples/stm32g4/build.rs new file mode 100644 index 000000000..8cd32d7ed --- /dev/null +++ b/examples/stm32g4/build.rs | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | fn 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/stm32g4/src/bin/blinky.rs b/examples/stm32g4/src/bin/blinky.rs new file mode 100644 index 000000000..a43922a63 --- /dev/null +++ b/examples/stm32g4/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.PA5, 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/stm32g4/src/bin/button.rs b/examples/stm32g4/src/bin/button.rs new file mode 100644 index 000000000..f0a4c8745 --- /dev/null +++ b/examples/stm32g4/src/bin/button.rs | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | #[path = "../example_common.rs"] | ||
| 6 | mod example_common; | ||
| 7 | use cortex_m_rt::entry; | ||
| 8 | use embassy_stm32::gpio::{Input, Pull}; | ||
| 9 | use embedded_hal::digital::v2::InputPin; | ||
| 10 | use example_common::*; | ||
| 11 | |||
| 12 | #[entry] | ||
| 13 | fn 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 | |||
| 20 | loop { | ||
| 21 | if unwrap!(button.is_high()) { | ||
| 22 | info!("high"); | ||
| 23 | } else { | ||
| 24 | info!("low"); | ||
| 25 | } | ||
| 26 | } | ||
| 27 | } | ||
diff --git a/examples/stm32g4/src/bin/button_exti.rs b/examples/stm32g4/src/bin/button_exti.rs new file mode 100644 index 000000000..2c4318d64 --- /dev/null +++ b/examples/stm32g4/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"] | ||
| 6 | mod example_common; | ||
| 7 | use embassy::executor::Spawner; | ||
| 8 | use embassy_stm32::exti::ExtiInput; | ||
| 9 | use embassy_stm32::gpio::{Input, Pull}; | ||
| 10 | use embassy_stm32::Peripherals; | ||
| 11 | use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge}; | ||
| 12 | use example_common::*; | ||
| 13 | |||
| 14 | #[embassy::main] | ||
| 15 | async 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/stm32g4/src/example_common.rs b/examples/stm32g4/src/example_common.rs new file mode 100644 index 000000000..54d633837 --- /dev/null +++ b/examples/stm32g4/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 | } | ||
