diff options
| author | Ulf Lilleengen <[email protected]> | 2021-09-21 13:42:27 +0200 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2021-09-21 14:50:23 +0200 |
| commit | c79485c286d96ca7b1d0bdeb7360488b838a841e (patch) | |
| tree | 58415adb5d9dbdb1a31ab8f9b4b6cc3cb727c986 /examples | |
| parent | 14aa4265db25adb75fdcaf66798a878ae789bf9c (diff) | |
Support for STM32L1
* Add RCC
* Fix more issues with dash in chip names
* Update stm32-data version
* Add blinky and spi example
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32l1/.cargo/config.toml | 18 | ||||
| -rw-r--r-- | examples/stm32l1/Cargo.toml | 35 | ||||
| -rw-r--r-- | examples/stm32l1/build.rs | 31 | ||||
| -rw-r--r-- | examples/stm32l1/memory.x | 5 | ||||
| -rw-r--r-- | examples/stm32l1/src/bin/blinky.rs | 30 | ||||
| -rw-r--r-- | examples/stm32l1/src/bin/spi.rs | 43 | ||||
| -rw-r--r-- | examples/stm32l1/src/example_common.rs | 17 | ||||
| -rw-r--r-- | examples/stm32l4/.cargo/config.toml | 3 |
8 files changed, 181 insertions, 1 deletions
diff --git a/examples/stm32l1/.cargo/config.toml b/examples/stm32l1/.cargo/config.toml new file mode 100644 index 000000000..e0d2bddf0 --- /dev/null +++ b/examples/stm32l1/.cargo/config.toml | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] | ||
| 2 | # replace your chip as listed in `probe-run --list-chips` | ||
| 3 | runner = "probe-run --chip STM32L151CBxxA" | ||
| 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/stm32l1/Cargo.toml b/examples/stm32l1/Cargo.toml new file mode 100644 index 000000000..e4dd7186a --- /dev/null +++ b/examples/stm32l1/Cargo.toml | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | [package] | ||
| 2 | authors = ["Dario Nieuwenhuis <[email protected]>", "Ulf Lilleengen <[email protected]>"] | ||
| 3 | edition = "2018" | ||
| 4 | name = "embassy-stm32l1-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", "stm32l151cb-a", "time-driver-tim2", "memory-x"] } | ||
| 23 | embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" } | ||
| 24 | embassy-macros = { path = "../../embassy-macros" } | ||
| 25 | |||
| 26 | defmt = "0.2.3" | ||
| 27 | defmt-rtt = "0.2.0" | ||
| 28 | |||
| 29 | cortex-m = "0.7.3" | ||
| 30 | cortex-m-rt = "0.7.0" | ||
| 31 | embedded-hal = "0.2.6" | ||
| 32 | panic-probe = { version = "0.2.0", features = ["print-defmt"] } | ||
| 33 | futures = { version = "0.3.17", default-features = false, features = ["async-await"] } | ||
| 34 | rtt-target = { version = "0.3.1", features = ["cortex-m"] } | ||
| 35 | heapless = { version = "0.7.5", default-features = false } | ||
diff --git a/examples/stm32l1/build.rs b/examples/stm32l1/build.rs new file mode 100644 index 000000000..d534cc3df --- /dev/null +++ b/examples/stm32l1/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/stm32l1/memory.x b/examples/stm32l1/memory.x new file mode 100644 index 000000000..c94d395c8 --- /dev/null +++ b/examples/stm32l1/memory.x | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | FLASH : ORIGIN = 0x08000000, LENGTH = 128K | ||
| 4 | RAM : ORIGIN = 0x20000000, LENGTH = 32K | ||
| 5 | } | ||
diff --git a/examples/stm32l1/src/bin/blinky.rs b/examples/stm32l1/src/bin/blinky.rs new file mode 100644 index 000000000..deabdddba --- /dev/null +++ b/examples/stm32l1/src/bin/blinky.rs | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | #[path = "../example_common.rs"] | ||
| 6 | mod example_common; | ||
| 7 | |||
| 8 | use embassy::executor::Spawner; | ||
| 9 | use embassy::time::{Duration, Timer}; | ||
| 10 | use embassy_stm32::gpio::{Level, Output, Speed}; | ||
| 11 | use embassy_stm32::Peripherals; | ||
| 12 | use embedded_hal::digital::v2::OutputPin; | ||
| 13 | use example_common::*; | ||
| 14 | |||
| 15 | #[embassy::main] | ||
| 16 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 17 | info!("Hello World!"); | ||
| 18 | |||
| 19 | let mut led = Output::new(p.PA12, Level::High, Speed::Low); | ||
| 20 | |||
| 21 | loop { | ||
| 22 | info!("high"); | ||
| 23 | unwrap!(led.set_high()); | ||
| 24 | Timer::after(Duration::from_millis(1000)).await; | ||
| 25 | |||
| 26 | info!("low"); | ||
| 27 | unwrap!(led.set_low()); | ||
| 28 | Timer::after(Duration::from_millis(1000)).await; | ||
| 29 | } | ||
| 30 | } | ||
diff --git a/examples/stm32l1/src/bin/spi.rs b/examples/stm32l1/src/bin/spi.rs new file mode 100644 index 000000000..3cfbe3fc4 --- /dev/null +++ b/examples/stm32l1/src/bin/spi.rs | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | #[path = "../example_common.rs"] | ||
| 6 | mod example_common; | ||
| 7 | |||
| 8 | use embassy::executor::Spawner; | ||
| 9 | use embassy_stm32::gpio::{Level, Output, Speed}; | ||
| 10 | use embedded_hal::digital::v2::OutputPin; | ||
| 11 | use example_common::*; | ||
| 12 | |||
| 13 | use embassy_stm32::dma::NoDma; | ||
| 14 | use embassy_stm32::spi::{Config, Spi}; | ||
| 15 | use embassy_stm32::time::Hertz; | ||
| 16 | use embassy_stm32::Peripherals; | ||
| 17 | use embedded_hal::blocking::spi::Transfer; | ||
| 18 | |||
| 19 | #[embassy::main] | ||
| 20 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 21 | info!("Hello World, folks!"); | ||
| 22 | |||
| 23 | let mut spi = Spi::new( | ||
| 24 | p.SPI1, | ||
| 25 | p.PA5, | ||
| 26 | p.PA7, | ||
| 27 | p.PA6, | ||
| 28 | NoDma, | ||
| 29 | NoDma, | ||
| 30 | Hertz(1_000_000), | ||
| 31 | Config::default(), | ||
| 32 | ); | ||
| 33 | |||
| 34 | let mut cs = Output::new(p.PA4, Level::High, Speed::VeryHigh); | ||
| 35 | |||
| 36 | loop { | ||
| 37 | let mut buf = [0x0Au8; 4]; | ||
| 38 | unwrap!(cs.set_low()); | ||
| 39 | unwrap!(spi.transfer(&mut buf)); | ||
| 40 | unwrap!(cs.set_high()); | ||
| 41 | info!("xfer {=[u8]:x}", buf); | ||
| 42 | } | ||
| 43 | } | ||
diff --git a/examples/stm32l1/src/example_common.rs b/examples/stm32l1/src/example_common.rs new file mode 100644 index 000000000..54d633837 --- /dev/null +++ b/examples/stm32l1/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 | } | ||
diff --git a/examples/stm32l4/.cargo/config.toml b/examples/stm32l4/.cargo/config.toml index 38dd98d1e..b157e3aeb 100644 --- a/examples/stm32l4/.cargo/config.toml +++ b/examples/stm32l4/.cargo/config.toml | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] | 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] |
| 2 | # replace STM32F429ZITx with your chip as listed in `probe-run --list-chips` | 2 | # replace STM32F429ZITx with your chip as listed in `probe-run --list-chips` |
| 3 | runner = "probe-run --chip STM32L4S5VI" | 3 | #runner = "probe-run --chip STM32L475VGT6" |
| 4 | runner = "probe-run --chip STM32L475VG" | ||
| 4 | 5 | ||
| 5 | rustflags = [ | 6 | rustflags = [ |
| 6 | # LLD (shipped with the Rust toolchain) is used as the default linker | 7 | # LLD (shipped with the Rust toolchain) is used as the default linker |
