diff options
Diffstat (limited to 'docs/examples')
| -rw-r--r-- | docs/examples/basic/.cargo/config.toml | 4 | ||||
| -rw-r--r-- | docs/examples/basic/Cargo.toml | 20 | ||||
| -rw-r--r-- | docs/examples/basic/src/main.rs | 33 | ||||
| -rw-r--r-- | docs/examples/layer-by-layer/.cargo/config.toml | 3 | ||||
| -rw-r--r-- | docs/examples/layer-by-layer/Cargo.toml | 5 | ||||
| -rw-r--r-- | docs/examples/layer-by-layer/blinky-async/Cargo.toml | 20 | ||||
| -rw-r--r-- | docs/examples/layer-by-layer/blinky-hal/Cargo.toml | 18 | ||||
| -rw-r--r-- | docs/examples/layer-by-layer/blinky-irq/Cargo.toml | 20 | ||||
| -rw-r--r-- | docs/examples/layer-by-layer/blinky-pac/Cargo.toml | 18 | ||||
| -rw-r--r-- | docs/examples/layer-by-layer/blinky-pac/src/main.rs | 48 | ||||
| -rw-r--r-- | docs/examples/layer-by-layer/memory.x | 5 |
11 files changed, 118 insertions, 76 deletions
diff --git a/docs/examples/basic/.cargo/config.toml b/docs/examples/basic/.cargo/config.toml index 8ca28df39..17616a054 100644 --- a/docs/examples/basic/.cargo/config.toml +++ b/docs/examples/basic/.cargo/config.toml | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] | 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] |
| 2 | # replace nRF82840_xxAA with your chip as listed in `probe-run --list-chips` | 2 | # replace nRF82840_xxAA with your chip as listed in `probe-rs chip list` |
| 3 | runner = "probe-run --chip nRF52840_xxAA" | 3 | runner = "probe-rs run --chip nRF52840_xxAA" |
| 4 | 4 | ||
| 5 | [build] | 5 | [build] |
| 6 | target = "thumbv7em-none-eabi" | 6 | target = "thumbv7em-none-eabi" |
diff --git a/docs/examples/basic/Cargo.toml b/docs/examples/basic/Cargo.toml index e82165032..fadda102b 100644 --- a/docs/examples/basic/Cargo.toml +++ b/docs/examples/basic/Cargo.toml | |||
| @@ -1,18 +1,24 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | authors = ["Dario Nieuwenhuis <[email protected]>"] | 2 | authors = ["Dario Nieuwenhuis <[email protected]>"] |
| 3 | edition = "2018" | 3 | edition = "2024" |
| 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 | license = "MIT OR Apache-2.0" |
| 7 | 7 | ||
| 8 | publish = false | ||
| 8 | [dependencies] | 9 | [dependencies] |
| 9 | embassy-executor = { version = "0.5.0", path = "../../../embassy-executor", features = ["defmt", "integrated-timers", "arch-cortex-m", "executor-thread"] } | 10 | embassy-executor = { version = "0.9.0", path = "../../../embassy-executor", features = ["defmt", "arch-cortex-m", "executor-thread"] } |
| 10 | embassy-time = { version = "0.3.1", path = "../../../embassy-time", features = ["defmt"] } | 11 | embassy-time = { version = "0.5.0", path = "../../../embassy-time", features = ["defmt"] } |
| 11 | embassy-nrf = { version = "0.1.0", path = "../../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote"] } | 12 | embassy-nrf = { version = "0.8.0", path = "../../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote"] } |
| 12 | 13 | ||
| 13 | defmt = "0.3" | 14 | defmt = "1.0.1" |
| 14 | defmt-rtt = "0.3" | 15 | defmt-rtt = "1.0.0" |
| 15 | 16 | ||
| 16 | cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } | 17 | cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } |
| 17 | cortex-m-rt = "0.7.0" | 18 | cortex-m-rt = "0.7.0" |
| 18 | panic-probe = { version = "0.3", features = ["print-defmt"] } | 19 | panic-probe = { version = "1.0.0", features = ["print-defmt"] } |
| 20 | |||
| 21 | [package.metadata.embassy] | ||
| 22 | build = [ | ||
| 23 | { target = "thumbv7em-none-eabi" } | ||
| 24 | ] | ||
diff --git a/docs/examples/basic/src/main.rs b/docs/examples/basic/src/main.rs index 4412712c8..42797612c 100644 --- a/docs/examples/basic/src/main.rs +++ b/docs/examples/basic/src/main.rs | |||
| @@ -3,24 +3,41 @@ | |||
| 3 | 3 | ||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_nrf::gpio::{Level, Output, OutputDrive}; | 6 | use embassy_nrf::Peri; |
| 7 | use embassy_time::{Duration, Timer}; | 7 | use embassy_nrf::gpio::{AnyPin, Input, Level, Output, OutputDrive, Pull}; |
| 8 | use {defmt_rtt as _, panic_probe as _}; // global logger | 8 | use embassy_time::Timer; |
| 9 | use {defmt_rtt as _, panic_probe as _}; | ||
| 9 | 10 | ||
| 11 | // Declare async tasks | ||
| 10 | #[embassy_executor::task] | 12 | #[embassy_executor::task] |
| 11 | async fn blinker(mut led: Output<'static>, interval: Duration) { | 13 | async fn blink(pin: Peri<'static, AnyPin>) { |
| 14 | let mut led = Output::new(pin, Level::Low, OutputDrive::Standard); | ||
| 15 | |||
| 12 | loop { | 16 | loop { |
| 17 | // Timekeeping is globally available, no need to mess with hardware timers. | ||
| 13 | led.set_high(); | 18 | led.set_high(); |
| 14 | Timer::after(interval).await; | 19 | Timer::after_millis(150).await; |
| 15 | led.set_low(); | 20 | led.set_low(); |
| 16 | Timer::after(interval).await; | 21 | Timer::after_millis(150).await; |
| 17 | } | 22 | } |
| 18 | } | 23 | } |
| 19 | 24 | ||
| 25 | // Main is itself an async task as well. | ||
| 20 | #[embassy_executor::main] | 26 | #[embassy_executor::main] |
| 21 | async fn main(spawner: Spawner) { | 27 | async fn main(spawner: Spawner) { |
| 28 | // Initialize the embassy-nrf HAL. | ||
| 22 | let p = embassy_nrf::init(Default::default()); | 29 | let p = embassy_nrf::init(Default::default()); |
| 23 | 30 | ||
| 24 | let led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard); | 31 | // Spawned tasks run in the background, concurrently. |
| 25 | unwrap!(spawner.spawn(blinker(led, Duration::from_millis(300)))); | 32 | spawner.spawn(blink(p.P0_13.into()).unwrap()); |
| 33 | |||
| 34 | let mut button = Input::new(p.P0_11, Pull::Up); | ||
| 35 | loop { | ||
| 36 | // Asynchronously wait for GPIO events, allowing other tasks | ||
| 37 | // to run, or the core to sleep. | ||
| 38 | button.wait_for_low().await; | ||
| 39 | info!("Button pressed!"); | ||
| 40 | button.wait_for_high().await; | ||
| 41 | info!("Button released!"); | ||
| 42 | } | ||
| 26 | } | 43 | } |
diff --git a/docs/examples/layer-by-layer/.cargo/config.toml b/docs/examples/layer-by-layer/.cargo/config.toml index 3012f05dc..f30d9e446 100644 --- a/docs/examples/layer-by-layer/.cargo/config.toml +++ b/docs/examples/layer-by-layer/.cargo/config.toml | |||
| @@ -1,5 +1,6 @@ | |||
| 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] | 1 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] |
| 2 | runner = "probe-run --chip STM32L475VG" | 2 | # replace your chip as listed in `probe-rs chip list` |
| 3 | runner = "probe-rs run --chip STM32L475VG" | ||
| 3 | 4 | ||
| 4 | rustflags = [ | 5 | rustflags = [ |
| 5 | "-C", "link-arg=--nmagic", | 6 | "-C", "link-arg=--nmagic", |
diff --git a/docs/examples/layer-by-layer/Cargo.toml b/docs/examples/layer-by-layer/Cargo.toml index 0f233eae5..01666ec6e 100644 --- a/docs/examples/layer-by-layer/Cargo.toml +++ b/docs/examples/layer-by-layer/Cargo.toml | |||
| @@ -3,14 +3,9 @@ resolver = "2" | |||
| 3 | members = [ | 3 | members = [ |
| 4 | "blinky-pac", | 4 | "blinky-pac", |
| 5 | "blinky-hal", | 5 | "blinky-hal", |
| 6 | "blinky-irq", | ||
| 7 | "blinky-async", | 6 | "blinky-async", |
| 8 | ] | 7 | ] |
| 9 | 8 | ||
| 10 | [patch.crates-io] | ||
| 11 | embassy-executor = { path = "../../../embassy-executor" } | ||
| 12 | embassy-stm32 = { path = "../../../embassy-stm32" } | ||
| 13 | |||
| 14 | [profile.release] | 9 | [profile.release] |
| 15 | codegen-units = 1 | 10 | codegen-units = 1 |
| 16 | debug = 2 | 11 | debug = 2 |
diff --git a/docs/examples/layer-by-layer/blinky-async/Cargo.toml b/docs/examples/layer-by-layer/blinky-async/Cargo.toml index 64f7e8403..797ae3097 100644 --- a/docs/examples/layer-by-layer/blinky-async/Cargo.toml +++ b/docs/examples/layer-by-layer/blinky-async/Cargo.toml | |||
| @@ -1,15 +1,21 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | name = "blinky-async" | 2 | name = "blinky-async" |
| 3 | version = "0.1.0" | 3 | version = "0.1.0" |
| 4 | edition = "2021" | 4 | edition = "2024" |
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | 6 | ||
| 7 | publish = false | ||
| 7 | [dependencies] | 8 | [dependencies] |
| 8 | cortex-m = "0.7" | 9 | cortex-m = { version = "0.7", features = ["critical-section-single-core"] } |
| 9 | cortex-m-rt = "0.7" | 10 | cortex-m-rt = "0.7" |
| 10 | embassy-stm32 = { version = "0.1.0", features = ["stm32l475vg", "memory-x", "exti"] } | 11 | embassy-stm32 = { version = "0.4.0", path = "../../../../embassy-stm32", features = ["stm32l475vg", "memory-x", "exti"] } |
| 11 | embassy-executor = { version = "0.5.0", features = ["arch-cortex-m", "executor-thread"] } | 12 | embassy-executor = { version = "0.9.0", path = "../../../../embassy-executor", features = ["arch-cortex-m", "executor-thread"] } |
| 12 | 13 | ||
| 13 | defmt = "0.3.0" | 14 | defmt = "1.0.1" |
| 14 | defmt-rtt = "0.3.0" | 15 | defmt-rtt = "1.0.0" |
| 15 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } | 16 | panic-probe = { version = "1.0.0", features = ["print-defmt"] } |
| 17 | |||
| 18 | [package.metadata.embassy] | ||
| 19 | build = [ | ||
| 20 | { target = "thumbv7em-none-eabi" } | ||
| 21 | ] | ||
diff --git a/docs/examples/layer-by-layer/blinky-hal/Cargo.toml b/docs/examples/layer-by-layer/blinky-hal/Cargo.toml index c15de2db2..802b8b32e 100644 --- a/docs/examples/layer-by-layer/blinky-hal/Cargo.toml +++ b/docs/examples/layer-by-layer/blinky-hal/Cargo.toml | |||
| @@ -1,14 +1,20 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | name = "blinky-hal" | 2 | name = "blinky-hal" |
| 3 | version = "0.1.0" | 3 | version = "0.1.0" |
| 4 | edition = "2021" | 4 | edition = "2024" |
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | 6 | ||
| 7 | publish = false | ||
| 7 | [dependencies] | 8 | [dependencies] |
| 8 | cortex-m = "0.7" | ||
| 9 | cortex-m-rt = "0.7" | 9 | cortex-m-rt = "0.7" |
| 10 | embassy-stm32 = { version = "0.1.0", features = ["stm32l475vg", "memory-x"] } | 10 | cortex-m = { version = "0.7", features = ["critical-section-single-core"] } |
| 11 | embassy-stm32 = { version = "0.4.0", path = "../../../../embassy-stm32", features = ["stm32l475vg", "memory-x"] } | ||
| 11 | 12 | ||
| 12 | defmt = "0.3.0" | 13 | defmt = "1.0.1" |
| 13 | defmt-rtt = "0.3.0" | 14 | defmt-rtt = "1.0.0" |
| 14 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } | 15 | panic-probe = { version = "1.0.0", features = ["print-defmt"] } |
| 16 | |||
| 17 | [package.metadata.embassy] | ||
| 18 | build = [ | ||
| 19 | { target = "thumbv7em-none-eabi" } | ||
| 20 | ] | ||
diff --git a/docs/examples/layer-by-layer/blinky-irq/Cargo.toml b/docs/examples/layer-by-layer/blinky-irq/Cargo.toml index 9733658b6..d1b893a1e 100644 --- a/docs/examples/layer-by-layer/blinky-irq/Cargo.toml +++ b/docs/examples/layer-by-layer/blinky-irq/Cargo.toml | |||
| @@ -1,14 +1,22 @@ | |||
| 1 | [workspace] | ||
| 2 | |||
| 1 | [package] | 3 | [package] |
| 2 | name = "blinky-irq" | 4 | name = "blinky-irq" |
| 3 | version = "0.1.0" | 5 | version = "0.1.0" |
| 4 | edition = "2021" | 6 | edition = "2024" |
| 5 | license = "MIT OR Apache-2.0" | 7 | license = "MIT OR Apache-2.0" |
| 6 | 8 | ||
| 9 | publish = false | ||
| 7 | [dependencies] | 10 | [dependencies] |
| 8 | cortex-m = "0.7" | 11 | cortex-m = { version = "0.7", features = ["critical-section-single-core"] } |
| 9 | cortex-m-rt = { version = "0.7" } | 12 | cortex-m-rt = { version = "0.7" } |
| 10 | embassy-stm32 = { version = "0.1.0", features = ["stm32l475vg", "memory-x", "unstable-pac"] } | 13 | embassy-stm32 = { version = "0.4.0", path = "../../../../embassy-stm32", features = ["stm32l475vg", "memory-x", "unstable-pac"] } |
| 14 | |||
| 15 | defmt = "1.0.1" | ||
| 16 | defmt-rtt = "1.0.0" | ||
| 17 | panic-probe = { version = "1.0.0", features = ["print-defmt"] } | ||
| 11 | 18 | ||
| 12 | defmt = "0.3.0" | 19 | [package.metadata.embassy] |
| 13 | defmt-rtt = "0.3.0" | 20 | build = [ |
| 14 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } | 21 | { target = "thumbv7em-none-eabi" } |
| 22 | ] | ||
diff --git a/docs/examples/layer-by-layer/blinky-pac/Cargo.toml b/docs/examples/layer-by-layer/blinky-pac/Cargo.toml index f872b94cb..fa093a3af 100644 --- a/docs/examples/layer-by-layer/blinky-pac/Cargo.toml +++ b/docs/examples/layer-by-layer/blinky-pac/Cargo.toml | |||
| @@ -1,14 +1,20 @@ | |||
| 1 | [package] | 1 | [package] |
| 2 | name = "blinky-pac" | 2 | name = "blinky-pac" |
| 3 | version = "0.1.0" | 3 | version = "0.1.0" |
| 4 | edition = "2021" | 4 | edition = "2024" |
| 5 | license = "MIT OR Apache-2.0" | 5 | license = "MIT OR Apache-2.0" |
| 6 | 6 | ||
| 7 | publish = false | ||
| 7 | [dependencies] | 8 | [dependencies] |
| 8 | cortex-m = "0.7" | 9 | cortex-m = { version = "0.7", features = ["critical-section-single-core"] } |
| 9 | cortex-m-rt = "0.7" | 10 | cortex-m-rt = "0.7" |
| 10 | stm32-metapac = { version = "1", features = ["stm32l475vg", "memory-x"] } | 11 | stm32-metapac = { version = "16", features = ["stm32l475vg"] } |
| 11 | 12 | ||
| 12 | defmt = "0.3.0" | 13 | defmt = "1.0.1" |
| 13 | defmt-rtt = "0.3.0" | 14 | defmt-rtt = "1.0.0" |
| 14 | panic-probe = { version = "0.3.0", features = ["print-defmt"] } | 15 | panic-probe = { version = "1.0.0", features = ["print-defmt"] } |
| 16 | |||
| 17 | [package.metadata.embassy] | ||
| 18 | build = [ | ||
| 19 | { target = "thumbv7em-none-eabi" } | ||
| 20 | ] | ||
diff --git a/docs/examples/layer-by-layer/blinky-pac/src/main.rs b/docs/examples/layer-by-layer/blinky-pac/src/main.rs index 990d46cb6..cfbd91306 100644 --- a/docs/examples/layer-by-layer/blinky-pac/src/main.rs +++ b/docs/examples/layer-by-layer/blinky-pac/src/main.rs | |||
| @@ -8,46 +8,38 @@ use {defmt_rtt as _, panic_probe as _, stm32_metapac as pac}; | |||
| 8 | fn main() -> ! { | 8 | fn main() -> ! { |
| 9 | // Enable GPIO clock | 9 | // Enable GPIO clock |
| 10 | let rcc = pac::RCC; | 10 | let rcc = pac::RCC; |
| 11 | unsafe { | 11 | rcc.ahb2enr().modify(|w| { |
| 12 | rcc.ahb2enr().modify(|w| { | 12 | w.set_gpioben(true); |
| 13 | w.set_gpioben(true); | 13 | w.set_gpiocen(true); |
| 14 | w.set_gpiocen(true); | 14 | }); |
| 15 | }); | ||
| 16 | 15 | ||
| 17 | rcc.ahb2rstr().modify(|w| { | 16 | rcc.ahb2rstr().modify(|w| { |
| 18 | w.set_gpiobrst(true); | 17 | w.set_gpiobrst(true); |
| 19 | w.set_gpiocrst(true); | 18 | w.set_gpiocrst(true); |
| 20 | w.set_gpiobrst(false); | 19 | w.set_gpiobrst(false); |
| 21 | w.set_gpiocrst(false); | 20 | w.set_gpiocrst(false); |
| 22 | }); | 21 | }); |
| 23 | } | ||
| 24 | 22 | ||
| 25 | // Setup button | 23 | // Setup button |
| 26 | let gpioc = pac::GPIOC; | 24 | let gpioc = pac::GPIOC; |
| 27 | const BUTTON_PIN: usize = 13; | 25 | const BUTTON_PIN: usize = 13; |
| 28 | unsafe { | 26 | gpioc.pupdr().modify(|w| w.set_pupdr(BUTTON_PIN, vals::Pupdr::PULL_UP)); |
| 29 | gpioc.pupdr().modify(|w| w.set_pupdr(BUTTON_PIN, vals::Pupdr::PULLUP)); | 27 | gpioc.otyper().modify(|w| w.set_ot(BUTTON_PIN, vals::Ot::PUSH_PULL)); |
| 30 | gpioc.otyper().modify(|w| w.set_ot(BUTTON_PIN, vals::Ot::PUSHPULL)); | 28 | gpioc.moder().modify(|w| w.set_moder(BUTTON_PIN, vals::Moder::INPUT)); |
| 31 | gpioc.moder().modify(|w| w.set_moder(BUTTON_PIN, vals::Moder::INPUT)); | ||
| 32 | } | ||
| 33 | 29 | ||
| 34 | // Setup LED | 30 | // Setup LED |
| 35 | let gpiob = pac::GPIOB; | 31 | let gpiob = pac::GPIOB; |
| 36 | const LED_PIN: usize = 14; | 32 | const LED_PIN: usize = 14; |
| 37 | unsafe { | 33 | gpiob.pupdr().modify(|w| w.set_pupdr(LED_PIN, vals::Pupdr::FLOATING)); |
| 38 | gpiob.pupdr().modify(|w| w.set_pupdr(LED_PIN, vals::Pupdr::FLOATING)); | 34 | gpiob.otyper().modify(|w| w.set_ot(LED_PIN, vals::Ot::PUSH_PULL)); |
| 39 | gpiob.otyper().modify(|w| w.set_ot(LED_PIN, vals::Ot::PUSHPULL)); | 35 | gpiob.moder().modify(|w| w.set_moder(LED_PIN, vals::Moder::OUTPUT)); |
| 40 | gpiob.moder().modify(|w| w.set_moder(LED_PIN, vals::Moder::OUTPUT)); | ||
| 41 | } | ||
| 42 | 36 | ||
| 43 | // Main loop | 37 | // Main loop |
| 44 | loop { | 38 | loop { |
| 45 | unsafe { | 39 | if gpioc.idr().read().idr(BUTTON_PIN) == vals::Idr::LOW { |
| 46 | if gpioc.idr().read().idr(BUTTON_PIN) == vals::Idr::LOW { | 40 | gpiob.bsrr().write(|w| w.set_bs(LED_PIN, true)); |
| 47 | gpiob.bsrr().write(|w| w.set_bs(LED_PIN, true)); | 41 | } else { |
| 48 | } else { | 42 | gpiob.bsrr().write(|w| w.set_br(LED_PIN, true)); |
| 49 | gpiob.bsrr().write(|w| w.set_br(LED_PIN, true)); | ||
| 50 | } | ||
| 51 | } | 43 | } |
| 52 | } | 44 | } |
| 53 | } | 45 | } |
diff --git a/docs/examples/layer-by-layer/memory.x b/docs/examples/layer-by-layer/memory.x new file mode 100644 index 000000000..69f5b28a1 --- /dev/null +++ b/docs/examples/layer-by-layer/memory.x | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | MEMORY | ||
| 2 | { | ||
| 3 | FLASH : ORIGIN = 0x08000000, LENGTH = 2048K /* BANK_1 */ | ||
| 4 | RAM : ORIGIN = 0x20000000, LENGTH = 640K /* SRAM */ | ||
| 5 | } | ||
