aboutsummaryrefslogtreecommitdiff
path: root/docs/modules/ROOT/examples
diff options
context:
space:
mode:
authorQuentin Smith <[email protected]>2023-07-17 21:31:43 -0400
committerQuentin Smith <[email protected]>2023-07-17 21:31:43 -0400
commit6f02403184eb7fb7990fb88fc9df9c4328a690a3 (patch)
tree748f510e190bb2724750507a6e69ed1a8e08cb20 /docs/modules/ROOT/examples
parentd896f80405aa8963877049ed999e4aba25d6e2bb (diff)
parent6b5df4523aa1c4902f02e803450ae4b418e0e3ca (diff)
Merge remote-tracking branch 'origin/main' into nrf-pdm
Diffstat (limited to 'docs/modules/ROOT/examples')
-rw-r--r--docs/modules/ROOT/examples/basic/Cargo.toml6
-rw-r--r--docs/modules/ROOT/examples/basic/build.rs35
-rw-r--r--docs/modules/ROOT/examples/basic/memory.x7
-rw-r--r--docs/modules/ROOT/examples/layer-by-layer/Cargo.toml1
-rw-r--r--docs/modules/ROOT/examples/layer-by-layer/blinky-async/Cargo.toml5
-rw-r--r--docs/modules/ROOT/examples/layer-by-layer/blinky-hal/Cargo.toml3
-rw-r--r--docs/modules/ROOT/examples/layer-by-layer/blinky-irq/Cargo.toml1
-rw-r--r--docs/modules/ROOT/examples/layer-by-layer/blinky-irq/src/main.rs24
-rw-r--r--docs/modules/ROOT/examples/layer-by-layer/blinky-pac/Cargo.toml3
9 files changed, 63 insertions, 22 deletions
diff --git a/docs/modules/ROOT/examples/basic/Cargo.toml b/docs/modules/ROOT/examples/basic/Cargo.toml
index ae124a871..237ae0ac2 100644
--- a/docs/modules/ROOT/examples/basic/Cargo.toml
+++ b/docs/modules/ROOT/examples/basic/Cargo.toml
@@ -3,16 +3,16 @@ authors = ["Dario Nieuwenhuis <[email protected]>"]
3edition = "2018" 3edition = "2018"
4name = "embassy-basic-example" 4name = "embassy-basic-example"
5version = "0.1.0" 5version = "0.1.0"
6license = "MIT OR Apache-2.0"
6 7
7[dependencies] 8[dependencies]
8embassy-executor = { version = "0.1.0", path = "../../../../../embassy-executor", features = ["defmt", "nightly"] } 9embassy-executor = { version = "0.2.0", path = "../../../../../embassy-executor", features = ["defmt", "nightly", "integrated-timers", "arch-cortex-m", "executor-thread"] }
9embassy-time = { version = "0.1.0", path = "../../../../../embassy-time", features = ["defmt", "nightly"] } 10embassy-time = { version = "0.1.0", path = "../../../../../embassy-time", features = ["defmt", "nightly"] }
10embassy-nrf = { version = "0.1.0", path = "../../../../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "nightly"] } 11embassy-nrf = { version = "0.1.0", path = "../../../../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "nightly"] }
11 12
12defmt = "0.3" 13defmt = "0.3"
13defmt-rtt = "0.3" 14defmt-rtt = "0.3"
14 15
15cortex-m = "0.7.3" 16cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
16cortex-m-rt = "0.7.0" 17cortex-m-rt = "0.7.0"
17embedded-hal = "0.2.6"
18panic-probe = { version = "0.3", features = ["print-defmt"] } 18panic-probe = { version = "0.3", features = ["print-defmt"] }
diff --git a/docs/modules/ROOT/examples/basic/build.rs b/docs/modules/ROOT/examples/basic/build.rs
new file mode 100644
index 000000000..30691aa97
--- /dev/null
+++ b/docs/modules/ROOT/examples/basic/build.rs
@@ -0,0 +1,35 @@
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
32 println!("cargo:rustc-link-arg-bins=--nmagic");
33 println!("cargo:rustc-link-arg-bins=-Tlink.x");
34 println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
35}
diff --git a/docs/modules/ROOT/examples/basic/memory.x b/docs/modules/ROOT/examples/basic/memory.x
new file mode 100644
index 000000000..9b04edec0
--- /dev/null
+++ b/docs/modules/ROOT/examples/basic/memory.x
@@ -0,0 +1,7 @@
1MEMORY
2{
3 /* NOTE 1 K = 1 KiBi = 1024 bytes */
4 /* These values correspond to the NRF52840 with Softdevices S140 7.0.1 */
5 FLASH : ORIGIN = 0x00000000, LENGTH = 1024K
6 RAM : ORIGIN = 0x20000000, LENGTH = 256K
7}
diff --git a/docs/modules/ROOT/examples/layer-by-layer/Cargo.toml b/docs/modules/ROOT/examples/layer-by-layer/Cargo.toml
index 9048d9302..943249a17 100644
--- a/docs/modules/ROOT/examples/layer-by-layer/Cargo.toml
+++ b/docs/modules/ROOT/examples/layer-by-layer/Cargo.toml
@@ -10,7 +10,6 @@ members = [
10[patch.crates-io] 10[patch.crates-io]
11embassy-executor = { path = "../../../../../embassy-executor" } 11embassy-executor = { path = "../../../../../embassy-executor" }
12embassy-stm32 = { path = "../../../../../embassy-stm32" } 12embassy-stm32 = { path = "../../../../../embassy-stm32" }
13stm32-metapac = { path = "../../../../../stm32-metapac" }
14 13
15[profile.release] 14[profile.release]
16codegen-units = 1 15codegen-units = 1
diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-async/Cargo.toml b/docs/modules/ROOT/examples/layer-by-layer/blinky-async/Cargo.toml
index e2933076f..a7236ed5e 100644
--- a/docs/modules/ROOT/examples/layer-by-layer/blinky-async/Cargo.toml
+++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-async/Cargo.toml
@@ -2,12 +2,13 @@
2name = "blinky-async" 2name = "blinky-async"
3version = "0.1.0" 3version = "0.1.0"
4edition = "2021" 4edition = "2021"
5license = "MIT OR Apache-2.0"
5 6
6[dependencies] 7[dependencies]
7cortex-m = "0.7" 8cortex-m = "0.7"
8cortex-m-rt = "0.7" 9cortex-m-rt = "0.7"
9embassy-stm32 = { version = "0.1.0", features = ["stm32l475vg", "memory-x", "exti"], default-features = false } 10embassy-stm32 = { version = "0.1.0", features = ["stm32l475vg", "memory-x", "exti"] }
10embassy-executor = { version = "0.1.0", default-features = false, features = ["nightly"] } 11embassy-executor = { version = "0.2.0", features = ["nightly", "arch-cortex-m", "executor-thread"] }
11 12
12defmt = "0.3.0" 13defmt = "0.3.0"
13defmt-rtt = "0.3.0" 14defmt-rtt = "0.3.0"
diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/Cargo.toml b/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/Cargo.toml
index dbd3aba8b..c15de2db2 100644
--- a/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/Cargo.toml
+++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/Cargo.toml
@@ -2,11 +2,12 @@
2name = "blinky-hal" 2name = "blinky-hal"
3version = "0.1.0" 3version = "0.1.0"
4edition = "2021" 4edition = "2021"
5license = "MIT OR Apache-2.0"
5 6
6[dependencies] 7[dependencies]
7cortex-m = "0.7" 8cortex-m = "0.7"
8cortex-m-rt = "0.7" 9cortex-m-rt = "0.7"
9embassy-stm32 = { version = "0.1.0", features = ["stm32l475vg", "memory-x"], default-features = false } 10embassy-stm32 = { version = "0.1.0", features = ["stm32l475vg", "memory-x"] }
10 11
11defmt = "0.3.0" 12defmt = "0.3.0"
12defmt-rtt = "0.3.0" 13defmt-rtt = "0.3.0"
diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/Cargo.toml b/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/Cargo.toml
index 0dd326015..9733658b6 100644
--- a/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/Cargo.toml
+++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/Cargo.toml
@@ -2,6 +2,7 @@
2name = "blinky-irq" 2name = "blinky-irq"
3version = "0.1.0" 3version = "0.1.0"
4edition = "2021" 4edition = "2021"
5license = "MIT OR Apache-2.0"
5 6
6[dependencies] 7[dependencies]
7cortex-m = "0.7" 8cortex-m = "0.7"
diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/src/main.rs b/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/src/main.rs
index 743d0c342..aecba0755 100644
--- a/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/src/main.rs
+++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/src/main.rs
@@ -20,13 +20,13 @@ fn main() -> ! {
20 let led = Output::new(p.PB14, Level::Low, Speed::Low); 20 let led = Output::new(p.PB14, Level::Low, Speed::Low);
21 let mut button = Input::new(p.PC13, Pull::Up); 21 let mut button = Input::new(p.PC13, Pull::Up);
22 22
23 cortex_m::interrupt::free(|cs| unsafe { 23 cortex_m::interrupt::free(|cs| {
24 enable_interrupt(&mut button); 24 enable_interrupt(&mut button);
25 25
26 LED.borrow(cs).borrow_mut().replace(led); 26 LED.borrow(cs).borrow_mut().replace(led);
27 BUTTON.borrow(cs).borrow_mut().replace(button); 27 BUTTON.borrow(cs).borrow_mut().replace(button);
28 28
29 NVIC::unmask(pac::Interrupt::EXTI15_10); 29 unsafe { NVIC::unmask(pac::Interrupt::EXTI15_10) };
30 }); 30 });
31 31
32 loop { 32 loop {
@@ -64,25 +64,21 @@ const PORT: u8 = 2;
64const PIN: usize = 13; 64const PIN: usize = 13;
65fn check_interrupt<P: Pin>(_pin: &mut Input<'static, P>) -> bool { 65fn check_interrupt<P: Pin>(_pin: &mut Input<'static, P>) -> bool {
66 let exti = pac::EXTI; 66 let exti = pac::EXTI;
67 unsafe { 67 let pin = PIN;
68 let pin = PIN; 68 let lines = exti.pr(0).read();
69 let lines = exti.pr(0).read(); 69 lines.line(pin)
70 lines.line(pin)
71 }
72} 70}
73 71
74fn clear_interrupt<P: Pin>(_pin: &mut Input<'static, P>) { 72fn clear_interrupt<P: Pin>(_pin: &mut Input<'static, P>) {
75 let exti = pac::EXTI; 73 let exti = pac::EXTI;
76 unsafe { 74 let pin = PIN;
77 let pin = PIN; 75 let mut lines = exti.pr(0).read();
78 let mut lines = exti.pr(0).read(); 76 lines.set_line(pin, true);
79 lines.set_line(pin, true); 77 exti.pr(0).write_value(lines);
80 exti.pr(0).write_value(lines);
81 }
82} 78}
83 79
84fn enable_interrupt<P: Pin>(_pin: &mut Input<'static, P>) { 80fn enable_interrupt<P: Pin>(_pin: &mut Input<'static, P>) {
85 cortex_m::interrupt::free(|_| unsafe { 81 cortex_m::interrupt::free(|_| {
86 let rcc = pac::RCC; 82 let rcc = pac::RCC;
87 rcc.apb2enr().modify(|w| w.set_syscfgen(true)); 83 rcc.apb2enr().modify(|w| w.set_syscfgen(true));
88 84
diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/Cargo.toml b/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/Cargo.toml
index e7f4f5d1f..f872b94cb 100644
--- a/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/Cargo.toml
+++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/Cargo.toml
@@ -2,11 +2,12 @@
2name = "blinky-pac" 2name = "blinky-pac"
3version = "0.1.0" 3version = "0.1.0"
4edition = "2021" 4edition = "2021"
5license = "MIT OR Apache-2.0"
5 6
6[dependencies] 7[dependencies]
7cortex-m = "0.7" 8cortex-m = "0.7"
8cortex-m-rt = "0.7" 9cortex-m-rt = "0.7"
9stm32-metapac = { version = "0.1.0", features = ["stm32l475vg", "memory-x"] } 10stm32-metapac = { version = "1", features = ["stm32l475vg", "memory-x"] }
10 11
11defmt = "0.3.0" 12defmt = "0.3.0"
12defmt-rtt = "0.3.0" 13defmt-rtt = "0.3.0"