aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2021-09-21 13:42:27 +0200
committerUlf Lilleengen <[email protected]>2021-09-21 14:50:23 +0200
commitc79485c286d96ca7b1d0bdeb7360488b838a841e (patch)
tree58415adb5d9dbdb1a31ab8f9b4b6cc3cb727c986 /examples
parent14aa4265db25adb75fdcaf66798a878ae789bf9c (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.toml18
-rw-r--r--examples/stm32l1/Cargo.toml35
-rw-r--r--examples/stm32l1/build.rs31
-rw-r--r--examples/stm32l1/memory.x5
-rw-r--r--examples/stm32l1/src/bin/blinky.rs30
-rw-r--r--examples/stm32l1/src/bin/spi.rs43
-rw-r--r--examples/stm32l1/src/example_common.rs17
-rw-r--r--examples/stm32l4/.cargo/config.toml3
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`
3runner = "probe-run --chip STM32L151CBxxA"
4
5rustflags = [
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]
18target = "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]
2authors = ["Dario Nieuwenhuis <[email protected]>", "Ulf Lilleengen <[email protected]>"]
3edition = "2018"
4name = "embassy-stm32l1-examples"
5version = "0.1.0"
6resolver = "2"
7
8[features]
9default = [
10 "defmt-default",
11]
12defmt-default = []
13defmt-trace = []
14defmt-debug = []
15defmt-info = []
16defmt-warn = []
17defmt-error = []
18
19[dependencies]
20embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt", "defmt-trace"] }
21embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
22embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "defmt-trace", "stm32l151cb-a", "time-driver-tim2", "memory-x"] }
23embassy-hal-common = {version = "0.1.0", path = "../../embassy-hal-common" }
24embassy-macros = { path = "../../embassy-macros" }
25
26defmt = "0.2.3"
27defmt-rtt = "0.2.0"
28
29cortex-m = "0.7.3"
30cortex-m-rt = "0.7.0"
31embedded-hal = "0.2.6"
32panic-probe = { version = "0.2.0", features = ["print-defmt"] }
33futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
34rtt-target = { version = "0.3.1", features = ["cortex-m"] }
35heapless = { 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
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/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 @@
1MEMORY
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"]
6mod example_common;
7
8use embassy::executor::Spawner;
9use embassy::time::{Duration, Timer};
10use embassy_stm32::gpio::{Level, Output, Speed};
11use embassy_stm32::Peripherals;
12use embedded_hal::digital::v2::OutputPin;
13use example_common::*;
14
15#[embassy::main]
16async 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"]
6mod example_common;
7
8use embassy::executor::Spawner;
9use embassy_stm32::gpio::{Level, Output, Speed};
10use embedded_hal::digital::v2::OutputPin;
11use example_common::*;
12
13use embassy_stm32::dma::NoDma;
14use embassy_stm32::spi::{Config, Spi};
15use embassy_stm32::time::Hertz;
16use embassy_stm32::Peripherals;
17use embedded_hal::blocking::spi::Transfer;
18
19#[embassy::main]
20async 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
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}
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`
3runner = "probe-run --chip STM32L4S5VI" 3#runner = "probe-run --chip STM32L475VGT6"
4runner = "probe-run --chip STM32L475VG"
4 5
5rustflags = [ 6rustflags = [
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