diff options
Diffstat (limited to 'docs/modules/ROOT/examples')
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]>"] | |||
| 3 | edition = "2018" | 3 | edition = "2018" |
| 4 | name = "embassy-basic-example" | 4 | name = "embassy-basic-example" |
| 5 | version = "0.1.0" | 5 | version = "0.1.0" |
| 6 | license = "MIT OR Apache-2.0" | ||
| 6 | 7 | ||
| 7 | [dependencies] | 8 | [dependencies] |
| 8 | embassy-executor = { version = "0.1.0", path = "../../../../../embassy-executor", features = ["defmt", "nightly"] } | 9 | embassy-executor = { version = "0.2.0", path = "../../../../../embassy-executor", features = ["defmt", "nightly", "integrated-timers", "arch-cortex-m", "executor-thread"] } |
| 9 | embassy-time = { version = "0.1.0", path = "../../../../../embassy-time", features = ["defmt", "nightly"] } | 10 | embassy-time = { version = "0.1.0", path = "../../../../../embassy-time", features = ["defmt", "nightly"] } |
| 10 | embassy-nrf = { version = "0.1.0", path = "../../../../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "nightly"] } | 11 | embassy-nrf = { version = "0.1.0", path = "../../../../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote", "nightly"] } |
| 11 | 12 | ||
| 12 | defmt = "0.3" | 13 | defmt = "0.3" |
| 13 | defmt-rtt = "0.3" | 14 | defmt-rtt = "0.3" |
| 14 | 15 | ||
| 15 | cortex-m = "0.7.3" | 16 | cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } |
| 16 | cortex-m-rt = "0.7.0" | 17 | cortex-m-rt = "0.7.0" |
| 17 | embedded-hal = "0.2.6" | ||
| 18 | panic-probe = { version = "0.3", features = ["print-defmt"] } | 18 | panic-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 | |||
| 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 | |||
| 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 @@ | |||
| 1 | MEMORY | ||
| 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] |
| 11 | embassy-executor = { path = "../../../../../embassy-executor" } | 11 | embassy-executor = { path = "../../../../../embassy-executor" } |
| 12 | embassy-stm32 = { path = "../../../../../embassy-stm32" } | 12 | embassy-stm32 = { path = "../../../../../embassy-stm32" } |
| 13 | stm32-metapac = { path = "../../../../../stm32-metapac" } | ||
| 14 | 13 | ||
| 15 | [profile.release] | 14 | [profile.release] |
| 16 | codegen-units = 1 | 15 | codegen-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 @@ | |||
| 2 | name = "blinky-async" | 2 | name = "blinky-async" |
| 3 | version = "0.1.0" | 3 | version = "0.1.0" |
| 4 | edition = "2021" | 4 | edition = "2021" |
| 5 | license = "MIT OR Apache-2.0" | ||
| 5 | 6 | ||
| 6 | [dependencies] | 7 | [dependencies] |
| 7 | cortex-m = "0.7" | 8 | cortex-m = "0.7" |
| 8 | cortex-m-rt = "0.7" | 9 | cortex-m-rt = "0.7" |
| 9 | embassy-stm32 = { version = "0.1.0", features = ["stm32l475vg", "memory-x", "exti"], default-features = false } | 10 | embassy-stm32 = { version = "0.1.0", features = ["stm32l475vg", "memory-x", "exti"] } |
| 10 | embassy-executor = { version = "0.1.0", default-features = false, features = ["nightly"] } | 11 | embassy-executor = { version = "0.2.0", features = ["nightly", "arch-cortex-m", "executor-thread"] } |
| 11 | 12 | ||
| 12 | defmt = "0.3.0" | 13 | defmt = "0.3.0" |
| 13 | defmt-rtt = "0.3.0" | 14 | defmt-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 @@ | |||
| 2 | name = "blinky-hal" | 2 | name = "blinky-hal" |
| 3 | version = "0.1.0" | 3 | version = "0.1.0" |
| 4 | edition = "2021" | 4 | edition = "2021" |
| 5 | license = "MIT OR Apache-2.0" | ||
| 5 | 6 | ||
| 6 | [dependencies] | 7 | [dependencies] |
| 7 | cortex-m = "0.7" | 8 | cortex-m = "0.7" |
| 8 | cortex-m-rt = "0.7" | 9 | cortex-m-rt = "0.7" |
| 9 | embassy-stm32 = { version = "0.1.0", features = ["stm32l475vg", "memory-x"], default-features = false } | 10 | embassy-stm32 = { version = "0.1.0", features = ["stm32l475vg", "memory-x"] } |
| 10 | 11 | ||
| 11 | defmt = "0.3.0" | 12 | defmt = "0.3.0" |
| 12 | defmt-rtt = "0.3.0" | 13 | defmt-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 @@ | |||
| 2 | name = "blinky-irq" | 2 | name = "blinky-irq" |
| 3 | version = "0.1.0" | 3 | version = "0.1.0" |
| 4 | edition = "2021" | 4 | edition = "2021" |
| 5 | license = "MIT OR Apache-2.0" | ||
| 5 | 6 | ||
| 6 | [dependencies] | 7 | [dependencies] |
| 7 | cortex-m = "0.7" | 8 | cortex-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; | |||
| 64 | const PIN: usize = 13; | 64 | const PIN: usize = 13; |
| 65 | fn check_interrupt<P: Pin>(_pin: &mut Input<'static, P>) -> bool { | 65 | fn 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 | ||
| 74 | fn clear_interrupt<P: Pin>(_pin: &mut Input<'static, P>) { | 72 | fn 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 | ||
| 84 | fn enable_interrupt<P: Pin>(_pin: &mut Input<'static, P>) { | 80 | fn 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 @@ | |||
| 2 | name = "blinky-pac" | 2 | name = "blinky-pac" |
| 3 | version = "0.1.0" | 3 | version = "0.1.0" |
| 4 | edition = "2021" | 4 | edition = "2021" |
| 5 | license = "MIT OR Apache-2.0" | ||
| 5 | 6 | ||
| 6 | [dependencies] | 7 | [dependencies] |
| 7 | cortex-m = "0.7" | 8 | cortex-m = "0.7" |
| 8 | cortex-m-rt = "0.7" | 9 | cortex-m-rt = "0.7" |
| 9 | stm32-metapac = { version = "0.1.0", features = ["stm32l475vg", "memory-x"] } | 10 | stm32-metapac = { version = "1", features = ["stm32l475vg", "memory-x"] } |
| 10 | 11 | ||
| 11 | defmt = "0.3.0" | 12 | defmt = "0.3.0" |
| 12 | defmt-rtt = "0.3.0" | 13 | defmt-rtt = "0.3.0" |
