From 876faa5685de66ce422bc9196f2442195cdff63b Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Wed, 13 Dec 2023 19:00:26 +0100 Subject: docs: more docs in embassy-boot crate documentation --- docs/modules/ROOT/pages/bootloader.adoc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/pages/bootloader.adoc b/docs/modules/ROOT/pages/bootloader.adoc index b7215e52a..3b0cdb182 100644 --- a/docs/modules/ROOT/pages/bootloader.adoc +++ b/docs/modules/ROOT/pages/bootloader.adoc @@ -45,6 +45,8 @@ The BOOTLOADER_STATE partition must be big enough to store one word per page in The bootloader has a platform-agnostic part, which implements the power fail safe swapping algorithm given the boundaries set by the partitions. The platform-specific part is a minimal shim that provides additional functionality such as watchdogs or supporting the nRF52 softdevice. +NOTE: The linker scripts for the application and bootloader look similar, but the FLASH region must point to the BOOTLOADER partition for the bootloader, and the ACTIVE partition for the application. + === FirmwareUpdater The `FirmwareUpdater` is an object for conveniently flashing firmware to the DFU partition and subsequently marking it as being ready for swapping with the active partition on the next reset. Its principle methods are `write_firmware`, which is called once per the size of the flash "write block" (typically 4KiB), and `mark_updated`, which is the final call. @@ -91,4 +93,4 @@ cp $FIRMWARE_DIR/myfirmware $FIRMWARE_DIR/myfirmware+signed tail -n1 $SECRETS_DIR/message.txt.sig | base64 -d -i - | dd ibs=10 skip=1 >> $FIRMWARE_DIR/myfirmware+signed ---- -Remember, guard the `$SECRETS_DIR/key.sec` key as compromising it means that another party can sign your firmware. \ No newline at end of file +Remember, guard the `$SECRETS_DIR/key.sec` key as compromising it means that another party can sign your firmware. -- cgit From d81395fab3c4e336650b0481790ecdab7d7aa13f Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Thu, 14 Dec 2023 16:01:51 +0100 Subject: Update embedded-hal to 1.0.0-rc.3 --- docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs b/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs index d0c9f4907..54b87662e 100644 --- a/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs +++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs @@ -9,7 +9,7 @@ use {defmt_rtt as _, panic_probe as _}; fn main() -> ! { let p = embassy_stm32::init(Default::default()); let mut led = Output::new(p.PB14, Level::High, Speed::VeryHigh); - let button = Input::new(p.PC13, Pull::Up); + let mut button = Input::new(p.PC13, Pull::Up); loop { if button.is_low() { -- cgit From cf0e5e32add134aefb8ffc1bfac9f49f48bdc9c3 Mon Sep 17 00:00:00 2001 From: Dániel Buga Date: Thu, 21 Dec 2023 14:22:56 +0100 Subject: Remove Xtensa specifier --- docs/modules/ROOT/pages/faq.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/pages/faq.adoc b/docs/modules/ROOT/pages/faq.adoc index d1a012978..1fe9bde37 100644 --- a/docs/modules/ROOT/pages/faq.adoc +++ b/docs/modules/ROOT/pages/faq.adoc @@ -35,7 +35,7 @@ For Cortex-M targets, consider making sure that ALL of the following features ar * `executor-thread` * `nightly` -For Xtensa ESP32, consider using the executors and `#[main]` macro provided by your appropriate link:https://crates.io/crates/esp-hal-common[HAL crate]. +For ESP32, consider using the executors and `#[main]` macro provided by your appropriate link:https://crates.io/crates/esp-hal-common[HAL crate]. == Why is my binary so big? -- cgit From 8b36a32ed5d834b23e970d5b723dd7df1f1c94a2 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Thu, 21 Dec 2023 14:57:49 +0100 Subject: ci: use beta, add secondary nightly ci. --- docs/modules/ROOT/examples/basic/src/main.rs | 1 - docs/modules/ROOT/examples/layer-by-layer/blinky-async/Cargo.toml | 2 +- docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/examples/basic/src/main.rs b/docs/modules/ROOT/examples/basic/src/main.rs index 04170db55..2a4ee5968 100644 --- a/docs/modules/ROOT/examples/basic/src/main.rs +++ b/docs/modules/ROOT/examples/basic/src/main.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use defmt::*; use embassy_executor::Spawner; 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 dcdb71e7b..2d47dccf4 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 @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" cortex-m = "0.7" cortex-m-rt = "0.7" embassy-stm32 = { version = "0.1.0", features = ["stm32l475vg", "memory-x", "exti"] } -embassy-executor = { version = "0.4.0", features = ["nightly", "arch-cortex-m", "executor-thread"] } +embassy-executor = { version = "0.4.0", features = ["arch-cortex-m", "executor-thread"] } defmt = "0.3.0" defmt-rtt = "0.3.0" diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs b/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs index 8df632240..e6753be28 100644 --- a/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs +++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs @@ -1,6 +1,5 @@ #![no_std] #![no_main] -#![feature(type_alias_impl_trait)] use embassy_executor::Spawner; use embassy_stm32::exti::ExtiInput; -- cgit From 9ea7a245e9f74faa1ba1f35988d98fc914414609 Mon Sep 17 00:00:00 2001 From: Adin Ackerman Date: Sun, 24 Dec 2023 11:51:16 -0800 Subject: add some generation resources, add some feature descriptions --- docs/modules/ROOT/pages/new_project.adoc | 25 ++++++++++++++++++------- docs/modules/ROOT/pages/project_structure.adoc | 9 +++++++-- 2 files changed, 25 insertions(+), 9 deletions(-) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/pages/new_project.adoc b/docs/modules/ROOT/pages/new_project.adoc index ce139ed8d..320966bb6 100644 --- a/docs/modules/ROOT/pages/new_project.adoc +++ b/docs/modules/ROOT/pages/new_project.adoc @@ -1,6 +1,17 @@ = Starting a new Embassy project -Once you’ve successfully xref:getting_started.adoc[run some example projects], the next step is to make a standalone Embassy project. The easiest way to do this is to adapt an example for a similar chip to the one you’re targeting. +Once you’ve successfully xref:getting_started.adoc[run some example projects], the next step is to make a standalone Embassy project. + +There are some tools for generating Embassy projects: (WIP) + +==== CLI +- link:https://github.com/adinack/cargo-embassy[cargo-embassy] (STM32 and NRF) + +==== cargo-generate +- link:https://github.com/lulf/embassy-template[embassy-template] (STM32, NRF, and RP) +- link:https://github.com/bentwire/embassy-rp2040-template[embassy-rp2040-template] (RP) + +But if you want to start from scratch: As an example, let’s create a new embassy project from scratch for a STM32G474. The same instructions are applicable for any supported chip with some minor changes. @@ -166,13 +177,13 @@ should result in a blinking LED (if there’s one attached to the pin in `src/ma Erasing sectors ✔ [00:00:00] [#########################################################] 18.00 KiB/18.00 KiB @ 54.09 KiB/s (eta 0s ) Programming pages ✔ [00:00:00] [#########################################################] 17.00 KiB/17.00 KiB @ 35.91 KiB/s (eta 0s ) Finished in 0.817s 0.000000 TRACE BDCR configured: 00008200 -└─ embassy_stm32::rcc::bd::{impl#3}::init::{closure#4} @ /home/you/.cargo/git/checkouts/embassy-9312dcb0ed774b29/7703f47/embassy-stm32/src/fmt.rs:117 +└─ embassy_stm32::rcc::bd::{impl#3}::init::{closure#4} @ /home/you/.cargo/git/checkouts/embassy-9312dcb0ed774b29/7703f47/embassy-stm32/src/fmt.rs:117 0.000000 DEBUG rcc: Clocks { sys: Hertz(16000000), pclk1: Hertz(16000000), pclk1_tim: Hertz(16000000), pclk2: Hertz(16000000), pclk2_tim: Hertz(16000000), hclk1: Hertz(16000000), hclk2: Hertz(16000000), pll1_p: None, adc: None, adc34: None, rtc: Some(Hertz(32000)) } -└─ embassy_stm32::rcc::set_freqs @ /home/you/.cargo/git/checkouts/embassy-9312dcb0ed774b29/7703f47/embassy-stm32/src/fmt.rs:130 +└─ embassy_stm32::rcc::set_freqs @ /home/you/.cargo/git/checkouts/embassy-9312dcb0ed774b29/7703f47/embassy-stm32/src/fmt.rs:130 0.000000 INFO Hello World! -└─ embassy_stm32g474::____embassy_main_task::{async_fn#0} @ src/main.rs:14 +└─ embassy_stm32g474::____embassy_main_task::{async_fn#0} @ src/main.rs:14 0.000091 INFO high -└─ embassy_stm32g474::____embassy_main_task::{async_fn#0} @ src/main.rs:19 +└─ embassy_stm32g474::____embassy_main_task::{async_fn#0} @ src/main.rs:19 0.300201 INFO low -└─ embassy_stm32g474::____embassy_main_task::{async_fn#0} @ src/main.rs:23 ----- \ No newline at end of file +└─ embassy_stm32g474::____embassy_main_task::{async_fn#0} @ src/main.rs:23 +---- diff --git a/docs/modules/ROOT/pages/project_structure.adoc b/docs/modules/ROOT/pages/project_structure.adoc index 3e6008ec4..bdb41d328 100644 --- a/docs/modules/ROOT/pages/project_structure.adoc +++ b/docs/modules/ROOT/pages/project_structure.adoc @@ -38,13 +38,18 @@ DEFMT_LOG = "trace" # <- can change to info, warn, or error === build.rs -This is the build script for your project. It links defmt (what is defmt?) and the `memory.x` file if needed. This file is pretty specific for each chipset, just copy and paste from the corresponding link:https://github.com/embassy-rs/embassy/tree/main/examples[example]. +This is the build script for your project. It links defmt (what is link:https://defmt.ferrous-systems.com[defmt]?) and the `memory.x` file if needed. This file is pretty specific for each chipset, just copy and paste from the corresponding link:https://github.com/embassy-rs/embassy/tree/main/examples[example]. === Cargo.toml This is your manifest file, where you can configure all of the embassy components to use the features you need. -TODO: someone should exhaustively describe every feature for every component! +==== Features +===== Time +- tick-hz-x: Configures the tick rate of `embassy-time`. Higher tick rate means higher precision, and higher CPU wakes. +- defmt-timestamp-uptime: defmt log entries will display the uptime in seconds. + +...more to come === memory.x -- cgit From fa9cb99cb6daa898c0333cd02e0cd0b23ee6852b Mon Sep 17 00:00:00 2001 From: Benjamin Ward Date: Sat, 30 Dec 2023 21:28:41 -0500 Subject: Update docs to reflect current LoRa crate name/location --- docs/modules/ROOT/pages/index.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/pages/index.adoc b/docs/modules/ROOT/pages/index.adoc index 6fba80eda..3cf032c45 100644 --- a/docs/modules/ROOT/pages/index.adoc +++ b/docs/modules/ROOT/pages/index.adoc @@ -41,7 +41,7 @@ The link:https://docs.embassy.dev/embassy-net/[embassy-net] network stack implem The link:https://github.com/embassy-rs/nrf-softdevice[nrf-softdevice] crate provides Bluetooth Low Energy 4.x and 5.x support for nRF52 microcontrollers. === LoRa -link:https://github.com/embassy-rs/lora-phy[lora-phy] and link:https://docs.embassy.dev/embassy-lora/[embassy-lora] supports LoRa networking on a wide range of LoRa radios, fully integrated with a Rust link:https://github.com/ivajloip/rust-lorawan[LoRaWAN] implementation. +link:https://github.com/lora-rs/lora-rs[lora-rs] supports LoRa networking on a wide range of LoRa radios, fully integrated with a Rust link:https://github.com/ivajloip/rust-lorawan[LoRaWAN] implementation. === USB link:https://docs.embassy.dev/embassy-usb/[embassy-usb] implements a device-side USB stack. Implementations for common classes such as USB serial (CDC ACM) and USB HID are available, and a rich builder API allows building your own. -- cgit From 79cb62c9b4ba1d12b31072a9ecf7ce0b818cda8c Mon Sep 17 00:00:00 2001 From: Benjamin Ward Date: Mon, 1 Jan 2024 10:23:57 -0500 Subject: Expand LoRa crate notes per PR review --- docs/modules/ROOT/pages/index.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/pages/index.adoc b/docs/modules/ROOT/pages/index.adoc index 3cf032c45..e17adbbd7 100644 --- a/docs/modules/ROOT/pages/index.adoc +++ b/docs/modules/ROOT/pages/index.adoc @@ -41,7 +41,7 @@ The link:https://docs.embassy.dev/embassy-net/[embassy-net] network stack implem The link:https://github.com/embassy-rs/nrf-softdevice[nrf-softdevice] crate provides Bluetooth Low Energy 4.x and 5.x support for nRF52 microcontrollers. === LoRa -link:https://github.com/lora-rs/lora-rs[lora-rs] supports LoRa networking on a wide range of LoRa radios, fully integrated with a Rust link:https://github.com/ivajloip/rust-lorawan[LoRaWAN] implementation. +link:https://github.com/lora-rs/lora-rs[lora-rs] supports LoRa networking on a wide range of LoRa radios, fully integrated with a Rust LoRaWAN implementation. It provides four crates — lora-phy, lora-modulation, lorawan-encoding, and lorawan-device — and basic examples for various development boards. It has support for STM32WL wireless microcontrollers or Semtech SX127x transceivers, among others. === USB link:https://docs.embassy.dev/embassy-usb/[embassy-usb] implements a device-side USB stack. Implementations for common classes such as USB serial (CDC ACM) and USB HID are available, and a rich builder API allows building your own. -- cgit From 7dec3ccca4726ed42bf26dbd99d9f5d5dcf025b4 Mon Sep 17 00:00:00 2001 From: James Munns Date: Tue, 2 Jan 2024 18:44:41 +0100 Subject: [FAQ]: Link to Arena configuration docs --- docs/modules/ROOT/pages/faq.adoc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/pages/faq.adoc b/docs/modules/ROOT/pages/faq.adoc index 1fe9bde37..fd355827b 100644 --- a/docs/modules/ROOT/pages/faq.adoc +++ b/docs/modules/ROOT/pages/faq.adoc @@ -152,4 +152,10 @@ Note that the git revision should match any other embassy patches or git depende * When using `InterruptExecutor`: ** disable `executor-thread` ** make `main`` spawn everything, then enable link:https://docs.rs/cortex-m/latest/cortex_m/peripheral/struct.SCB.html#method.set_sleeponexit[SCB.SLEEPONEXIT] and `loop { cortex_m::asm::wfi() }` - ** *Note:* If you need 2 priority levels, using 2 interrupt executors is better than 1 thread executor + 1 interrupt executor. \ No newline at end of file + ** *Note:* If you need 2 priority levels, using 2 interrupt executors is better than 1 thread executor + 1 interrupt executor. + +== How do I set up the task arenas on stable? + +When you aren't using the `nightly` feature of `embassy-executor`, the executor uses a bump allocator, which may require configuration. + +Check out link:https://docs.embassy.dev/embassy-executor/git/cortex-m/index.html#task-arena[Task Arena Documentation] for more details. -- cgit From 781e33023e3755bddecba23fb3c2dab10e16ccc6 Mon Sep 17 00:00:00 2001 From: Vasil Nikolov Date: Wed, 10 Jan 2024 00:49:54 +0200 Subject: add draft doc page for peripheral sharing --- docs/modules/ROOT/nav.adoc | 1 + docs/modules/ROOT/pages/sharing_peripherals.adoc | 78 ++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 docs/modules/ROOT/pages/sharing_peripherals.adoc (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc index fabb80e31..b692c44e1 100644 --- a/docs/modules/ROOT/nav.adoc +++ b/docs/modules/ROOT/nav.adoc @@ -6,6 +6,7 @@ * xref:layer_by_layer.adoc[Bare metal to async] * xref:runtime.adoc[Executor] * xref:delaying_a_task.adoc[Delaying a Task] +* xref:sharing_peripherals.adoc[Sharing peripherals between tasks] * xref:hal.adoc[HAL] ** xref:nrf.adoc[nRF] ** xref:stm32.adoc[STM32] diff --git a/docs/modules/ROOT/pages/sharing_peripherals.adoc b/docs/modules/ROOT/pages/sharing_peripherals.adoc new file mode 100644 index 000000000..41f467942 --- /dev/null +++ b/docs/modules/ROOT/pages/sharing_peripherals.adoc @@ -0,0 +1,78 @@ += Sharing peripherals between tasks + +Often times, more than one task needs access to the same resource (pin, communication interface, etc.). The following example shows how to use the on-board LED on a Raspberry Pi Pico board by two tasks simultaneously. + +[,rust] +---- +use defmt::*; +use embassy_executor::Spawner; +use embassy_rp::gpio; +use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; +use embassy_sync::mutex::Mutex; +use embassy_time::{Duration, Ticker}; +use gpio::{AnyPin, Level, Output}; +use {defmt_rtt as _, panic_probe as _}; + +type LedType = Mutex>>; +static LED: LedType = Mutex::new(None); + +#[embassy_executor::main] +async fn main(spawner: Spawner) { + let p = embassy_rp::init(Default::default()); + // set the content of the global LED reference to the real LED pin + let led = Output::new(AnyPin::from(p.PIN_25), Level::High); + // inner scope is so that once the mutex is written to, the MutexGuard is dropped, thus the + // Mutex is released + { + *(LED.lock().await) = Some(led); + } + let dt = 100 * 1_000_000; + let k = 1.003; + + unwrap!(spawner.spawn(toggle(&LED, Duration::from_nanos(dt)))); + unwrap!(spawner.spawn(toggle_slightly_slower( + &LED, + Duration::from_nanos((dt as f64 * k) as u64) + ))); +} + +async fn toggle_led(led: &'static LedType, delay: Duration) { + let mut ticker = Ticker::every(delay); + loop { + { + let mut led_unlocked = led.lock().await; + if let Some(pin_ref) = led_unlocked.as_mut() { + pin_ref.toggle(); + } + } + ticker.next().await; + } +} +#[embassy_executor::task] +async fn toggle(led: &'static LedType, delay: Duration) { + toggle_led(led, delay).await +} + +#[embassy_executor::task] +async fn toggle_slightly_slower(led: &'static LedType, delay: Duration) { + toggle_led(led, delay).await +} +---- + +The structure facilitating access to the resource is the defined `LedType`. + +== Why so complicated + +Unwrapping the layers gives insight into why each one is needed. + +=== `Mutex` + +The mutex is there so if one task gets the resource first and begins modifying it, all other tasks wanting to write will have to wait (the `led.lock().await` will return immediately if no task has locked the mutex, and will block if it is accessed somewhere else). + +=== `Option` + +The `LED` variable needs to be defined outside the main task as references accepted by tasks need to be `'static`. However, if it is outside the main task, it cannot be initialised to point to any pin, as the pins themselves are not initialised. Thus, it is set to `None`. + +=== `Output` + +To indicate that the pin will be set to an Output. The `AnyPin` could have been `embassy_rp::peripherals::PIN_25`, however this option lets the `toggle_led` function be more generic. -- cgit From 495b8b739aaba3d1fe7e105559c830496fabb1d7 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Tue, 9 Jan 2024 23:58:26 +0100 Subject: Change GPIO inherent methods back to `&self`. With the embedded-hal rc3 update I changed them to require `&mut self`, but in retrospect I think `&self` is better, for extra flexibility. This PR reverts the changes from the rc3 update to inherent methods. --- docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs b/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs index 54b87662e..d0c9f4907 100644 --- a/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs +++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs @@ -9,7 +9,7 @@ use {defmt_rtt as _, panic_probe as _}; fn main() -> ! { let p = embassy_stm32::init(Default::default()); let mut led = Output::new(p.PB14, Level::High, Speed::VeryHigh); - let mut button = Input::new(p.PC13, Pull::Up); + let button = Input::new(p.PC13, Pull::Up); loop { if button.is_low() { -- cgit From ff5f5021fb4f469f72b3645760238ebe1c4d99af Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Wed, 10 Jan 2024 09:48:09 +0100 Subject: cleanup docs and add channel synchronization example --- docs/modules/ROOT/nav.adoc | 6 +- docs/modules/ROOT/pages/delaying_a_task.adoc | 28 -------- docs/modules/ROOT/pages/project_structure.adoc | 10 +-- docs/modules/ROOT/pages/sharing_peripherals.adoc | 86 ++++++++++++++++++------ docs/modules/ROOT/pages/time_keeping.adoc | 60 +++++++++++++++++ 5 files changed, 135 insertions(+), 55 deletions(-) delete mode 100644 docs/modules/ROOT/pages/delaying_a_task.adoc create mode 100644 docs/modules/ROOT/pages/time_keeping.adoc (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc index b692c44e1..44b0eddb9 100644 --- a/docs/modules/ROOT/nav.adoc +++ b/docs/modules/ROOT/nav.adoc @@ -3,11 +3,11 @@ ** xref:project_structure.adoc[Project Structure] ** xref:new_project.adoc[Starting a new Embassy project] ** xref:best_practices.adoc[Best Practices] -* xref:layer_by_layer.adoc[Bare metal to async] * xref:runtime.adoc[Executor] -* xref:delaying_a_task.adoc[Delaying a Task] -* xref:sharing_peripherals.adoc[Sharing peripherals between tasks] +* xref::time_keeping.adoc[Time-keeping] +* xref:sharing_peripherals.adoc[Sharing peripherals] * xref:hal.adoc[HAL] +** xref:layer_by_layer.adoc[Anatomy of an async HAL] ** xref:nrf.adoc[nRF] ** xref:stm32.adoc[STM32] * xref:bootloader.adoc[Bootloader] diff --git a/docs/modules/ROOT/pages/delaying_a_task.adoc b/docs/modules/ROOT/pages/delaying_a_task.adoc deleted file mode 100644 index 3171e3515..000000000 --- a/docs/modules/ROOT/pages/delaying_a_task.adoc +++ /dev/null @@ -1,28 +0,0 @@ -= Delaying a Task - -In an embedded program, delaying a task is one of the most common actions taken. In an event loop, delays will need to be inserted to ensure -that other tasks have a chance to run before the next iteration of the loop is called, if no other I/O is performed. Embassy provides an abstraction -to delay the current task for a specified interval of time. - -Timing is serviced by the `embassy::time::Timer` struct, which provides two timing methods. - -`Timer::at` creates a future that completes at the specified `Instant`, relative to the system boot time. -`Timer::after` creates a future that completes after the specified `Duration`, relative to when the future was created. - -An example of a delay is provided as follows: - -[,rust] ----- -use embassy::executor::{task, Executor}; -use embassy::time::{Duration, Timer}; - -#[task] -/// Task that ticks periodically -async fn tick_periodic() -> ! { - loop { - rprintln!("tick!"); - // async sleep primitive, suspends the task for 500ms. - Timer::after(Duration::from_millis(500)).await; - } -} ----- \ No newline at end of file diff --git a/docs/modules/ROOT/pages/project_structure.adoc b/docs/modules/ROOT/pages/project_structure.adoc index 3e6008ec4..61ffd05a6 100644 --- a/docs/modules/ROOT/pages/project_structure.adoc +++ b/docs/modules/ROOT/pages/project_structure.adoc @@ -18,7 +18,7 @@ my-project |- rust-toolchain.toml ---- -=== .cargo/config.toml +== .cargo/config.toml This directory/file describes what platform you're on, and configures link:https://github.com/probe-rs/probe-rs[probe-rs] to deploy to your device. @@ -36,17 +36,17 @@ target = "thumbv6m-none-eabi" # <-change for your platform DEFMT_LOG = "trace" # <- can change to info, warn, or error ---- -=== build.rs +== build.rs This is the build script for your project. It links defmt (what is defmt?) and the `memory.x` file if needed. This file is pretty specific for each chipset, just copy and paste from the corresponding link:https://github.com/embassy-rs/embassy/tree/main/examples[example]. -=== Cargo.toml +== Cargo.toml This is your manifest file, where you can configure all of the embassy components to use the features you need. TODO: someone should exhaustively describe every feature for every component! -=== memory.x +== memory.x This file outlines the flash/ram usage of your program. It is especially useful when using link:https://github.com/embassy-rs/nrf-softdevice[nrf-softdevice] on an nRF5x. @@ -63,7 +63,7 @@ MEMORY } ---- -=== rust-toolchain.toml +== rust-toolchain.toml This file configures the rust version and configuration to use. diff --git a/docs/modules/ROOT/pages/sharing_peripherals.adoc b/docs/modules/ROOT/pages/sharing_peripherals.adoc index 41f467942..fcba0e27b 100644 --- a/docs/modules/ROOT/pages/sharing_peripherals.adoc +++ b/docs/modules/ROOT/pages/sharing_peripherals.adoc @@ -1,6 +1,12 @@ = Sharing peripherals between tasks -Often times, more than one task needs access to the same resource (pin, communication interface, etc.). The following example shows how to use the on-board LED on a Raspberry Pi Pico board by two tasks simultaneously. +Often times, more than one task needs access to the same resource (pin, communication interface, etc.). Embassy provides many different synchronization primitives in the link:https://crates.io/crates/embassy-sync[embassy-sync] crate. + +The following examples shows different ways to use the on-board LED on a Raspberry Pi Pico board by two tasks simultaneously. + +== Sharing using a Mutex + +Using mutual exclusion is the simplest way to share a peripheral. [,rust] ---- @@ -29,13 +35,12 @@ async fn main(spawner: Spawner) { let dt = 100 * 1_000_000; let k = 1.003; - unwrap!(spawner.spawn(toggle(&LED, Duration::from_nanos(dt)))); - unwrap!(spawner.spawn(toggle_slightly_slower( - &LED, - Duration::from_nanos((dt as f64 * k) as u64) - ))); + unwrap!(spawner.spawn(toggle_led(&LED, Duration::from_nanos(dt)))); + unwrap!(spawner.spawn(toggle_led(&LED, Duration::from_nanos((dt as f64 * k) as u64)))); } +// A pool size of 2 means you can spawn two instances of this task. +#[embassy_executor::task(pool_size = 2)] async fn toggle_led(led: &'static LedType, delay: Duration) { let mut ticker = Ticker::every(delay); loop { @@ -48,31 +53,74 @@ async fn toggle_led(led: &'static LedType, delay: Duration) { ticker.next().await; } } -#[embassy_executor::task] -async fn toggle(led: &'static LedType, delay: Duration) { - toggle_led(led, delay).await -} - -#[embassy_executor::task] -async fn toggle_slightly_slower(led: &'static LedType, delay: Duration) { - toggle_led(led, delay).await -} ---- The structure facilitating access to the resource is the defined `LedType`. -== Why so complicated +=== Why so complicated Unwrapping the layers gives insight into why each one is needed. -=== `Mutex` +==== `Mutex` The mutex is there so if one task gets the resource first and begins modifying it, all other tasks wanting to write will have to wait (the `led.lock().await` will return immediately if no task has locked the mutex, and will block if it is accessed somewhere else). -=== `Option` +==== `Option` The `LED` variable needs to be defined outside the main task as references accepted by tasks need to be `'static`. However, if it is outside the main task, it cannot be initialised to point to any pin, as the pins themselves are not initialised. Thus, it is set to `None`. -=== `Output` +==== `Output` To indicate that the pin will be set to an Output. The `AnyPin` could have been `embassy_rp::peripherals::PIN_25`, however this option lets the `toggle_led` function be more generic. + +== Sharing using a Channel + +A channel is another way to ensure exclusive access to a resource. Using a channel is great in the cases where the access can happen at a later point in time, allowing you to enqueue operations and do other things. + +[,rust] +---- +use defmt::*; +use embassy_executor::Spawner; +use embassy_rp::gpio; +use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex; +use embassy_sync::channel::{Channel, Sender}; +use embassy_time::{Duration, Ticker}; +use gpio::{AnyPin, Level, Output}; +use {defmt_rtt as _, panic_probe as _}; + +enum LedState { + Toggle, +} +static CHANNEL: Channel = Channel::new(); + +#[embassy_executor::main] +async fn main(spawner: Spawner) { + let p = embassy_rp::init(Default::default()); + let mut led = Output::new(AnyPin::from(p.PIN_25), Level::High); + + let dt = 100 * 1_000_000; + let k = 1.003; + + unwrap!(spawner.spawn(toggle_led(CHANNEL.sender(), Duration::from_nanos(dt)))); + unwrap!(spawner.spawn(toggle_led(CHANNEL.sender(), Duration::from_nanos((dt as f64 * k) as u64)))); + + loop { + match CHANNEL.receive().await { + LedState::Toggle => led.toggle(), + } + } +} + +// A pool size of 2 means you can spawn two instances of this task. +#[embassy_executor::task(pool_size = 2)] +async fn toggle_led(control: Sender<'static, ThreadModeRawMutex, LedState, 64>, delay: Duration) { + let mut ticker = Ticker::every(delay); + loop { + control.send(LedState::Toggle).await; + ticker.next().await; + } +} +---- + +This example replaces the Mutex with a Channel, and uses another task (the main loop) to drive the LED. The advantage of this approach is that only a single task references the peripheral, separating concerns. However, using a Mutex has a lower overhead and might be necessary if you need to ensure +that the operation is ecompleted before continuing to do other work in your task. diff --git a/docs/modules/ROOT/pages/time_keeping.adoc b/docs/modules/ROOT/pages/time_keeping.adoc new file mode 100644 index 000000000..5068216ed --- /dev/null +++ b/docs/modules/ROOT/pages/time_keeping.adoc @@ -0,0 +1,60 @@ += Time-keeping + +In an embedded program, delaying a task is one of the most common actions taken. In an event loop, delays will need to be inserted to ensure +that other tasks have a chance to run before the next iteration of the loop is called, if no other I/O is performed. Embassy provides abstractions +to delay the current task for a specified interval of time. + +The interface for time-keeping in Embassy is handled by the link:https://crates.io/crates/embassy-time[embassy-time] crate. The types can be used with the internal +timer queue in link:https://crates.io/crates/embassy-executor[embassy-executor] or a custom timer queue implementation. + +== Timer + +The `embassy::time::Timer` type provides two timing methods. + +`Timer::at` creates a future that completes at the specified `Instant`, relative to the system boot time. +`Timer::after` creates a future that completes after the specified `Duration`, relative to when the future was created. + +An example of a delay is provided as follows: + +[,rust] +---- +use embassy::executor::{task, Executor}; +use embassy::time::{Duration, Timer}; + +#[task] +/// Task that ticks periodically +async fn tick_periodic() -> ! { + loop { + rprintln!("tick!"); + // async sleep primitive, suspends the task for 500ms. + Timer::after(Duration::from_millis(500)).await; + } +} +---- + +== Delay + +The `embassy::time::Delay` type provides an implementation of the link:https://docs.rs/embedded-hal/1.0.0/embedded_hal/delay/index.html[embedded-hal] and +link:https://docs.rs/embedded-hal-async/latest/embedded_hal_async/delay/index.html[embedded-hal-async] traits. This can be used for drivers +that expect a generic delay implementation to be provided. + +An example of how this can be used: + +[,rust] +---- +use embassy::executor::{task, Executor}; + +#[task] +/// Task that ticks periodically +async fn tick_periodic() -> ! { + loop { + rprintln!("tick!"); + // async sleep primitive, suspends the task for 500ms. + generic_delay(embassy::time::Delay).await + } +} + +async fn generic_delay(delay: D) { + delay.delay_ms(500).await; +} +---- -- cgit From 22197320ff5dcef6cdc692a4c556ea9eae270074 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Thu, 11 Jan 2024 22:57:29 +0100 Subject: bump embassy-time 0.3, embassy-executor 0.5, embassy-net 0.4. --- docs/modules/ROOT/examples/basic/Cargo.toml | 4 ++-- docs/modules/ROOT/examples/layer-by-layer/blinky-async/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/examples/basic/Cargo.toml b/docs/modules/ROOT/examples/basic/Cargo.toml index 8f6e05fae..2c282145d 100644 --- a/docs/modules/ROOT/examples/basic/Cargo.toml +++ b/docs/modules/ROOT/examples/basic/Cargo.toml @@ -6,8 +6,8 @@ version = "0.1.0" license = "MIT OR Apache-2.0" [dependencies] -embassy-executor = { version = "0.4.0", path = "../../../../../embassy-executor", features = ["defmt", "integrated-timers", "arch-cortex-m", "executor-thread"] } -embassy-time = { version = "0.2.0", path = "../../../../../embassy-time", features = ["defmt"] } +embassy-executor = { version = "0.5.0", path = "../../../../../embassy-executor", features = ["defmt", "integrated-timers", "arch-cortex-m", "executor-thread"] } +embassy-time = { version = "0.3.0", path = "../../../../../embassy-time", features = ["defmt"] } embassy-nrf = { version = "0.1.0", path = "../../../../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote"] } defmt = "0.3" 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 2d47dccf4..64f7e8403 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 @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" cortex-m = "0.7" cortex-m-rt = "0.7" embassy-stm32 = { version = "0.1.0", features = ["stm32l475vg", "memory-x", "exti"] } -embassy-executor = { version = "0.4.0", features = ["arch-cortex-m", "executor-thread"] } +embassy-executor = { version = "0.5.0", features = ["arch-cortex-m", "executor-thread"] } defmt = "0.3.0" defmt-rtt = "0.3.0" -- cgit From d2d9175a1dce7c52173dfac74711287dc799e81b Mon Sep 17 00:00:00 2001 From: Barnaby Walters Date: Sat, 13 Jan 2024 02:14:56 +0100 Subject: Added manual ISR FAQ --- docs/modules/ROOT/pages/faq.adoc | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/pages/faq.adoc b/docs/modules/ROOT/pages/faq.adoc index fd355827b..b33623053 100644 --- a/docs/modules/ROOT/pages/faq.adoc +++ b/docs/modules/ROOT/pages/faq.adoc @@ -159,3 +159,7 @@ Note that the git revision should match any other embassy patches or git depende When you aren't using the `nightly` feature of `embassy-executor`, the executor uses a bump allocator, which may require configuration. Check out link:https://docs.embassy.dev/embassy-executor/git/cortex-m/index.html#task-arena[Task Arena Documentation] for more details. + +== Can I use manual ISRs alongside Embassy? + +Yes! This can be useful if you need to respond to an event as fast as possible, and the latency caused by the usual “ISR, wake, return from ISR, context switch to woken task” flow is too much for your application. Simply define a `#[interrupt] fn INTERRUPT_NAME() {}` handler as you would link:https://docs.rust-embedded.org/book/start/interrupts.html[in any other embedded rust project]. \ No newline at end of file -- cgit From b825f76c285cc7dae518f67506f0cc0fdc6d540a Mon Sep 17 00:00:00 2001 From: Adin Ackerman Date: Tue, 16 Jan 2024 20:00:39 -0800 Subject: add extra info to stable arena usage --- docs/modules/ROOT/pages/faq.adoc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/pages/faq.adoc b/docs/modules/ROOT/pages/faq.adoc index b33623053..147f119b0 100644 --- a/docs/modules/ROOT/pages/faq.adoc +++ b/docs/modules/ROOT/pages/faq.adoc @@ -158,8 +158,25 @@ Note that the git revision should match any other embassy patches or git depende When you aren't using the `nightly` feature of `embassy-executor`, the executor uses a bump allocator, which may require configuration. +Something like this error will occur at **compile time** if the task arena is *too large* for the target's RAM: + +[source,plain] +---- +rust-lld: error: section '.bss' will not fit in region 'RAM': overflowed by _ bytes +rust-lld: error: section '.uninit' will not fit in region 'RAM': overflowed by _ bytes +---- + +And this message will appear at **runtime** if the task arena is *too small* for the tasks running: + +[source,plain] +---- +ERROR panicked at 'embassy-executor: task arena is full. You must increase the arena size, see the documentation for details: https://docs.embassy.dev/embassy-executor/' +---- + +NOTE: If all tasks are spawned at startup, this panic will occur immediately. + Check out link:https://docs.embassy.dev/embassy-executor/git/cortex-m/index.html#task-arena[Task Arena Documentation] for more details. == Can I use manual ISRs alongside Embassy? -Yes! This can be useful if you need to respond to an event as fast as possible, and the latency caused by the usual “ISR, wake, return from ISR, context switch to woken task” flow is too much for your application. Simply define a `#[interrupt] fn INTERRUPT_NAME() {}` handler as you would link:https://docs.rust-embedded.org/book/start/interrupts.html[in any other embedded rust project]. \ No newline at end of file +Yes! This can be useful if you need to respond to an event as fast as possible, and the latency caused by the usual “ISR, wake, return from ISR, context switch to woken task” flow is too much for your application. Simply define a `#[interrupt] fn INTERRUPT_NAME() {}` handler as you would link:https://docs.rust-embedded.org/book/start/interrupts.html[in any other embedded rust project]. -- cgit From 3387ee7238f1c9c4eeccb732ba543cbe38ab7ccd Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 22 Jan 2024 20:12:36 +0100 Subject: stm32/gpio: remove generics. --- .../ROOT/examples/layer-by-layer/blinky-async/src/main.rs | 4 ++-- .../ROOT/examples/layer-by-layer/blinky-irq/src/main.rs | 13 ++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs b/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs index e6753be28..004602816 100644 --- a/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs +++ b/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs @@ -3,14 +3,14 @@ use embassy_executor::Spawner; use embassy_stm32::exti::ExtiInput; -use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; +use embassy_stm32::gpio::{Level, Output, Pull, Speed}; use {defmt_rtt as _, panic_probe as _}; #[embassy_executor::main] async fn main(_spawner: Spawner) { let p = embassy_stm32::init(Default::default()); let mut led = Output::new(p.PB14, Level::Low, Speed::VeryHigh); - let mut button = ExtiInput::new(Input::new(p.PC13, Pull::Up), p.EXTI13); + let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Up); loop { button.wait_for_any_edge().await; 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 aecba0755..743c9d99b 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 @@ -6,13 +6,12 @@ use core::cell::RefCell; use cortex_m::interrupt::Mutex; use cortex_m::peripheral::NVIC; use cortex_m_rt::entry; -use embassy_stm32::gpio::{Input, Level, Output, Pin, Pull, Speed}; -use embassy_stm32::peripherals::{PB14, PC13}; +use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed}; use embassy_stm32::{interrupt, pac}; use {defmt_rtt as _, panic_probe as _}; -static BUTTON: Mutex>>> = Mutex::new(RefCell::new(None)); -static LED: Mutex>>> = Mutex::new(RefCell::new(None)); +static BUTTON: Mutex>>> = Mutex::new(RefCell::new(None)); +static LED: Mutex>>> = Mutex::new(RefCell::new(None)); #[entry] fn main() -> ! { @@ -62,14 +61,14 @@ fn EXTI15_10() { const PORT: u8 = 2; const PIN: usize = 13; -fn check_interrupt(_pin: &mut Input<'static, P>) -> bool { +fn check_interrupt(_pin: &mut Input<'static>) -> bool { let exti = pac::EXTI; let pin = PIN; let lines = exti.pr(0).read(); lines.line(pin) } -fn clear_interrupt(_pin: &mut Input<'static, P>) { +fn clear_interrupt(_pin: &mut Input<'static>) { let exti = pac::EXTI; let pin = PIN; let mut lines = exti.pr(0).read(); @@ -77,7 +76,7 @@ fn clear_interrupt(_pin: &mut Input<'static, P>) { exti.pr(0).write_value(lines); } -fn enable_interrupt(_pin: &mut Input<'static, P>) { +fn enable_interrupt(_pin: &mut Input<'static>) { cortex_m::interrupt::free(|_| { let rcc = pac::RCC; rcc.apb2enr().modify(|w| w.set_syscfgen(true)); -- cgit From 2bc5e9523d4373002487614ecfef1e3f0858fd66 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 22 Jan 2024 21:19:18 +0100 Subject: nrf/gpio: remove generics. --- docs/modules/ROOT/examples/basic/src/main.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/examples/basic/src/main.rs b/docs/modules/ROOT/examples/basic/src/main.rs index 2a4ee5968..4412712c8 100644 --- a/docs/modules/ROOT/examples/basic/src/main.rs +++ b/docs/modules/ROOT/examples/basic/src/main.rs @@ -4,12 +4,11 @@ use defmt::*; use embassy_executor::Spawner; use embassy_nrf::gpio::{Level, Output, OutputDrive}; -use embassy_nrf::peripherals::P0_13; use embassy_time::{Duration, Timer}; use {defmt_rtt as _, panic_probe as _}; // global logger #[embassy_executor::task] -async fn blinker(mut led: Output<'static, P0_13>, interval: Duration) { +async fn blinker(mut led: Output<'static>, interval: Duration) { loop { led.set_high(); Timer::after(interval).await; -- cgit From 40e9fc36dc3af75a9625413504d4e90a0d5f35d9 Mon Sep 17 00:00:00 2001 From: James Munns Date: Tue, 23 Jan 2024 12:06:28 +0100 Subject: Update faq.adoc Don't suggest people disable debuginfo, and explain why --- docs/modules/ROOT/pages/faq.adoc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/pages/faq.adoc b/docs/modules/ROOT/pages/faq.adoc index 147f119b0..bf061d978 100644 --- a/docs/modules/ROOT/pages/faq.adoc +++ b/docs/modules/ROOT/pages/faq.adoc @@ -44,11 +44,12 @@ The first step to managing your binary size is to set up your link:https://doc.r [source,toml] ---- [profile.release] -debug = false lto = true opt-level = "s" incremental = false codegen-units = 1 +# note: debug = true is okay - debuginfo isn't flashed to the device! +debug = true ---- All of these flags are elaborated on in the Rust Book page linked above. -- cgit From 3c159205a78cb2cc72e3dfeec1eff80d7b95846d Mon Sep 17 00:00:00 2001 From: Shane Snover Date: Thu, 25 Jan 2024 22:30:42 -0700 Subject: Fix the backticks on the getting started page --- docs/modules/ROOT/pages/getting_started.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/pages/getting_started.adoc b/docs/modules/ROOT/pages/getting_started.adoc index ab819ac2a..24bde1c1f 100644 --- a/docs/modules/ROOT/pages/getting_started.adoc +++ b/docs/modules/ROOT/pages/getting_started.adoc @@ -88,7 +88,7 @@ NOTE: How does the `cargo run` command know how to connect to our board and prog If you hare having issues when running `cargo run --release`, please check the following: -* You are specifying the correct `--chip on the command line``, OR +* You are specifying the correct `--chip` on the command line, OR * You have set `.cargo/config.toml`'s run line to the correct chip, AND * You have changed `examples/Cargo.toml`'s HAL (e.g. embassy-stm32) dependency's feature to use the correct chip (replace the existing stm32xxxx feature) -- cgit From f38807433882374fe4ccf3510070abb42639c1cb Mon Sep 17 00:00:00 2001 From: James Munns Date: Tue, 30 Jan 2024 10:34:09 +0100 Subject: Add some comments from chat --- docs/modules/ROOT/pages/faq.adoc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/pages/faq.adoc b/docs/modules/ROOT/pages/faq.adoc index bf061d978..254c0aa97 100644 --- a/docs/modules/ROOT/pages/faq.adoc +++ b/docs/modules/ROOT/pages/faq.adoc @@ -181,3 +181,21 @@ Check out link:https://docs.embassy.dev/embassy-executor/git/cortex-m/index.html == Can I use manual ISRs alongside Embassy? Yes! This can be useful if you need to respond to an event as fast as possible, and the latency caused by the usual “ISR, wake, return from ISR, context switch to woken task” flow is too much for your application. Simply define a `#[interrupt] fn INTERRUPT_NAME() {}` handler as you would link:https://docs.rust-embedded.org/book/start/interrupts.html[in any other embedded rust project]. + +== How can I measure resource usage (CPU, RAM, etc.)? + +=== For CPU Usage: + +There are a couple techniques that have been documented, generally you want to measure how long you are spending in the idle or low priority loop. + +We need to document specifically how to do this in embassy, but link:https://blog.japaric.io/cpu-monitor/[this older post] describes the general process. + +If you end up doing this, please update this section with more specific examples! + +=== For Static Memory Usage + +Tools like `cargo size` and `cargo nm` can tell you the size of any globals or other static usage. Specifically you will want to see the size of the `.data` and `.bss` sections, which together make up the total global/static memory usage. + +=== For Max Stack Usage + +Check out link:https://github.com/Dirbaio/cargo-call-stack/[`cargo-call-stack`] for statically calculating worst-case stack usage. There are some caveats and inaccuracies possible with this, but this is a good way to get the general idea. -- cgit From 5e7876c80047718457923bcd8f1e9859e6483b57 Mon Sep 17 00:00:00 2001 From: James Munns Date: Tue, 30 Jan 2024 12:41:46 +0100 Subject: Update docs/modules/ROOT/pages/faq.adoc --- docs/modules/ROOT/pages/faq.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/pages/faq.adoc b/docs/modules/ROOT/pages/faq.adoc index 254c0aa97..05ff7c598 100644 --- a/docs/modules/ROOT/pages/faq.adoc +++ b/docs/modules/ROOT/pages/faq.adoc @@ -198,4 +198,4 @@ Tools like `cargo size` and `cargo nm` can tell you the size of any globals or o === For Max Stack Usage -Check out link:https://github.com/Dirbaio/cargo-call-stack/[`cargo-call-stack`] for statically calculating worst-case stack usage. There are some caveats and inaccuracies possible with this, but this is a good way to get the general idea. +Check out link:https://github.com/Dirbaio/cargo-call-stack/[`cargo-call-stack`] for statically calculating worst-case stack usage. There are some caveats and inaccuracies possible with this, but this is a good way to get the general idea. See link:https://github.com/dirbaio/cargo-call-stack#known-limitations[the README] for more details. -- cgit From 4650a3566161ece4a743948129112402b9bb6e48 Mon Sep 17 00:00:00 2001 From: Matous Hybl Date: Sat, 3 Feb 2024 09:41:14 +0100 Subject: docs: Embassy in the wild - add air quality monitoring system --- docs/modules/ROOT/pages/embassy_in_the_wild.adoc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/pages/embassy_in_the_wild.adoc b/docs/modules/ROOT/pages/embassy_in_the_wild.adoc index a1c31bfc7..dfe9fd6e3 100644 --- a/docs/modules/ROOT/pages/embassy_in_the_wild.adoc +++ b/docs/modules/ROOT/pages/embassy_in_the_wild.adoc @@ -7,3 +7,5 @@ Here are known examples of real-world projects which make use of Embassy. Feel f * link:https://github.com/card-io-ecg/card-io-fw[Card/IO firmware] - firmware for an open source ECG device ** Targets the ESP32-S3 or ESP32-C6 MCU * The link:https://github.com/lora-rs/lora-rs[lora-rs] project includes link:https://github.com/lora-rs/lora-rs/tree/main/examples/stm32l0/src/bin[various standalone examples] for NRF52840, RP2040, STM32L0 and STM32WL +** link:https://github.com/matoushybl/air-force-one[Air force one: A simple air quality monitoring system] +* Targets nRF52 and uses nrf-softdevice -- cgit From 7817c8b17c2a65e799fb3f64e5e3a703ad4ace33 Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Mon, 5 Feb 2024 09:10:53 +0100 Subject: docs: fix bullet point indentation --- docs/modules/ROOT/pages/embassy_in_the_wild.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/pages/embassy_in_the_wild.adoc b/docs/modules/ROOT/pages/embassy_in_the_wild.adoc index dfe9fd6e3..85ad7f4a2 100644 --- a/docs/modules/ROOT/pages/embassy_in_the_wild.adoc +++ b/docs/modules/ROOT/pages/embassy_in_the_wild.adoc @@ -8,4 +8,4 @@ Here are known examples of real-world projects which make use of Embassy. Feel f ** Targets the ESP32-S3 or ESP32-C6 MCU * The link:https://github.com/lora-rs/lora-rs[lora-rs] project includes link:https://github.com/lora-rs/lora-rs/tree/main/examples/stm32l0/src/bin[various standalone examples] for NRF52840, RP2040, STM32L0 and STM32WL ** link:https://github.com/matoushybl/air-force-one[Air force one: A simple air quality monitoring system] -* Targets nRF52 and uses nrf-softdevice +*** Targets nRF52 and uses nrf-softdevice -- cgit From bb743420be5f7347cab7e2cc19a427b93e90b1e8 Mon Sep 17 00:00:00 2001 From: Priit Laes Date: Fri, 9 Feb 2024 10:14:34 +0200 Subject: faq: Fix typo --- docs/modules/ROOT/pages/best_practices.adoc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/pages/best_practices.adoc b/docs/modules/ROOT/pages/best_practices.adoc index 1e02f9ba9..bfcedec06 100644 --- a/docs/modules/ROOT/pages/best_practices.adoc +++ b/docs/modules/ROOT/pages/best_practices.adoc @@ -3,8 +3,10 @@ Over time, a couple of best practices have emerged. The following list should serve as a guideline for developers writing embedded software in _Rust_, especially in the context of the _Embassy_ framework. == Passing Buffers by Reference -It may be tempting to pass arrays or wrappers, like link:https://docs.rs/heapless/latest/heapless/[`heapless::Vec`], to a function or return one just like you would with a `std::Vec`. However, in most embedded applications you don't want to spend ressources on an allocator and end up placing buffers on the stack. -This, however, can easily blow up your stack if you are not careful. +It may be tempting to pass arrays or wrappers, like link:https://docs.rs/heapless/latest/heapless/[`heapless::Vec`], +to a function or return one just like you would with a `std::Vec`. However, in most embedded applications you don't +want to spend resources on an allocator and end up placing buffers on the stack. This, however, can easily blow up +your stack if you are not careful. Consider the following example: [,rust] -- cgit From 6e2d54c40bfdb07b6bb28f5fd8009846d0695f67 Mon Sep 17 00:00:00 2001 From: Priit Laes Date: Fri, 9 Feb 2024 10:14:55 +0200 Subject: faq: Nightly is not required anymore --- docs/modules/ROOT/pages/faq.adoc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/pages/faq.adoc b/docs/modules/ROOT/pages/faq.adoc index 05ff7c598..c8695a01a 100644 --- a/docs/modules/ROOT/pages/faq.adoc +++ b/docs/modules/ROOT/pages/faq.adoc @@ -29,11 +29,10 @@ If you see an error like this: You are likely missing some features of the `embassy-executor` crate. -For Cortex-M targets, consider making sure that ALL of the following features are active in your `Cargo.toml` for the `embassy-executor` crate: +For Cortex-M targets, check whether ALL of the following features are enabled in your `Cargo.toml` for the `embassy-executor` crate: * `arch-cortex-m` * `executor-thread` -* `nightly` For ESP32, consider using the executors and `#[main]` macro provided by your appropriate link:https://crates.io/crates/esp-hal-common[HAL crate]. -- cgit From cbdc49ef8d92606f917d1df0d88e4baef7bb23df Mon Sep 17 00:00:00 2001 From: Priit Laes Date: Fri, 9 Feb 2024 10:15:15 +0200 Subject: faq: embassy-time was split into three packages, update faq accordingly I ran into this issue when I had to pull in embassy-nrf from git, though cargo didn't complain about conflicting embassy-time links. --- docs/modules/ROOT/pages/faq.adoc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/pages/faq.adoc b/docs/modules/ROOT/pages/faq.adoc index c8695a01a..7fb81e2ca 100644 --- a/docs/modules/ROOT/pages/faq.adoc +++ b/docs/modules/ROOT/pages/faq.adoc @@ -124,15 +124,18 @@ You have multiple versions of the same crate in your dependency tree. This means embassy crates are coming from crates.io, and some from git, each of them pulling in a different set of dependencies. -To resolve this issue, make sure to only use a single source for all your embassy crates! To do this, -you should patch your dependencies to use git sources using `[patch.crates.io]` and maybe `[patch.'https://github.com/embassy-rs/embassy.git']`. +To resolve this issue, make sure to only use a single source for all your embassy crates! +To do this, you should patch your dependencies to use git sources using `[patch.crates.io]` +and maybe `[patch.'https://github.com/embassy-rs/embassy.git']`. Example: [source,toml] ---- [patch.crates-io] -embassy-time = { git = "https://github.com/embassy-rs/embassy.git", rev = "e5fdd35" } +embassy-time-queue-driver = { git = "https://github.com/embassy-rs/embassy.git", rev = "e5fdd35" } +embassy-time-driver = { git = "https://github.com/embassy-rs/embassy.git", rev = "e5fdd35" } +# embassy-time = { git = "https://github.com/embassy-rs/embassy.git", rev = "e5fdd35" } ---- Note that the git revision should match any other embassy patches or git dependencies that you are using! -- cgit From f9af0096bd6cd74853b8e5406d6135de2f5c8274 Mon Sep 17 00:00:00 2001 From: Ralf Date: Mon, 12 Feb 2024 19:29:29 +0100 Subject: FAQ add hint to embassy-time linker error to include HAL in linking --- docs/modules/ROOT/pages/faq.adoc | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/pages/faq.adoc b/docs/modules/ROOT/pages/faq.adoc index 7fb81e2ca..d55e63130 100644 --- a/docs/modules/ROOT/pages/faq.adoc +++ b/docs/modules/ROOT/pages/faq.adoc @@ -118,6 +118,13 @@ features = [ ] ---- +If you are in the early project setup phase and not using anything from the HAL, make sure the HAL is passed to the linker by adding this line to your source: + +[source,rust] +---- +use embassy_stm32 as _; +---- + == Error: `Only one package in the dependency graph may specify the same links value.` You have multiple versions of the same crate in your dependency tree. This means that some of your -- cgit From 4a0b1cbadb252f186ef41c465936bb3ac4dfcf3f Mon Sep 17 00:00:00 2001 From: James Munns Date: Tue, 13 Feb 2024 15:23:50 +0100 Subject: Update docs/modules/ROOT/pages/faq.adoc --- docs/modules/ROOT/pages/faq.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/pages/faq.adoc b/docs/modules/ROOT/pages/faq.adoc index d55e63130..6b5e6d009 100644 --- a/docs/modules/ROOT/pages/faq.adoc +++ b/docs/modules/ROOT/pages/faq.adoc @@ -118,7 +118,7 @@ features = [ ] ---- -If you are in the early project setup phase and not using anything from the HAL, make sure the HAL is passed to the linker by adding this line to your source: +If you are in the early project setup phase and not using anything from the HAL, make sure the HAL is explicitly used to prevent the linker removing it as dead code by adding this line to your source: [source,rust] ---- -- cgit From 990b44566ce1393a4a553a65d5a6c412cb656805 Mon Sep 17 00:00:00 2001 From: Barnaby Walters Date: Wed, 28 Feb 2024 15:11:30 +0100 Subject: [docs] Added some failure modes to watch out for * Linked to probe.rs website rather than the crates.io page * Fixed some formatting errors (>:( grrr asciidoc) * Added cargo add probe-rs failure mode * Added pico-w vs pico blinky failure mode --- docs/modules/ROOT/pages/getting_started.adoc | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/pages/getting_started.adoc b/docs/modules/ROOT/pages/getting_started.adoc index 24bde1c1f..be2b868eb 100644 --- a/docs/modules/ROOT/pages/getting_started.adoc +++ b/docs/modules/ROOT/pages/getting_started.adoc @@ -3,7 +3,7 @@ So you want to try Embassy, great! To get started, there are a few tools you need to install: * link:https://rustup.rs/[rustup] - the Rust toolchain is needed to compile Rust code. -* link:https://crates.io/crates/probe-rs[probe-rs] - to flash the firmware on your device. If you already have other tools like `OpenOCD` setup, you can use that as well. +* link:https://probe.rs/[probe-rs] - to flash the firmware on your device. If you already have other tools like `OpenOCD` setup, you can use that as well. If you don't have any supported board, don't worry: you can also run embassy on your PC using the `std` examples. @@ -82,19 +82,19 @@ If everything worked correctly, you should see a blinking LED on your board, and └─ blinky::__embassy_main::task::{generator#0} @ src/bin/blinky.rs:27 ---- -NOTE: How does the `cargo run` command know how to connect to our board and program it? In each `examples` folder, there’s a `.cargo/config.toml` file which tells cargo to use link:https://probe.rs/[probe-rs] as the runner for ARM binaries in that folder. probe-rs handles communication with the debug probe and MCU. In order for this to work, probe-rs needs to know which chip it’s programming, so you’ll have to edit this file if you want to run examples on other chips. +NOTE: How does the `+cargo run+` command know how to connect to our board and program it? In each `examples` folder, there’s a `.cargo/config.toml` file which tells cargo to use link:https://probe.rs/[probe-rs] as the runner for ARM binaries in that folder. probe-rs handles communication with the debug probe and MCU. In order for this to work, probe-rs needs to know which chip it’s programming, so you’ll have to edit this file if you want to run examples on other chips. === It didn’t work! -If you hare having issues when running `cargo run --release`, please check the following: +If you hare having issues when running `+cargo run --release+`, please check the following: -* You are specifying the correct `--chip` on the command line, OR -* You have set `.cargo/config.toml`'s run line to the correct chip, AND -* You have changed `examples/Cargo.toml`'s HAL (e.g. embassy-stm32) dependency's feature to use the correct chip (replace the existing stm32xxxx feature) +* You are specifying the correct `+--chip+` on the command line, OR +* You have set `+.cargo/config.toml+`’s run line to the correct chip, AND +* You have changed `+examples/Cargo.toml+`’s HAL (e.g. embassy-stm32) dependency's feature to use the correct chip (replace the existing stm32xxxx feature) At this point the project should run. If you do not see a blinky LED for blinky, for example, be sure to check the code is toggling your board's LED pin. -If you are trying to run an example with `cargo run --release` and you see the following output: +If you are trying to run an example with `+cargo run --release+` and you see the following output: [source] ---- 0.000000 INFO Hello World! @@ -115,6 +115,20 @@ To get rid of the frame-index error add the following to your `Cargo.toml`: debug = 2 ---- +If you’re get an extremely long error message containing something like the following: + +[source] +---- +error[E0463]: can't find crate for `std` + | + = note: the `thumbv6m-none-eabi` target may not support the standard library + = note: `std` is required by `stable_deref_trait` because it does not declare `#![no_std]` +---- + +Make sure that you didn’t accidentally run `+cargo add probe-rs+` (which adds it as a dependency) instead of link:https://probe.rs/docs/getting-started/installation/[correctly installing probe-rs]. + +If you’re using a raspberry pi pico-w, make sure you’re running `+cargo run --bin wifi_blinky --release+` rather than the regular blinky. The pico-w’s on-board LED is connected to the WiFi chip, which needs to be initialized before the LED can be blinked. + If you’re still having problems, check the link:https://embassy.dev/book/dev/faq.html[FAQ], or ask for help in the link:https://matrix.to/#/#embassy-rs:matrix.org[Embassy Chat Room]. == What's next? -- cgit From 2787164ea9ba30f806d6c38443d2eca2984b1e62 Mon Sep 17 00:00:00 2001 From: Barnaby Walters Date: Wed, 28 Feb 2024 15:15:43 +0100 Subject: grammar fix --- docs/modules/ROOT/pages/getting_started.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/pages/getting_started.adoc b/docs/modules/ROOT/pages/getting_started.adoc index be2b868eb..e8bc84255 100644 --- a/docs/modules/ROOT/pages/getting_started.adoc +++ b/docs/modules/ROOT/pages/getting_started.adoc @@ -115,7 +115,7 @@ To get rid of the frame-index error add the following to your `Cargo.toml`: debug = 2 ---- -If you’re get an extremely long error message containing something like the following: +If you’re getting an extremely long error message containing something like the following: [source] ---- -- cgit From d07a0148d759fa09ba1ee8dc4810bb4edd8bda49 Mon Sep 17 00:00:00 2001 From: Barnaby Walters Date: Wed, 28 Feb 2024 15:48:37 +0100 Subject: Documented rp2040 probe-rs info bug, linked to new_project page --- docs/modules/ROOT/pages/getting_started.adoc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/pages/getting_started.adoc b/docs/modules/ROOT/pages/getting_started.adoc index e8bc84255..73cb5530d 100644 --- a/docs/modules/ROOT/pages/getting_started.adoc +++ b/docs/modules/ROOT/pages/getting_started.adoc @@ -129,6 +129,8 @@ Make sure that you didn’t accidentally run `+cargo add probe-rs+` (which adds If you’re using a raspberry pi pico-w, make sure you’re running `+cargo run --bin wifi_blinky --release+` rather than the regular blinky. The pico-w’s on-board LED is connected to the WiFi chip, which needs to be initialized before the LED can be blinked. +If you’re using an rp2040 debug probe (e.g. the pico probe) and are having issues after running `probe-rs info`, unplug and reconnect the probe, letting it power cycle. Running `probe-rs info` is link:https://github.com/probe-rs/probe-rs/issues/1849[known to put the pico probe into an unusable state]. + If you’re still having problems, check the link:https://embassy.dev/book/dev/faq.html[FAQ], or ask for help in the link:https://matrix.to/#/#embassy-rs:matrix.org[Embassy Chat Room]. == What's next? @@ -138,3 +140,4 @@ Congratulations, you have your first Embassy application running! Here are some * Read more about the xref:runtime.adoc[executor]. * Read more about the xref:hal.adoc[HAL]. * Start xref:basic_application.adoc[writing your application]. +* Learn how to xref:new_project.adoc[start a new embassy project by adapting an example]. -- cgit From e954d1716a229bae94cd4739d1349a487bdaa8ae Mon Sep 17 00:00:00 2001 From: Andreas Schmidt Date: Thu, 29 Feb 2024 20:27:35 +0100 Subject: docs: update basic example references in basic_application.adoc --- docs/modules/ROOT/pages/basic_application.adoc | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/pages/basic_application.adoc b/docs/modules/ROOT/pages/basic_application.adoc index 95792d5a0..02b8981c9 100644 --- a/docs/modules/ROOT/pages/basic_application.adoc +++ b/docs/modules/ROOT/pages/basic_application.adoc @@ -17,15 +17,6 @@ The first thing you’ll notice are two attributes at the top of the file. These include::example$basic/src/main.rs[lines="1..2"] ---- -=== Rust Nightly - -The next declaration is a Rust Unstable feature, which means that Embassy requires Rust Nightly: - -[source,rust] ----- -include::example$basic/src/main.rs[lines="3"] ----- - === Dealing with errors Then, what follows are some declarations on how to deal with panics and faults. During development, a good practice is to rely on `defmt-rtt` and `panic-probe` to print diagnostics to the terminal: @@ -41,7 +32,7 @@ After a bit of import declaration, the tasks run by the application should be de [source,rust] ---- -include::example$basic/src/main.rs[lines="12..20"] +include::example$basic/src/main.rs[lines="10..18"] ---- An embassy task must be declared `async`, and may NOT take generic arguments. In this case, we are handed the LED that should be blinked and the interval of the blinking. @@ -56,7 +47,7 @@ We then initialize the HAL with a default config, which gives us a `Peripherals` [source,rust] ---- -include::example$basic/src/main.rs[lines="22..-1"] +include::example$basic/src/main.rs[lines="20..-1"] ---- What happens when the `blinker` task has been spawned and main returns? Well, the main entry point is actually just like any other task, except that you can only have one and it takes some specific type arguments. The magic lies within the `#[embassy_executor::main]` macro. The macro does the following: -- cgit From 4c0d63ce6188a340bd75388c3e772ba5d89ca8d4 Mon Sep 17 00:00:00 2001 From: Andreas Schmidt Date: Fri, 1 Mar 2024 10:13:59 +0100 Subject: docs: update broken reference in basic_application.adoc --- docs/modules/ROOT/pages/basic_application.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/modules/ROOT') diff --git a/docs/modules/ROOT/pages/basic_application.adoc b/docs/modules/ROOT/pages/basic_application.adoc index 02b8981c9..d5aad806d 100644 --- a/docs/modules/ROOT/pages/basic_application.adoc +++ b/docs/modules/ROOT/pages/basic_application.adoc @@ -23,7 +23,7 @@ Then, what follows are some declarations on how to deal with panics and faults. [source,rust] ---- -include::example$basic/src/main.rs[lines="10"] +include::example$basic/src/main.rs[lines="8"] ---- === Task declaration -- cgit