aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/Makefile8
-rw-r--r--docs/README.md29
-rw-r--r--docs/antora.yml5
-rw-r--r--docs/examples/basic/.cargo/config.toml (renamed from docs/modules/ROOT/examples/basic/.cargo/config.toml)0
-rw-r--r--docs/examples/basic/Cargo.toml18
-rw-r--r--docs/examples/basic/build.rs (renamed from docs/modules/ROOT/examples/basic/build.rs)0
-rw-r--r--docs/examples/basic/memory.x (renamed from docs/modules/ROOT/examples/basic/memory.x)0
-rw-r--r--docs/examples/basic/src/main.rs (renamed from docs/modules/ROOT/examples/basic/src/main.rs)0
l---------docs/examples/examples1
-rw-r--r--docs/examples/layer-by-layer/.cargo/config.toml (renamed from docs/modules/ROOT/examples/layer-by-layer/.cargo/config.toml)0
-rw-r--r--docs/examples/layer-by-layer/Cargo.toml (renamed from docs/modules/ROOT/examples/layer-by-layer/Cargo.toml)4
-rw-r--r--docs/examples/layer-by-layer/blinky-async/Cargo.toml (renamed from docs/modules/ROOT/examples/layer-by-layer/blinky-async/Cargo.toml)2
-rw-r--r--docs/examples/layer-by-layer/blinky-async/src/main.rs (renamed from docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs)0
-rw-r--r--docs/examples/layer-by-layer/blinky-hal/Cargo.toml (renamed from docs/modules/ROOT/examples/layer-by-layer/blinky-hal/Cargo.toml)0
-rw-r--r--docs/examples/layer-by-layer/blinky-hal/src/main.rs (renamed from docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs)0
-rw-r--r--docs/examples/layer-by-layer/blinky-irq/Cargo.toml (renamed from docs/modules/ROOT/examples/layer-by-layer/blinky-irq/Cargo.toml)0
-rw-r--r--docs/examples/layer-by-layer/blinky-irq/src/main.rs (renamed from docs/modules/ROOT/examples/layer-by-layer/blinky-irq/src/main.rs)0
-rw-r--r--docs/examples/layer-by-layer/blinky-pac/Cargo.toml (renamed from docs/modules/ROOT/examples/layer-by-layer/blinky-pac/Cargo.toml)0
-rw-r--r--docs/examples/layer-by-layer/blinky-pac/src/main.rs (renamed from docs/modules/ROOT/examples/layer-by-layer/blinky-pac/src/main.rs)0
-rw-r--r--docs/images/bootloader_flash.png (renamed from docs/modules/ROOT/images/bootloader_flash.png)bin32147 -> 32147 bytes
-rw-r--r--docs/images/embassy_executor.drawio (renamed from docs/modules/ROOT/images/embassy_executor.drawio)0
-rw-r--r--docs/images/embassy_executor.png (renamed from docs/modules/ROOT/images/embassy_executor.png)bin121382 -> 121382 bytes
-rw-r--r--docs/images/embassy_irq.drawio (renamed from docs/modules/ROOT/images/embassy_irq.drawio)0
-rw-r--r--docs/images/embassy_irq.png (renamed from docs/modules/ROOT/images/embassy_irq.png)bin134158 -> 134158 bytes
-rw-r--r--docs/index.adoc16
-rw-r--r--docs/modules/ROOT/examples/basic/Cargo.toml18
l---------docs/modules/ROOT/examples/examples1
-rw-r--r--docs/modules/ROOT/nav.adoc19
-rw-r--r--docs/modules/ROOT/pages/embassy_in_the_wild.adoc11
-rw-r--r--docs/modules/ROOT/pages/faq.adoc203
-rw-r--r--docs/pages/basic_application.adoc (renamed from docs/modules/ROOT/pages/basic_application.adoc)23
-rw-r--r--docs/pages/beginners.adoc11
-rw-r--r--docs/pages/best_practices.adoc (renamed from docs/modules/ROOT/pages/best_practices.adoc)0
-rw-r--r--docs/pages/bootloader.adoc (renamed from docs/modules/ROOT/pages/bootloader.adoc)5
-rw-r--r--docs/pages/developer.adoc (renamed from docs/modules/ROOT/pages/developer.adoc)0
-rw-r--r--docs/pages/developer_stm32.adoc (renamed from docs/modules/ROOT/pages/developer_stm32.adoc)0
-rw-r--r--docs/pages/embassy_in_the_wild.adoc24
-rw-r--r--docs/pages/examples.adoc (renamed from docs/modules/ROOT/pages/examples.adoc)2
-rw-r--r--docs/pages/faq.adoc374
-rw-r--r--docs/pages/getting_started.adoc (renamed from docs/modules/ROOT/pages/getting_started.adoc)42
-rw-r--r--docs/pages/hal.adoc (renamed from docs/modules/ROOT/pages/hal.adoc)2
-rw-r--r--docs/pages/layer_by_layer.adoc (renamed from docs/modules/ROOT/pages/layer_by_layer.adoc)12
-rw-r--r--docs/pages/new_project.adoc (renamed from docs/modules/ROOT/pages/new_project.adoc)23
-rw-r--r--docs/pages/nrf.adoc (renamed from docs/modules/ROOT/pages/nrf.adoc)2
-rw-r--r--docs/pages/overview.adoc (renamed from docs/modules/ROOT/pages/index.adoc)23
-rw-r--r--docs/pages/project_structure.adoc (renamed from docs/modules/ROOT/pages/project_structure.adoc)12
-rw-r--r--docs/pages/runtime.adoc (renamed from docs/modules/ROOT/pages/runtime.adoc)0
-rw-r--r--docs/pages/sharing_peripherals.adoc (renamed from docs/modules/ROOT/pages/sharing_peripherals.adoc)10
-rw-r--r--docs/pages/stm32.adoc (renamed from docs/modules/ROOT/pages/stm32.adoc)2
-rw-r--r--docs/pages/system.adoc13
-rw-r--r--docs/pages/time_keeping.adoc (renamed from docs/modules/ROOT/pages/time_keeping.adoc)2
51 files changed, 601 insertions, 316 deletions
diff --git a/docs/Makefile b/docs/Makefile
new file mode 100644
index 000000000..834802d3b
--- /dev/null
+++ b/docs/Makefile
@@ -0,0 +1,8 @@
1all:
2 asciidoctor -d book -D book/ index.adoc
3 cp -r images book
4
5clean:
6 rm -rf book
7
8.PHONY: all clean
diff --git a/docs/README.md b/docs/README.md
index 0bf3a6c89..d766a86d9 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -1,4 +1,29 @@
1# embassy docs 1# embassy docs
2 2
3The documentation hosted at [https://embassy.dev/book](https://embassy.dev/book). Building the documentation requires 3The documentation hosted at [https://embassy.dev/book](https://embassy.dev/book). Building the documentation requires the [asciidoctor](https://asciidoctor.org/) tool, and can built running `make` in this folder:
4cloning the [embassy-book](https://github.com/embassy-rs/embassy-book) repository and following the instructions. 4
5```
6make
7```
8
9Then open the generated file `thebook/index.html`.
10
11## License
12
13The Embassy Docs (this folder) is distributed under the following licenses:
14
15* The code samples and free-standing Cargo projects contained within these docs are licensed under the terms of both the [MIT License] and the [Apache License v2.0].
16* The written prose contained within these docs are licensed under the terms of the Creative Commons [CC-BY-SA v4.0] license.
17
18Copies of the licenses used by this project may also be found here:
19
20* [MIT License Hosted]
21* [Apache License v2.0 Hosted]
22* [CC-BY-SA v4.0 Hosted]
23
24[MIT License]: ./../LICENSE-MIT
25[Apache License v2.0]: ./../LICENSE-APACHE
26[CC-BY-SA v4.0]: ./../LICENSE-CC-BY-SA
27[MIT License Hosted]: https://opensource.org/licenses/MIT
28[Apache License v2.0 Hosted]: http://www.apache.org/licenses/LICENSE-2.0
29[CC-BY-SA v4.0 Hosted]: https://creativecommons.org/licenses/by-sa/4.0/legalcode
diff --git a/docs/antora.yml b/docs/antora.yml
deleted file mode 100644
index 9a00fa820..000000000
--- a/docs/antora.yml
+++ /dev/null
@@ -1,5 +0,0 @@
1name: ROOT
2title: Embassy
3version: dev
4nav:
5 - modules/ROOT/nav.adoc
diff --git a/docs/modules/ROOT/examples/basic/.cargo/config.toml b/docs/examples/basic/.cargo/config.toml
index 8ca28df39..8ca28df39 100644
--- a/docs/modules/ROOT/examples/basic/.cargo/config.toml
+++ b/docs/examples/basic/.cargo/config.toml
diff --git a/docs/examples/basic/Cargo.toml b/docs/examples/basic/Cargo.toml
new file mode 100644
index 000000000..5d391adf3
--- /dev/null
+++ b/docs/examples/basic/Cargo.toml
@@ -0,0 +1,18 @@
1[package]
2authors = ["Dario Nieuwenhuis <[email protected]>"]
3edition = "2018"
4name = "embassy-basic-example"
5version = "0.1.0"
6license = "MIT OR Apache-2.0"
7
8[dependencies]
9embassy-executor = { version = "0.6.0", path = "../../../embassy-executor", features = ["defmt", "integrated-timers", "arch-cortex-m", "executor-thread"] }
10embassy-time = { version = "0.3.2", path = "../../../embassy-time", features = ["defmt"] }
11embassy-nrf = { version = "0.2.0", path = "../../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote"] }
12
13defmt = "0.3"
14defmt-rtt = "0.3"
15
16cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
17cortex-m-rt = "0.7.0"
18panic-probe = { version = "0.3", features = ["print-defmt"] }
diff --git a/docs/modules/ROOT/examples/basic/build.rs b/docs/examples/basic/build.rs
index 30691aa97..30691aa97 100644
--- a/docs/modules/ROOT/examples/basic/build.rs
+++ b/docs/examples/basic/build.rs
diff --git a/docs/modules/ROOT/examples/basic/memory.x b/docs/examples/basic/memory.x
index 9b04edec0..9b04edec0 100644
--- a/docs/modules/ROOT/examples/basic/memory.x
+++ b/docs/examples/basic/memory.x
diff --git a/docs/modules/ROOT/examples/basic/src/main.rs b/docs/examples/basic/src/main.rs
index 4412712c8..4412712c8 100644
--- a/docs/modules/ROOT/examples/basic/src/main.rs
+++ b/docs/examples/basic/src/main.rs
diff --git a/docs/examples/examples b/docs/examples/examples
new file mode 120000
index 000000000..d15735c1d
--- /dev/null
+++ b/docs/examples/examples
@@ -0,0 +1 @@
../../examples \ No newline at end of file
diff --git a/docs/modules/ROOT/examples/layer-by-layer/.cargo/config.toml b/docs/examples/layer-by-layer/.cargo/config.toml
index 3012f05dc..3012f05dc 100644
--- a/docs/modules/ROOT/examples/layer-by-layer/.cargo/config.toml
+++ b/docs/examples/layer-by-layer/.cargo/config.toml
diff --git a/docs/modules/ROOT/examples/layer-by-layer/Cargo.toml b/docs/examples/layer-by-layer/Cargo.toml
index 943249a17..0f233eae5 100644
--- a/docs/modules/ROOT/examples/layer-by-layer/Cargo.toml
+++ b/docs/examples/layer-by-layer/Cargo.toml
@@ -8,8 +8,8 @@ members = [
8] 8]
9 9
10[patch.crates-io] 10[patch.crates-io]
11embassy-executor = { path = "../../../../../embassy-executor" } 11embassy-executor = { path = "../../../embassy-executor" }
12embassy-stm32 = { path = "../../../../../embassy-stm32" } 12embassy-stm32 = { path = "../../../embassy-stm32" }
13 13
14[profile.release] 14[profile.release]
15codegen-units = 1 15codegen-units = 1
diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-async/Cargo.toml b/docs/examples/layer-by-layer/blinky-async/Cargo.toml
index 64f7e8403..7f8d8af3e 100644
--- a/docs/modules/ROOT/examples/layer-by-layer/blinky-async/Cargo.toml
+++ b/docs/examples/layer-by-layer/blinky-async/Cargo.toml
@@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0"
8cortex-m = "0.7" 8cortex-m = "0.7"
9cortex-m-rt = "0.7" 9cortex-m-rt = "0.7"
10embassy-stm32 = { version = "0.1.0", features = ["stm32l475vg", "memory-x", "exti"] } 10embassy-stm32 = { version = "0.1.0", features = ["stm32l475vg", "memory-x", "exti"] }
11embassy-executor = { version = "0.5.0", features = ["arch-cortex-m", "executor-thread"] } 11embassy-executor = { version = "0.6.0", features = ["arch-cortex-m", "executor-thread"] }
12 12
13defmt = "0.3.0" 13defmt = "0.3.0"
14defmt-rtt = "0.3.0" 14defmt-rtt = "0.3.0"
diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs b/docs/examples/layer-by-layer/blinky-async/src/main.rs
index 004602816..004602816 100644
--- a/docs/modules/ROOT/examples/layer-by-layer/blinky-async/src/main.rs
+++ b/docs/examples/layer-by-layer/blinky-async/src/main.rs
diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/Cargo.toml b/docs/examples/layer-by-layer/blinky-hal/Cargo.toml
index c15de2db2..c15de2db2 100644
--- a/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/Cargo.toml
+++ b/docs/examples/layer-by-layer/blinky-hal/Cargo.toml
diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs b/docs/examples/layer-by-layer/blinky-hal/src/main.rs
index d0c9f4907..d0c9f4907 100644
--- a/docs/modules/ROOT/examples/layer-by-layer/blinky-hal/src/main.rs
+++ b/docs/examples/layer-by-layer/blinky-hal/src/main.rs
diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/Cargo.toml b/docs/examples/layer-by-layer/blinky-irq/Cargo.toml
index 9733658b6..9733658b6 100644
--- a/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/Cargo.toml
+++ b/docs/examples/layer-by-layer/blinky-irq/Cargo.toml
diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/src/main.rs b/docs/examples/layer-by-layer/blinky-irq/src/main.rs
index 743c9d99b..743c9d99b 100644
--- a/docs/modules/ROOT/examples/layer-by-layer/blinky-irq/src/main.rs
+++ b/docs/examples/layer-by-layer/blinky-irq/src/main.rs
diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/Cargo.toml b/docs/examples/layer-by-layer/blinky-pac/Cargo.toml
index f872b94cb..f872b94cb 100644
--- a/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/Cargo.toml
+++ b/docs/examples/layer-by-layer/blinky-pac/Cargo.toml
diff --git a/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/src/main.rs b/docs/examples/layer-by-layer/blinky-pac/src/main.rs
index 990d46cb6..990d46cb6 100644
--- a/docs/modules/ROOT/examples/layer-by-layer/blinky-pac/src/main.rs
+++ b/docs/examples/layer-by-layer/blinky-pac/src/main.rs
diff --git a/docs/modules/ROOT/images/bootloader_flash.png b/docs/images/bootloader_flash.png
index 635783b05..635783b05 100644
--- a/docs/modules/ROOT/images/bootloader_flash.png
+++ b/docs/images/bootloader_flash.png
Binary files differ
diff --git a/docs/modules/ROOT/images/embassy_executor.drawio b/docs/images/embassy_executor.drawio
index b76587d97..b76587d97 100644
--- a/docs/modules/ROOT/images/embassy_executor.drawio
+++ b/docs/images/embassy_executor.drawio
diff --git a/docs/modules/ROOT/images/embassy_executor.png b/docs/images/embassy_executor.png
index 2a83a3adb..2a83a3adb 100644
--- a/docs/modules/ROOT/images/embassy_executor.png
+++ b/docs/images/embassy_executor.png
Binary files differ
diff --git a/docs/modules/ROOT/images/embassy_irq.drawio b/docs/images/embassy_irq.drawio
index aa439a8e6..aa439a8e6 100644
--- a/docs/modules/ROOT/images/embassy_irq.drawio
+++ b/docs/images/embassy_irq.drawio
diff --git a/docs/modules/ROOT/images/embassy_irq.png b/docs/images/embassy_irq.png
index 154d336b6..154d336b6 100644
--- a/docs/modules/ROOT/images/embassy_irq.png
+++ b/docs/images/embassy_irq.png
Binary files differ
diff --git a/docs/index.adoc b/docs/index.adoc
new file mode 100644
index 000000000..9c6150196
--- /dev/null
+++ b/docs/index.adoc
@@ -0,0 +1,16 @@
1:description: Embassy Book
2:sectanchors:
3:doctype: book
4:toc:
5:toc-placement: left
6:toclevels: 2
7:imagesdir: images
8
9# Embassy Book
10
11Welcome to the Embassy Book. The Embassy Book is for everyone who wants to use Embassy and understand how Embassy works.
12
13include::pages/overview.adoc[leveloffset = 1]
14include::pages/beginners.adoc[leveloffset = 1]
15include::pages/system.adoc[leveloffset = 1]
16include::pages/faq.adoc[leveloffset = 1]
diff --git a/docs/modules/ROOT/examples/basic/Cargo.toml b/docs/modules/ROOT/examples/basic/Cargo.toml
deleted file mode 100644
index 2c282145d..000000000
--- a/docs/modules/ROOT/examples/basic/Cargo.toml
+++ /dev/null
@@ -1,18 +0,0 @@
1[package]
2authors = ["Dario Nieuwenhuis <[email protected]>"]
3edition = "2018"
4name = "embassy-basic-example"
5version = "0.1.0"
6license = "MIT OR Apache-2.0"
7
8[dependencies]
9embassy-executor = { version = "0.5.0", path = "../../../../../embassy-executor", features = ["defmt", "integrated-timers", "arch-cortex-m", "executor-thread"] }
10embassy-time = { version = "0.3.0", path = "../../../../../embassy-time", features = ["defmt"] }
11embassy-nrf = { version = "0.1.0", path = "../../../../../embassy-nrf", features = ["defmt", "nrf52840", "time-driver-rtc1", "gpiote"] }
12
13defmt = "0.3"
14defmt-rtt = "0.3"
15
16cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
17cortex-m-rt = "0.7.0"
18panic-probe = { version = "0.3", features = ["print-defmt"] }
diff --git a/docs/modules/ROOT/examples/examples b/docs/modules/ROOT/examples/examples
deleted file mode 120000
index 1929330b0..000000000
--- a/docs/modules/ROOT/examples/examples
+++ /dev/null
@@ -1 +0,0 @@
1../../../../examples \ No newline at end of file
diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc
deleted file mode 100644
index 44b0eddb9..000000000
--- a/docs/modules/ROOT/nav.adoc
+++ /dev/null
@@ -1,19 +0,0 @@
1* xref:getting_started.adoc[Getting started]
2** xref:basic_application.adoc[Basic application]
3** xref:project_structure.adoc[Project Structure]
4** xref:new_project.adoc[Starting a new Embassy project]
5** xref:best_practices.adoc[Best Practices]
6* xref:runtime.adoc[Executor]
7* xref::time_keeping.adoc[Time-keeping]
8* xref:sharing_peripherals.adoc[Sharing peripherals]
9* xref:hal.adoc[HAL]
10** xref:layer_by_layer.adoc[Anatomy of an async HAL]
11** xref:nrf.adoc[nRF]
12** xref:stm32.adoc[STM32]
13* xref:bootloader.adoc[Bootloader]
14
15* xref:examples.adoc[Examples]
16* xref:developer.adoc[Developer Docs]
17** xref:developer_stm32.adoc[Developer Docs: STM32]
18* xref:embassy_in_the_wild.adoc[Embassy in the wild]
19* xref:faq.adoc[Frequently Asked Questions]
diff --git a/docs/modules/ROOT/pages/embassy_in_the_wild.adoc b/docs/modules/ROOT/pages/embassy_in_the_wild.adoc
deleted file mode 100644
index 85ad7f4a2..000000000
--- a/docs/modules/ROOT/pages/embassy_in_the_wild.adoc
+++ /dev/null
@@ -1,11 +0,0 @@
1= Embassy in the wild!
2
3Here are known examples of real-world projects which make use of Embassy. Feel free to link:https://github.com/embassy-rs/embassy/blob/main/docs/modules/ROOT/pages/embassy_in_the_wild.adoc[add more]!
4
5* link:https://github.com/cbruiz/printhor/[Printhor: The highly reliable but not necessarily functional 3D printer firmware]
6** Targets some STM32 MCUs
7* link:https://github.com/card-io-ecg/card-io-fw[Card/IO firmware] - firmware for an open source ECG device
8** Targets the ESP32-S3 or ESP32-C6 MCU
9* 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
10** link:https://github.com/matoushybl/air-force-one[Air force one: A simple air quality monitoring system]
11*** Targets nRF52 and uses nrf-softdevice
diff --git a/docs/modules/ROOT/pages/faq.adoc b/docs/modules/ROOT/pages/faq.adoc
deleted file mode 100644
index 7fb81e2ca..000000000
--- a/docs/modules/ROOT/pages/faq.adoc
+++ /dev/null
@@ -1,203 +0,0 @@
1= Frequently Asked Questions
2
3These are a list of unsorted, commonly asked questions and answers.
4
5Please feel free to add items to link:https://github.com/embassy-rs/embassy/edit/main/docs/modules/ROOT/pages/faq.adoc[this page], especially if someone in the chat answered a question for you!
6
7== How to deploy to RP2040 without a debugging probe.
8
9Install link:https://github.com/JoNil/elf2uf2-rs[elf2uf2-rs] for converting the generated elf binary into a uf2 file.
10
11Configure the runner to use this tool, add this to `.cargo/config.toml`:
12[source,toml]
13----
14[target.'cfg(all(target_arch = "arm", target_os = "none"))']
15runner = "elf2uf2-rs --deploy --serial --verbose"
16----
17
18The command-line parameters `--deploy` will detect your device and upload the binary, `--serial` starts a serial connection. See the documentation for more info.
19
20== Missing main macro
21
22If you see an error like this:
23
24[source,rust]
25----
26#[embassy_executor::main]
27| ^^^^ could not find `main` in `embassy_executor`
28----
29
30You are likely missing some features of the `embassy-executor` crate.
31
32For Cortex-M targets, check whether ALL of the following features are enabled in your `Cargo.toml` for the `embassy-executor` crate:
33
34* `arch-cortex-m`
35* `executor-thread`
36
37For ESP32, consider using the executors and `#[main]` macro provided by your appropriate link:https://crates.io/crates/esp-hal-common[HAL crate].
38
39== Why is my binary so big?
40
41The first step to managing your binary size is to set up your link:https://doc.rust-lang.org/cargo/reference/profiles.html[profiles].
42
43[source,toml]
44----
45[profile.release]
46lto = true
47opt-level = "s"
48incremental = false
49codegen-units = 1
50# note: debug = true is okay - debuginfo isn't flashed to the device!
51debug = true
52----
53
54All of these flags are elaborated on in the Rust Book page linked above.
55
56=== My binary is still big... filled with `std::fmt` stuff!
57
58This means your code is sufficiently complex that `panic!` invocation's formatting requirements could not be optimized out, despite your usage of `panic-halt` or `panic-reset`.
59
60You can remedy this by adding the following to your `.cargo/config.toml`:
61
62[source,toml]
63----
64[unstable]
65build-std = ["core"]
66build-std-features = ["panic_immediate_abort"]
67----
68
69This replaces all panics with a `UDF` (undefined) instruction.
70
71Depending on your chipset, this will exhibit different behavior.
72
73Refer to the spec for your chipset, but for `thumbv6m`, it results in a hardfault. Which can be configured like so:
74
75[source,rust]
76----
77#[exception]
78unsafe fn HardFault(_frame: &ExceptionFrame) -> ! {
79 SCB::sys_reset() // <- you could do something other than reset
80}
81----
82
83Refer to cortex-m's link:https://docs.rs/cortex-m-rt/latest/cortex_m_rt/attr.exception.html[exception handling] for more info.
84
85== `embassy-time` throws linker errors
86
87If you see linker error like this:
88
89[source,text]
90----
91 = note: rust-lld: error: undefined symbol: _embassy_time_now
92 >>> referenced by driver.rs:127 (src/driver.rs:127)
93 >>> embassy_time-846f66f1620ad42c.embassy_time.4f6a638abb75dd4c-cgu.0.rcgu.o:(embassy_time::driver::now::hefb1f99d6e069842) in archive Devel/Embedded/pogodyna/target/thumbv7em-none-eabihf/debug/deps/libembassy_time-846f66f1620ad42c.rlib
94
95 rust-lld: error: undefined symbol: _embassy_time_allocate_alarm
96 >>> referenced by driver.rs:134 (src/driver.rs:134)
97 >>> embassy_time-846f66f1620ad42c.embassy_time.4f6a638abb75dd4c-cgu.0.rcgu.o:(embassy_time::driver::allocate_alarm::hf5145b6bd46706b2) in archive Devel/Embedded/pogodyna/target/thumbv7em-none-eabihf/debug/deps/libembassy_time-846f66f1620ad42c.rlib
98
99 rust-lld: error: undefined symbol: _embassy_time_set_alarm_callback
100 >>> referenced by driver.rs:139 (src/driver.rs:139)
101 >>> embassy_time-846f66f1620ad42c.embassy_time.4f6a638abb75dd4c-cgu.0.rcgu.o:(embassy_time::driver::set_alarm_callback::h24f92388d96eafd2) in archive Devel/Embedded/pogodyna/target/thumbv7em-none-eabihf/debug/deps/libembassy_time-846f66f1620ad42c.rlib
102
103 rust-lld: error: undefined symbol: _embassy_time_set_alarm
104 >>> referenced by driver.rs:144 (src/driver.rs:144)
105 >>> embassy_time-846f66f1620ad42c.embassy_time.4f6a638abb75dd4c-cgu.0.rcgu.o:(embassy_time::driver::set_alarm::h530a5b1f444a6d5b) in archive Devel/Embedded/pogodyna/target/thumbv7em-none-eabihf/debug/deps/libembassy_time-846f66f1620ad42c.rlib
106----
107
108You probably need to enable a time driver for your HAL (not in `embassy-time`!). For example with `embassy-stm32`, you might need to enable `time-driver-any`:
109
110[source,toml]
111----
112[dependencies.embassy-stm32]
113version = "0.1.0"
114features = [
115 # ...
116 "time-driver-any", # Add this line!
117 # ...
118]
119----
120
121== Error: `Only one package in the dependency graph may specify the same links value.`
122
123You have multiple versions of the same crate in your dependency tree. This means that some of your
124embassy crates are coming from crates.io, and some from git, each of them pulling in a different set
125of dependencies.
126
127To resolve this issue, make sure to only use a single source for all your embassy crates!
128To do this, you should patch your dependencies to use git sources using `[patch.crates.io]`
129and maybe `[patch.'https://github.com/embassy-rs/embassy.git']`.
130
131Example:
132
133[source,toml]
134----
135[patch.crates-io]
136embassy-time-queue-driver = { git = "https://github.com/embassy-rs/embassy.git", rev = "e5fdd35" }
137embassy-time-driver = { git = "https://github.com/embassy-rs/embassy.git", rev = "e5fdd35" }
138# embassy-time = { git = "https://github.com/embassy-rs/embassy.git", rev = "e5fdd35" }
139----
140
141Note that the git revision should match any other embassy patches or git dependencies that you are using!
142
143== How can I optimize the speed of my embassy-stm32 program?
144
145* Make sure RCC is set up to go as fast as possible
146* Make sure link:https://docs.rs/cortex-m/latest/cortex_m/peripheral/struct.SCB.html[flash cache] is enabled
147* build with `--release`
148* Set the following keys for the release profile in your `Cargo.toml`:
149 ** `opt-level = "s"`
150 ** `lto = "fat"`
151* Set the following keys in the `[unstable]` section of your `.cargo/config.toml`
152 ** `build-std = ["core"]`
153 ** `build-std-features = ["panic_immediate_abort"]`
154* Enable feature `embassy-time/generic-queue`, disable feature `embassy-executor/integrated-timers`
155* When using `InterruptExecutor`:
156 ** disable `executor-thread`
157 ** 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() }`
158 ** *Note:* If you need 2 priority levels, using 2 interrupt executors is better than 1 thread executor + 1 interrupt executor.
159
160== How do I set up the task arenas on stable?
161
162When you aren't using the `nightly` feature of `embassy-executor`, the executor uses a bump allocator, which may require configuration.
163
164Something like this error will occur at **compile time** if the task arena is *too large* for the target's RAM:
165
166[source,plain]
167----
168rust-lld: error: section '.bss' will not fit in region 'RAM': overflowed by _ bytes
169rust-lld: error: section '.uninit' will not fit in region 'RAM': overflowed by _ bytes
170----
171
172And this message will appear at **runtime** if the task arena is *too small* for the tasks running:
173
174[source,plain]
175----
176ERROR 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/'
177----
178
179NOTE: If all tasks are spawned at startup, this panic will occur immediately.
180
181Check out link:https://docs.embassy.dev/embassy-executor/git/cortex-m/index.html#task-arena[Task Arena Documentation] for more details.
182
183== Can I use manual ISRs alongside Embassy?
184
185Yes! 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].
186
187== How can I measure resource usage (CPU, RAM, etc.)?
188
189=== For CPU Usage:
190
191There 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.
192
193We 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.
194
195If you end up doing this, please update this section with more specific examples!
196
197=== For Static Memory Usage
198
199Tools 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.
200
201=== For Max Stack Usage
202
203Check 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.
diff --git a/docs/modules/ROOT/pages/basic_application.adoc b/docs/pages/basic_application.adoc
index 95792d5a0..5c4e3e8b3 100644
--- a/docs/modules/ROOT/pages/basic_application.adoc
+++ b/docs/pages/basic_application.adoc
@@ -1,10 +1,10 @@
1= A basic Embassy application 1= A basic Embassy application
2 2
3So you've got one of the xref:examples.adoc[examples] running, but what now? Let's go through a simple Embassy application for the nRF52 DK to understand it better. 3So you've got one of the examples running, but what now? Let's go through a simple Embassy application for the nRF52 DK to understand it better.
4 4
5== Main 5== Main
6 6
7The full example can be found link:https://github.com/embassy-rs/embassy/tree/master/docs/modules/ROOT/examples/basic[here]. 7The full example can be found link:https://github.com/embassy-rs/embassy/tree/main/docs/examples/basic[here].
8 8
9NOTE: If you’re using VS Code and rust-analyzer to view and edit the examples, you may need to make some changes to `.vscode/settings.json` to tell it which project we’re working on. Follow the instructions commented in that file to get rust-analyzer working correctly. 9NOTE: If you’re using VS Code and rust-analyzer to view and edit the examples, you may need to make some changes to `.vscode/settings.json` to tell it which project we’re working on. Follow the instructions commented in that file to get rust-analyzer working correctly.
10 10
@@ -14,16 +14,7 @@ The first thing you’ll notice are two attributes at the top of the file. These
14 14
15[source,rust] 15[source,rust]
16---- 16----
17include::example$basic/src/main.rs[lines="1..2"] 17include::../examples/basic/src/main.rs[lines="1..2"]
18----
19
20=== Rust Nightly
21
22The next declaration is a Rust Unstable feature, which means that Embassy requires Rust Nightly:
23
24[source,rust]
25----
26include::example$basic/src/main.rs[lines="3"]
27---- 18----
28 19
29=== Dealing with errors 20=== Dealing with errors
@@ -32,7 +23,7 @@ Then, what follows are some declarations on how to deal with panics and faults.
32 23
33[source,rust] 24[source,rust]
34---- 25----
35include::example$basic/src/main.rs[lines="10"] 26include::../examples/basic/src/main.rs[lines="8"]
36---- 27----
37 28
38=== Task declaration 29=== Task declaration
@@ -41,7 +32,7 @@ After a bit of import declaration, the tasks run by the application should be de
41 32
42[source,rust] 33[source,rust]
43---- 34----
44include::example$basic/src/main.rs[lines="12..20"] 35include::../examples/basic/src/main.rs[lines="10..18"]
45---- 36----
46 37
47An 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. 38An 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`
56 47
57[source,rust] 48[source,rust]
58---- 49----
59include::example$basic/src/main.rs[lines="22..-1"] 50include::../examples/basic/src/main.rs[lines="20..-1"]
60---- 51----
61 52
62What 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: 53What 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:
@@ -73,7 +64,7 @@ The project definition needs to contain the embassy dependencies:
73 64
74[source,toml] 65[source,toml]
75---- 66----
76include::example$basic/Cargo.toml[lines="9..11"] 67include::../examples/basic/Cargo.toml[lines="9..11"]
77---- 68----
78 69
79Depending on your microcontroller, you may need to replace `embassy-nrf` with something else (`embassy-stm32` for STM32. Remember to update feature flags as well). 70Depending on your microcontroller, you may need to replace `embassy-nrf` with something else (`embassy-stm32` for STM32. Remember to update feature flags as well).
diff --git a/docs/pages/beginners.adoc b/docs/pages/beginners.adoc
new file mode 100644
index 000000000..48c9f4541
--- /dev/null
+++ b/docs/pages/beginners.adoc
@@ -0,0 +1,11 @@
1= For beginners
2
3The articles in this section are primarily aimed at users new to Embassy,
4showing how to get started, how to structure your project and other best practices.
5
6include::getting_started.adoc[leveloffset = 2]
7include::basic_application.adoc[leveloffset = 2]
8include::project_structure.adoc[leveloffset = 2]
9include::new_project.adoc[leveloffset = 2]
10include::best_practices.adoc[leveloffset = 2]
11include::layer_by_layer.adoc[leveloffset = 2]
diff --git a/docs/modules/ROOT/pages/best_practices.adoc b/docs/pages/best_practices.adoc
index bfcedec06..bfcedec06 100644
--- a/docs/modules/ROOT/pages/best_practices.adoc
+++ b/docs/pages/best_practices.adoc
diff --git a/docs/modules/ROOT/pages/bootloader.adoc b/docs/pages/bootloader.adoc
index 3b0cdb182..53f85d995 100644
--- a/docs/modules/ROOT/pages/bootloader.adoc
+++ b/docs/pages/bootloader.adoc
@@ -19,6 +19,8 @@ The bootloader supports
19 19
20In general, the bootloader works on any platform that implements the `embedded-storage` traits for its internal flash, but may require custom initialization code to work. 20In general, the bootloader works on any platform that implements the `embedded-storage` traits for its internal flash, but may require custom initialization code to work.
21 21
22STM32L0x1 devices require the `flash-erase-zero` feature to be enabled.
23
22== Design 24== Design
23 25
24image::bootloader_flash.png[Bootloader flash layout] 26image::bootloader_flash.png[Bootloader flash layout]
@@ -86,8 +88,7 @@ Then, to sign your firmware given a declaration of `FIRMWARE_DIR` and a firmware
86 88
87[source, bash] 89[source, bash]
88---- 90----
89shasum -a 512 -b $FIRMWARE_DIR/myfirmware > $SECRETS_DIR/message.txt 91shasum -a 512 -b $FIRMWARE_DIR/myfirmware | head -c128 | xxd -p -r > $SECRETS_DIR/message.txt
90cat $SECRETS_DIR/message.txt | dd ibs=128 count=1 | xxd -p -r > $SECRETS_DIR/message.txt
91signify -S -s $SECRETS_DIR/key.sec -m $SECRETS_DIR/message.txt -x $SECRETS_DIR/message.txt.sig 92signify -S -s $SECRETS_DIR/key.sec -m $SECRETS_DIR/message.txt -x $SECRETS_DIR/message.txt.sig
92cp $FIRMWARE_DIR/myfirmware $FIRMWARE_DIR/myfirmware+signed 93cp $FIRMWARE_DIR/myfirmware $FIRMWARE_DIR/myfirmware+signed
93tail -n1 $SECRETS_DIR/message.txt.sig | base64 -d -i - | dd ibs=10 skip=1 >> $FIRMWARE_DIR/myfirmware+signed 94tail -n1 $SECRETS_DIR/message.txt.sig | base64 -d -i - | dd ibs=10 skip=1 >> $FIRMWARE_DIR/myfirmware+signed
diff --git a/docs/modules/ROOT/pages/developer.adoc b/docs/pages/developer.adoc
index e03ee51a8..e03ee51a8 100644
--- a/docs/modules/ROOT/pages/developer.adoc
+++ b/docs/pages/developer.adoc
diff --git a/docs/modules/ROOT/pages/developer_stm32.adoc b/docs/pages/developer_stm32.adoc
index 7c04ab1a4..7c04ab1a4 100644
--- a/docs/modules/ROOT/pages/developer_stm32.adoc
+++ b/docs/pages/developer_stm32.adoc
diff --git a/docs/pages/embassy_in_the_wild.adoc b/docs/pages/embassy_in_the_wild.adoc
new file mode 100644
index 000000000..bb457a869
--- /dev/null
+++ b/docs/pages/embassy_in_the_wild.adoc
@@ -0,0 +1,24 @@
1= Embassy in the wild!
2
3Here are known examples of real-world projects which make use of Embassy. Feel free to link:https://github.com/embassy-rs/embassy/blob/main/docs/pages/embassy_in_the_wild.adoc[add more]!
4
5* link:https://github.com/1-rafael-1/pi-pico-alarmclock-rust[A Raspberry Pi Pico W Alarmclock]
6** A hobbyist project building an alarm clock around a Pi Pico W complete with code, components list and enclosure design files.
7* link:https://github.com/haobogu/rmk/[RMK: A feature-rich Rust keyboard firmware]
8** RMK has built-in layer support, wireless(BLE) support, real-time key editing support using vial, and more!
9** Targets STM32, RP2040, nRF52 and ESP32 MCUs
10* link:https://github.com/cbruiz/printhor/[Printhor: The highly reliable but not necessarily functional 3D printer firmware]
11** Targets some STM32 MCUs
12* link:https://github.com/card-io-ecg/card-io-fw[Card/IO firmware] - firmware for an open source ECG device
13** Targets the ESP32-S3 or ESP32-C6 MCU
14* 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
15* link:https://github.com/matoushybl/air-force-one[Air force one: A simple air quality monitoring system]
16** Targets nRF52 and uses nrf-softdevice
17
18* link:https://github.com/schmettow/ylab-edge-go[YLab Edge Go] and link:https://github.com/schmettow/ylab-edge-pro[YLab Edge Pro] projects develop
19firmware (RP2040, STM32) for capturing physiological data in behavioural science research. Included so far are:
20** biopotentials (analog ports)
21** motion capture (6-axis accelerometers)
22** air quality (CO2, Temp, Humidity)
23** comes with an app for capturing and visualizing data [link:https://github.com/schmettow/ystudio-zero[Ystudio]]
24
diff --git a/docs/modules/ROOT/pages/examples.adoc b/docs/pages/examples.adoc
index c852f5205..82381a2c5 100644
--- a/docs/modules/ROOT/pages/examples.adoc
+++ b/docs/pages/examples.adoc
@@ -7,5 +7,5 @@ Main loop example
7 7
8[source,rust] 8[source,rust]
9---- 9----
10include::example$examples/std/src/bin/tick.rs[] 10include::../examples/examples/std/src/bin/tick.rs[]
11---- 11----
diff --git a/docs/pages/faq.adoc b/docs/pages/faq.adoc
new file mode 100644
index 000000000..8eb947b5e
--- /dev/null
+++ b/docs/pages/faq.adoc
@@ -0,0 +1,374 @@
1= Frequently Asked Questions
2
3These are a list of unsorted, commonly asked questions and answers.
4
5Please feel free to add items to link:https://github.com/embassy-rs/embassy/edit/main/docs/pages/faq.adoc[this page], especially if someone in the chat answered a question for you!
6
7== How to deploy to RP2040 without a debugging probe.
8
9Install link:https://github.com/JoNil/elf2uf2-rs[elf2uf2-rs] for converting the generated elf binary into a uf2 file.
10
11Configure the runner to use this tool, add this to `.cargo/config.toml`:
12[source,toml]
13----
14[target.'cfg(all(target_arch = "arm", target_os = "none"))']
15runner = "elf2uf2-rs --deploy --serial --verbose"
16----
17
18The command-line parameters `--deploy` will detect your device and upload the binary, `--serial` starts a serial connection. See the documentation for more info.
19
20== Missing main macro
21
22If you see an error like this:
23
24[source,rust]
25----
26#[embassy_executor::main]
27| ^^^^ could not find `main` in `embassy_executor`
28----
29
30You are likely missing some features of the `embassy-executor` crate.
31
32For Cortex-M targets, check whether ALL of the following features are enabled in your `Cargo.toml` for the `embassy-executor` crate:
33
34* `arch-cortex-m`
35* `executor-thread`
36
37For ESP32, consider using the executors and `#[main]` macro provided by your appropriate link:https://crates.io/crates/esp-hal-common[HAL crate].
38
39== Why is my binary so big?
40
41The first step to managing your binary size is to set up your link:https://doc.rust-lang.org/cargo/reference/profiles.html[profiles].
42
43[source,toml]
44----
45[profile.release]
46lto = true
47opt-level = "s"
48incremental = false
49codegen-units = 1
50# note: debug = true is okay - debuginfo isn't flashed to the device!
51debug = true
52----
53
54All of these flags are elaborated on in the Rust Book page linked above.
55
56=== My binary is still big... filled with `std::fmt` stuff!
57
58This means your code is sufficiently complex that `panic!` invocation's formatting requirements could not be optimized out, despite your usage of `panic-halt` or `panic-reset`.
59
60You can remedy this by adding the following to your `.cargo/config.toml`:
61
62[source,toml]
63----
64[unstable]
65build-std = ["core"]
66build-std-features = ["panic_immediate_abort"]
67----
68
69This replaces all panics with a `UDF` (undefined) instruction.
70
71Depending on your chipset, this will exhibit different behavior.
72
73Refer to the spec for your chipset, but for `thumbv6m`, it results in a hardfault. Which can be configured like so:
74
75[source,rust]
76----
77#[exception]
78unsafe fn HardFault(_frame: &ExceptionFrame) -> ! {
79 SCB::sys_reset() // <- you could do something other than reset
80}
81----
82
83Refer to cortex-m's link:https://docs.rs/cortex-m-rt/latest/cortex_m_rt/attr.exception.html[exception handling] for more info.
84
85== `embassy-time` throws linker errors
86
87If you see linker error like this:
88
89[source,text]
90----
91 = note: rust-lld: error: undefined symbol: _embassy_time_now
92 >>> referenced by driver.rs:127 (src/driver.rs:127)
93 >>> embassy_time-846f66f1620ad42c.embassy_time.4f6a638abb75dd4c-cgu.0.rcgu.o:(embassy_time::driver::now::hefb1f99d6e069842) in archive Devel/Embedded/pogodyna/target/thumbv7em-none-eabihf/debug/deps/libembassy_time-846f66f1620ad42c.rlib
94
95 rust-lld: error: undefined symbol: _embassy_time_allocate_alarm
96 >>> referenced by driver.rs:134 (src/driver.rs:134)
97 >>> embassy_time-846f66f1620ad42c.embassy_time.4f6a638abb75dd4c-cgu.0.rcgu.o:(embassy_time::driver::allocate_alarm::hf5145b6bd46706b2) in archive Devel/Embedded/pogodyna/target/thumbv7em-none-eabihf/debug/deps/libembassy_time-846f66f1620ad42c.rlib
98
99 rust-lld: error: undefined symbol: _embassy_time_set_alarm_callback
100 >>> referenced by driver.rs:139 (src/driver.rs:139)
101 >>> embassy_time-846f66f1620ad42c.embassy_time.4f6a638abb75dd4c-cgu.0.rcgu.o:(embassy_time::driver::set_alarm_callback::h24f92388d96eafd2) in archive Devel/Embedded/pogodyna/target/thumbv7em-none-eabihf/debug/deps/libembassy_time-846f66f1620ad42c.rlib
102
103 rust-lld: error: undefined symbol: _embassy_time_set_alarm
104 >>> referenced by driver.rs:144 (src/driver.rs:144)
105 >>> embassy_time-846f66f1620ad42c.embassy_time.4f6a638abb75dd4c-cgu.0.rcgu.o:(embassy_time::driver::set_alarm::h530a5b1f444a6d5b) in archive Devel/Embedded/pogodyna/target/thumbv7em-none-eabihf/debug/deps/libembassy_time-846f66f1620ad42c.rlib
106----
107
108You probably need to enable a time driver for your HAL (not in `embassy-time`!). For example with `embassy-stm32`, you might need to enable `time-driver-any`:
109
110[source,toml]
111----
112[dependencies.embassy-stm32]
113version = "0.1.0"
114features = [
115 # ...
116 "time-driver-any", # Add this line!
117 # ...
118]
119----
120
121If 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:
122
123[source,rust]
124----
125use embassy_stm32 as _;
126----
127
128== Error: `Only one package in the dependency graph may specify the same links value.`
129
130You have multiple versions of the same crate in your dependency tree. This means that some of your
131embassy crates are coming from crates.io, and some from git, each of them pulling in a different set
132of dependencies.
133
134To resolve this issue, make sure to only use a single source for all your embassy crates!
135To do this, you should patch your dependencies to use git sources using `[patch.crates.io]`
136and maybe `[patch.'https://github.com/embassy-rs/embassy.git']`.
137
138Example:
139
140[source,toml]
141----
142[patch.crates-io]
143embassy-time-queue-driver = { git = "https://github.com/embassy-rs/embassy.git", rev = "e5fdd35" }
144embassy-time-driver = { git = "https://github.com/embassy-rs/embassy.git", rev = "e5fdd35" }
145# embassy-time = { git = "https://github.com/embassy-rs/embassy.git", rev = "e5fdd35" }
146----
147
148Note that the git revision should match any other embassy patches or git dependencies that you are using!
149
150== How can I optimize the speed of my embassy-stm32 program?
151
152* Make sure RCC is set up to go as fast as possible
153* Make sure link:https://docs.rs/cortex-m/latest/cortex_m/peripheral/struct.SCB.html[flash cache] is enabled
154* build with `--release`
155* Set the following keys for the release profile in your `Cargo.toml`:
156 ** `opt-level = "s"`
157 ** `lto = "fat"`
158* Set the following keys in the `[unstable]` section of your `.cargo/config.toml`
159 ** `build-std = ["core"]`
160 ** `build-std-features = ["panic_immediate_abort"]`
161* Enable feature `embassy-time/generic-queue`, disable feature `embassy-executor/integrated-timers`
162* When using `InterruptExecutor`:
163 ** disable `executor-thread`
164 ** 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() }`
165 ** *Note:* If you need 2 priority levels, using 2 interrupt executors is better than 1 thread executor + 1 interrupt executor.
166
167== How do I set up the task arenas on stable?
168
169When you aren't using the `nightly` feature of `embassy-executor`, the executor uses a bump allocator, which may require configuration.
170
171Something like this error will occur at **compile time** if the task arena is *too large* for the target's RAM:
172
173[source,plain]
174----
175rust-lld: error: section '.bss' will not fit in region 'RAM': overflowed by _ bytes
176rust-lld: error: section '.uninit' will not fit in region 'RAM': overflowed by _ bytes
177----
178
179And this message will appear at **runtime** if the task arena is *too small* for the tasks running:
180
181[source,plain]
182----
183ERROR 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/'
184----
185
186NOTE: If all tasks are spawned at startup, this panic will occur immediately.
187
188Check out link:https://docs.embassy.dev/embassy-executor/git/cortex-m/index.html#task-arena[Task Arena Documentation] for more details.
189
190== Can I use manual ISRs alongside Embassy?
191
192Yes! 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].
193
194== How can I measure resource usage (CPU, RAM, etc.)?
195
196=== For CPU Usage:
197
198There 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.
199
200We 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.
201
202If you end up doing this, please update this section with more specific examples!
203
204=== For Static Memory Usage
205
206Tools 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.
207
208=== For Max Stack Usage
209
210Check 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.
211
212== The memory definition for my STM chip seems wrong, how do I define a `memory.x` file?
213
214It could happen that your project compiles, flashes but fails to run. The following situation can be true for your setup:
215
216The `memory.x` is generated automatically when enabling the `memory-x` feature on the `embassy-stm32` crate in the `Cargo.toml` file.
217This, in turn, uses `stm32-metapac` to generate the `memory.x` file for you. Unfortunately, more often than not this memory definition is not correct.
218
219You can override this by adding your own `memory.x` file. Such a file could look like this:
220```
221MEMORY
222{
223 FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 1024K
224 RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 320K
225}
226
227_stack_start = ORIGIN(RAM) + LENGTH(RAM);
228```
229
230Please refer to the STM32 documentation for the specific values suitable for your board and setup. The STM32 Cube examples often contain a linker script `.ld` file.
231Look for the `MEMORY` section and try to determine the FLASH and RAM sizes and section start.
232
233If you find a case where the memory.x is wrong, please report it on [this Github issue](https://github.com/embassy-rs/stm32-data/issues/301) so other users are not caught by surprise.
234
235== The USB examples are not working on my board, is there anything else I need to configure?
236
237If you are trying out the USB examples and your device doesn not connect, the most common issues are listed below.
238
239=== Incorrect RCC config
240
241Check your board and crystal/oscillator, in particular make sure that `HSE` is set to the correct value, e.g. `8_000_000` Hertz if your board does indeed run on a 8 MHz oscillator.
242
243=== VBUS detection on STM32 platform
244
245The USB specification requires that all USB devices monitor the bus for detection of plugging/unplugging actions. The devices must pull-up the D+ or D- lane as soon as the host supplies VBUS.
246
247See the docs, for example at link:https://docs.embassy.dev/embassy-stm32/git/stm32f401vc/usb/struct.Config.html[`usb/struct.Config.html`] for information on how to enable/disable `vbus_detection`.
248
249When the device is powered only from the USB bus that simultaneously serves as the data connection, this is optional. (If there's no power in VBUS the device would be off anyway, so it's safe to always assume there's power in VBUS, i.e. the USB cable is always plugged in). If your device doesn't have the required connections in place to allow VBUS sensing (see below), then this option needs to be set to `false` to work.
250
251When the device is powered from another power source and therefore can stay powered through USB cable plug/unplug events, then this must be implemented and `vbus_detection` MUST be set to `true`.
252
253If your board is powered from the USB and you are unsure whether it supports `vbus_detection`, consult the schematics of your board to see if VBUS is connected to PA9 for USB Full Speed or PB13 for USB High Speed, vice versa, possibly with a voltage divider. When designing your own hardware, see ST application note AN4879 (in particular section 2.6) and the reference manual of your specific chip for more details.
254
255== Known issues (details and/or mitigations)
256
257These are issues that are commonly reported. Help wanted fixing them, or improving the UX when possible!
258
259=== STM32H5 and STM32H7 power issues
260
261STM32 chips with built-in power management (SMPS and LDO) settings often cause user problems when the configuration does not match how the board was designed.
262
263Settings from the examples, or even from other working boards, may not work on YOUR board, because they are wired differently.
264
265Additionally, some PWR settings require a full device reboot (and enough time to discharge any power capacitors!), making this hard to troubleshoot. Also, some
266"wrong" power settings will ALMOST work, meaning it will sometimes work on some boots, or for a while, but crash unexpectedly.
267
268There is not a fix for this yet, as it is board/hardware dependant. See link:https://github.com/embassy-rs/embassy/issues/2806[this tracking issue] for more details
269
270=== STM32 BDMA only working out of some RAM regions
271
272The STM32 BDMA controller included in some STM32H7 chips has to be configured to use only certain regions of RAM,
273otherwise the transfer will fail.
274
275If you see errors that look like this:
276
277[source,plain]
278----
279DMA: error on BDMA@1234ABCD channel 4
280----
281
282You need to set up your linker script to define a special region for this area and copy data to that region before using with BDMA.
283
284General steps:
285
2861. Find out which memory region BDMA has access to. You can get this information from the bus matrix and the memory mapping table in the STM32 datasheet.
2872. Add the memory region to `memory.x`, you can modify the generated one from https://github.com/embassy-rs/stm32-data-generated/tree/main/data/chips.
2883. You might need to modify `build.rs` to make cargo pick up the modified `memory.x`.
2894. In your code, access the defined memory region using `#[link_section = ".xxx"]`
2905. Copy data to that region before using BDMA.
291
292See link:https://github.com/embassy-rs/embassy/blob/main/examples/stm32h7/src/bin/spi_bdma.rs[SMT32H7 SPI BDMA example] for more details.
293
294== How do I switch to the `main` branch?
295
296Sometimes to test new changes or fixes, you'll want to switch your project to using a version from GitHub.
297
298You can add a section to your `Cargo.toml` file like this, you'll need to patch ALL embassy crates to the same revision:
299
300Using `patch` will replace all direct AND indirect dependencies.
301
302See the link:https://embassy.dev/book/#_starting_a_new_project[new project docs] for more details on this approach.
303
304[source,toml]
305----
306[patch.crates-io]
307# make sure to get the latest git rev from github, you can see the latest one here:
308# https://github.com/embassy-rs/embassy/commits/main/
309embassy-embedded-hal = { git = "https://github.com/embassy-rs/embassy", rev = "4cade64ebd34bf93458f17cfe85c5f710d0ff13c" }
310embassy-executor = { git = "https://github.com/embassy-rs/embassy", rev = "4cade64ebd34bf93458f17cfe85c5f710d0ff13c" }
311embassy-rp = { git = "https://github.com/embassy-rs/embassy", rev = "4cade64ebd34bf93458f17cfe85c5f710d0ff13c" }
312embassy-sync = { git = "https://github.com/embassy-rs/embassy", rev = "4cade64ebd34bf93458f17cfe85c5f710d0ff13c" }
313embassy-time = { git = "https://github.com/embassy-rs/embassy", rev = "4cade64ebd34bf93458f17cfe85c5f710d0ff13c" }
314embassy-usb = { git = "https://github.com/embassy-rs/embassy", rev = "4cade64ebd34bf93458f17cfe85c5f710d0ff13c" }
315embassy-usb-driver = { git = "https://github.com/embassy-rs/embassy", rev = "4cade64ebd34bf93458f17cfe85c5f710d0ff13c" }
316----
317
318== How do I add support for a new microcontroller to embassy?
319
320This is particularly for cortex-m, and potentially risc-v, where there is already support for basics like interrupt handling, or even already embassy-executor support for your architecture.
321
322This is a *much harder path* than just using Embassy on an already supported chip. If you are a beginner, consider using embassy on an existing, well supported chip for a while, before you decide to write drivers from scratch. It's also worth reading the existing source of supported Embassy HALs, to get a feel for how drivers are implemented for various chips. You should already be comfortable reading and writing unsafe code, and understanding the responsibilities of writing safe abstractions for users of your HAL.
323
324This is not the only possible approach, but if you are looking for where to start, this is a reasonable way to tackle the task:
325
3261. First, drop by the Matrix room or search around to see if someone has already started writing drivers, either in Embassy or otherwise in Rust. You might not have to start from scratch!
3272. Make sure the target is supported in probe-rs, it likely is, and if not, there is likely a cmsis-pack you can use to add support so that flashing and debugging is possible. You will definitely appreciate being able to debug with SWD or JTAG when writing drivers!
3283. See if there is an SVD (or SVDs, if it's a family) available, if it is, run it through chiptool to create a PAC for low level register access. If not, there are other ways (like scraping the PDF datasheets or existing C header files), but these are more work than starting from the SVD file to define peripheral memory locations necessary for writing drivers.
3294. Either make a fork of embassy repo, and add your target there, or make a repo that just contains the PAC and an empty HAL. It doesn't necessarily have to live in the embassy repo at first.
3305. Get a hello world binary working on your chip, either with minimal HAL or just PAC access, use delays and blink a light or send some raw data on some interface, make sure it works and you can flash, debug with defmt + RTT, write a proper linker script, etc.
3316. Get basic timer operations and timer interrupts working, upgrade your blinking application to use hardware timers and interrupts, and ensure they are accurate (with a logic analyzer or oscilloscope, if possible).
3327. Implement the embassy-time driver API with your timer and timer interrupt code, so that you can use embassy-time operations in your drivers and applications.
3338. Then start implementing whatever peripherals you need, like GPIOs, UART, SPI, I2C, etc. This is the largest part of the work, and will likely continue for a while! Don't feel like you need 100% coverage of all peripherals at first, this is likely to be an ongoing process over time.
3349. Start implementing the embedded-hal, embedded-io, and embedded-hal-async traits on top of your HAL drivers, once you start having more features completed. This will allow users to use standard external device drivers (e.g. sensors, actuators, displays, etc.) with your HAL.
33510. Discuss upstreaming the PAC/HAL for embassy support, or make sure your drivers are added to the awesome-embedded-rust list so that people can find it.
336
337== Multiple Tasks, or one task with multiple futures?
338
339Some examples end like this in main:
340
341[source,rust]
342----
343// Run everything concurrently.
344// If we had made everything `'static` above instead, we could do this using separate tasks instead.
345join(usb_fut, join(echo_fut, log_fut)).await;
346----
347
348There are two main ways to handle concurrency in Embassy:
349
3501. Spawn multiple tasks, e.g. with `#[embassy_executor::task]`
3512. Manage multiple futures inside ONE task using `join()` or `select()` (as shown above)
352
353In general, either of these approaches will work. The main differences of these approaches are:
354
355When using **separate tasks**, each task needs its own RAM allocation, so there's a little overhead for each task, so one task that does three things will likely be a little bit smaller than three tasks that do one thing (not a lot, probably a couple dozen bytes). In contrast, with **multiple futures in one task**, you don't need multiple task allocations, and it will generally be easier to share data, or use borrowed resources, inside of a single task.
356An example showcasing some methods for sharing things between tasks link:https://github.com/embassy-rs/embassy/blob/main/examples/rp/src/bin/sharing.rs[can be found here].
357
358But when it comes to "waking" tasks, for example when a data transfer is complete or a button is pressed, it's faster to wake a dedicated task, because that task does not need to check which future is actually ready. `join` and `select` must check ALL of the futures they are managing to see which one (or which ones) are ready to do more work. This is because all Rust executors (like Embassy or Tokio) only have the ability to wake tasks, not specific futures. This means you will use slightly less CPU time juggling futures when using dedicated tasks.
359
360Practically, there's not a LOT of difference either way - so go with what makes it easier for you and your code first, but there will be some details that are slightly different in each case.
361
362== splitting peripherals resources between tasks
363
364There are two ways to split resources between tasks, either manually assigned or by a convenient macro. See link:https://github.com/embassy-rs/embassy/blob/main/examples/rp/src/bin/assign_resources.rs[this example]
365
366== My code/driver works in debug mode, but not release mode (or with LTO)
367
368Issues like these while implementing drivers often fall into one of the following general causes, which are a good list of common errors to check for:
369
3701. Some kind of race condition - the faster code means you miss an interrupt or something
3712. Some kind of UB, if you have unsafe code, or something like DMA with fences missing
3723. Some kind of hardware errata, or some hardware misconfiguration like wrong clock speeds
3734. Some issue with an interrupt handler, either enabling, disabling, or re-enabling of interrupts when necessary
3745. Some kind of async issue, like not registering wakers fully before checking flags, or not registering or pending wakers at the right time
diff --git a/docs/modules/ROOT/pages/getting_started.adoc b/docs/pages/getting_started.adoc
index 24bde1c1f..017409018 100644
--- a/docs/modules/ROOT/pages/getting_started.adoc
+++ b/docs/pages/getting_started.adoc
@@ -3,7 +3,7 @@
3So you want to try Embassy, great! To get started, there are a few tools you need to install: 3So you want to try Embassy, great! To get started, there are a few tools you need to install:
4 4
5* link:https://rustup.rs/[rustup] - the Rust toolchain is needed to compile Rust code. 5* link:https://rustup.rs/[rustup] - the Rust toolchain is needed to compile Rust code.
6* 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. 6* 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.
7 7
8If you don't have any supported board, don't worry: you can also run embassy on your PC using the `std` examples. 8If you don't have any supported board, don't worry: you can also run embassy on your PC using the `std` examples.
9 9
@@ -82,19 +82,19 @@ If everything worked correctly, you should see a blinking LED on your board, and
82└─ blinky::__embassy_main::task::{generator#0} @ src/bin/blinky.rs:27 82└─ blinky::__embassy_main::task::{generator#0} @ src/bin/blinky.rs:27
83---- 83----
84 84
85NOTE: 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. 85NOTE: 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.
86 86
87=== It didn’t work! 87=== It didn’t work!
88 88
89If you hare having issues when running `cargo run --release`, please check the following: 89If you hare having issues when running `+cargo run --release+`, please check the following:
90 90
91* You are specifying the correct `--chip` on the command line, OR 91* You are specifying the correct `+--chip+` on the command line, OR
92* You have set `.cargo/config.toml`'s run line to the correct chip, AND 92* You have set `+.cargo/config.toml+`s run line to the correct chip, AND
93* 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) 93* 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)
94 94
95At 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. 95At 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.
96 96
97If you are trying to run an example with `cargo run --release` and you see the following output: 97If you are trying to run an example with `+cargo run --release+` and you see the following output:
98[source] 98[source]
99---- 99----
1000.000000 INFO Hello World! 1000.000000 INFO Hello World!
@@ -115,12 +115,32 @@ To get rid of the frame-index error add the following to your `Cargo.toml`:
115debug = 2 115debug = 2
116---- 116----
117 117
118If 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]. 118If you’re getting an extremely long error message containing something like the following:
119
120[source]
121----
122error[E0463]: can't find crate for `std`
123 |
124 = note: the `thumbv6m-none-eabi` target may not support the standard library
125 = note: `std` is required by `stable_deref_trait` because it does not declare `#![no_std]`
126----
127
128Make 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].
129
130If 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.
131
132If 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].
133
134:embassy-dev-faq-link-with-hash: https://embassy.dev/book/#_frequently_asked_questions
135:embassy-matrix-channel: https://matrix.to/#/#embassy-rs:matrix.org
136
137If you’re still having problems, check the {embassy-dev-faq-link-with-hash}[FAQ], or ask for help in the {embassy-matrix-channel}[Embassy Chat Room].
119 138
120== What's next? 139== What's next?
121 140
122Congratulations, you have your first Embassy application running! Here are some suggestions for where to go from here: 141Congratulations, you have your first Embassy application running! Here are some suggestions for where to go from here:
123 142
124* Read more about the xref:runtime.adoc[executor]. 143* Read more about the xref:_embassy_executor[executor].
125* Read more about the xref:hal.adoc[HAL]. 144* Read more about the xref:_hardware_abstraction_layer_hal[HAL].
126* Start xref:basic_application.adoc[writing your application]. 145* Start xref:_a_basic_embassy_application[writing your application].
146* Learn how to xref:_starting_a_new_project[start a new embassy project by adapting an example].
diff --git a/docs/modules/ROOT/pages/hal.adoc b/docs/pages/hal.adoc
index b1382e8e5..14b85e1f1 100644
--- a/docs/modules/ROOT/pages/hal.adoc
+++ b/docs/pages/hal.adoc
@@ -10,3 +10,5 @@ These HALs implement async/await functionality for most peripherals while also i
10async traits in `embedded-hal` and `embedded-hal-async`. You can also use these HALs with another executor. 10async traits in `embedded-hal` and `embedded-hal-async`. You can also use these HALs with another executor.
11 11
12For the ESP32 series, there is an link:https://github.com/esp-rs/esp-hal[esp-hal] which you can use. 12For the ESP32 series, there is an link:https://github.com/esp-rs/esp-hal[esp-hal] which you can use.
13
14For the WCH 32-bit RISC-V series, there is an link:https://github.com/ch32-rs/ch32-hal[ch32-hal], which you can use.
diff --git a/docs/modules/ROOT/pages/layer_by_layer.adoc b/docs/pages/layer_by_layer.adoc
index 1d7bdc89b..7852d27b7 100644
--- a/docs/modules/ROOT/pages/layer_by_layer.adoc
+++ b/docs/pages/layer_by_layer.adoc
@@ -16,7 +16,7 @@ The blinky app using PAC is shown below:
16 16
17[source,rust] 17[source,rust]
18---- 18----
19include::example$layer-by-layer/blinky-pac/src/main.rs[] 19include::../examples/layer-by-layer/blinky-pac/src/main.rs[]
20---- 20----
21 21
22As you can see, a lot of code is needed to enable the peripheral clocks and to configure the input pins and the output pins of the application. 22As you can see, a lot of code is needed to enable the peripheral clocks and to configure the input pins and the output pins of the application.
@@ -35,7 +35,7 @@ The HAL example is shown below:
35 35
36[source,rust] 36[source,rust]
37---- 37----
38include::example$layer-by-layer/blinky-hal/src/main.rs[] 38include::../examples/layer-by-layer/blinky-hal/src/main.rs[]
39---- 39----
40 40
41As you can see, the application becomes a lot simpler, even without using any async code. The `Input` and `Output` types hide all the details of accessing the GPIO registers and allow you to use a much simpler API for querying the state of the button and toggling the LED output. 41As you can see, the application becomes a lot simpler, even without using any async code. The `Input` and `Output` types hide all the details of accessing the GPIO registers and allow you to use a much simpler API for querying the state of the button and toggling the LED output.
@@ -52,7 +52,7 @@ Given Embassy focus on async Rust (which we'll come back to after this example),
52 52
53[source,rust] 53[source,rust]
54---- 54----
55include::example$layer-by-layer/blinky-irq/src/main.rs[lines="1..57"] 55include::../examples/layer-by-layer/blinky-irq/src/main.rs[lines="1..57"]
56---- 56----
57 57
58The simple application is now more complex again, primarily because of the need to keep the button and LED states in the global scope where it is accessible by the main application loop, as well as the interrupt handler. 58The simple application is now more complex again, primarily because of the need to keep the button and LED states in the global scope where it is accessible by the main application loop, as well as the interrupt handler.
@@ -63,11 +63,11 @@ Luckily, there is an elegant solution to this problem when using Embassy.
63 63
64== Async version 64== Async version
65 65
66It's time to use the Embassy capabilities to its fullest. At the core, Embassy has an async excecutor, or a runtime for async tasks if you will. The executor polls a set of tasks (defined at compile time), and whenever a task `blocks`, the executor will run another task, or put the microcontroller to sleep. 66It's time to use the Embassy capabilities to its fullest. At the core, Embassy has an async executor, or a runtime for async tasks if you will. The executor polls a set of tasks (defined at compile time), and whenever a task `blocks`, the executor will run another task, or put the microcontroller to sleep.
67 67
68[source,rust] 68[source,rust]
69---- 69----
70include::example$layer-by-layer/blinky-async/src/main.rs[] 70include::../examples/layer-by-layer/blinky-async/src/main.rs[]
71---- 71----
72 72
73The async version looks very similar to the HAL version, apart from a few minor details: 73The async version looks very similar to the HAL version, apart from a few minor details:
@@ -76,7 +76,7 @@ The async version looks very similar to the HAL version, apart from a few minor
76* The peripheral initialization is done by the main macro, and is handed to the main task. 76* The peripheral initialization is done by the main macro, and is handed to the main task.
77* Before checking the button state, the application is awaiting a transition in the pin state (low -> high or high -> low). 77* Before checking the button state, the application is awaiting a transition in the pin state (low -> high or high -> low).
78 78
79When `button.await_for_any_edge().await` is called, the executor will pause the main task and put the microcontroller in sleep mode, unless there are other tasks that can run. Internally, the Embassy HAL has configured the interrupt handler for the button (in `ExtiButton`), so that whenever an interrupt is raised, the task awaiting the button will be woken up. 79When `button.await_for_any_edge().await` is called, the executor will pause the main task and put the microcontroller in sleep mode, unless there are other tasks that can run. Internally, the Embassy HAL has configured the interrupt handler for the button (in `ExtiInput`), so that whenever an interrupt is raised, the task awaiting the button will be woken up.
80 80
81The minimal overhead of the executor and the ability to run multiple tasks "concurrently" combined with the enormous simplification of the application, makes `async` a great fit for embedded. 81The minimal overhead of the executor and the ability to run multiple tasks "concurrently" combined with the enormous simplification of the application, makes `async` a great fit for embedded.
82 82
diff --git a/docs/modules/ROOT/pages/new_project.adoc b/docs/pages/new_project.adoc
index 320966bb6..821bcbd27 100644
--- a/docs/modules/ROOT/pages/new_project.adoc
+++ b/docs/pages/new_project.adoc
@@ -1,17 +1,18 @@
1= Starting a new Embassy project 1= Starting a new project
2 2
3Once you’ve successfully xref:getting_started.adoc[run some example projects], the next step is to make a standalone Embassy project. 3Once you’ve successfully xref:#_getting_started[run some example projects], the next step is to make a standalone Embassy project.
4 4
5There are some tools for generating Embassy projects: (WIP) 5== Tools for generating Embassy projects
6 6
7==== CLI 7=== CLI
8- link:https://github.com/adinack/cargo-embassy[cargo-embassy] (STM32 and NRF) 8- link:https://github.com/adinack/cargo-embassy[cargo-embassy] (STM32 and NRF)
9 9
10==== cargo-generate 10=== cargo-generate
11- link:https://github.com/lulf/embassy-template[embassy-template] (STM32, NRF, and RP) 11- link:https://github.com/lulf/embassy-template[embassy-template] (STM32, NRF, and RP)
12- link:https://github.com/bentwire/embassy-rp2040-template[embassy-rp2040-template] (RP) 12- link:https://github.com/bentwire/embassy-rp2040-template[embassy-rp2040-template] (RP)
13 13
14But if you want to start from scratch: 14
15== Starting a project from scratch
15 16
16As 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. 17As 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.
17 18
@@ -35,7 +36,7 @@ stm32g474-example
35 36
36Looking in link:https://github.com/embassy-rs/embassy/tree/main/examples[the Embassy examples], we can see there’s a `stm32g4` folder. Find `src/blinky.rs` and copy its contents into our `src/main.rs`. 37Looking in link:https://github.com/embassy-rs/embassy/tree/main/examples[the Embassy examples], we can see there’s a `stm32g4` folder. Find `src/blinky.rs` and copy its contents into our `src/main.rs`.
37 38
38== .cargo/config.toml 39=== The .cargo/config.toml
39 40
40Currently, we’d need to provide cargo with a target triple every time we run `cargo build` or `cargo run`. Let’s spare ourselves that work by copying `.cargo/config.toml` from `examples/stm32g4` into our project. 41Currently, we’d need to provide cargo with a target triple every time we run `cargo build` or `cargo run`. Let’s spare ourselves that work by copying `.cargo/config.toml` from `examples/stm32g4` into our project.
41 42
@@ -66,7 +67,7 @@ and copying `STM32G474RETx` into `.cargo/config.toml` as so:
66runner = "probe-rs run --chip STM32G474RETx" 67runner = "probe-rs run --chip STM32G474RETx"
67---- 68----
68 69
69== Cargo.toml 70=== Cargo.toml
70 71
71Now that cargo knows what target to compile for (and probe-rs knows what chip to run it on), we’re ready to add some dependencies. 72Now that cargo knows what target to compile for (and probe-rs knows what chip to run it on), we’re ready to add some dependencies.
72 73
@@ -117,7 +118,7 @@ Finally, copy the `[profile.release]` section from the example `Cargo.toml` into
117debug = 2 118debug = 2
118---- 119----
119 120
120== rust-toolchain.toml 121=== rust-toolchain.toml
121 122
122Before we can build our project, we need to add an additional file to tell cargo to use the nightly toolchain. Copy the `rust-toolchain.toml` from the embassy repo to ours, and trim the list of targets down to only the target triple relevent for our project — in this case, `thumbv7em-none-eabi`: 123Before we can build our project, we need to add an additional file to tell cargo to use the nightly toolchain. Copy the `rust-toolchain.toml` from the embassy repo to ours, and trim the list of targets down to only the target triple relevent for our project — in this case, `thumbv7em-none-eabi`:
123 124
@@ -142,7 +143,7 @@ components = [ "rust-src", "rustfmt", "llvm-tools", "miri" ]
142targets = ["thumbv7em-none-eabi"] 143targets = ["thumbv7em-none-eabi"]
143---- 144----
144 145
145== build.rs 146=== build.rs
146 147
147In order to produce a working binary for our target, cargo requires a custom build script. Copy `build.rs` from the example to our project: 148In order to produce a working binary for our target, cargo requires a custom build script. Copy `build.rs` from the example to our project:
148 149
@@ -158,7 +159,7 @@ stm32g474-example
158 └── main.rs 159 └── main.rs
159---- 160----
160 161
161== Building and running 162=== Building and running
162 163
163At this point, we‘re finally ready to build and run our project! Connect your board via a debug probe and run: 164At this point, we‘re finally ready to build and run our project! Connect your board via a debug probe and run:
164 165
diff --git a/docs/modules/ROOT/pages/nrf.adoc b/docs/pages/nrf.adoc
index 1706087ae..de052b63f 100644
--- a/docs/modules/ROOT/pages/nrf.adoc
+++ b/docs/pages/nrf.adoc
@@ -1,6 +1,6 @@
1= Embassy nRF HAL 1= Embassy nRF HAL
2 2
3The link:https://github.com/embassy-rs/embassy/tree/master/embassy-nrf[Embassy nRF HAL] is based on the PACs (Peripheral Access Crate) from link:https://github.com/nrf-rs/[nrf-rs]. 3The link:https://github.com/embassy-rs/embassy/tree/main/embassy-nrf[Embassy nRF HAL] is based on the PACs (Peripheral Access Crate) from link:https://github.com/nrf-rs/[nrf-rs].
4 4
5== Timer driver 5== Timer driver
6 6
diff --git a/docs/modules/ROOT/pages/index.adoc b/docs/pages/overview.adoc
index e17adbbd7..2ebc85f6d 100644
--- a/docs/modules/ROOT/pages/index.adoc
+++ b/docs/pages/overview.adoc
@@ -1,4 +1,4 @@
1= Embassy 1= Introduction
2 2
3Embassy is a project to make async/await a first-class option for embedded development. 3Embassy is a project to make async/await a first-class option for embedded development.
4 4
@@ -30,6 +30,7 @@ The Embassy project maintains HALs for select hardware, but you can still use HA
30* link:https://docs.embassy.dev/embassy-nrf/[embassy-nrf], for the Nordic Semiconductor nRF52, nRF53, nRF91 series. 30* link:https://docs.embassy.dev/embassy-nrf/[embassy-nrf], for the Nordic Semiconductor nRF52, nRF53, nRF91 series.
31* link:https://docs.embassy.dev/embassy-rp/[embassy-rp], for the Raspberry Pi RP2040 microcontroller. 31* link:https://docs.embassy.dev/embassy-rp/[embassy-rp], for the Raspberry Pi RP2040 microcontroller.
32* link:https://github.com/esp-rs[esp-rs], for the Espressif Systems ESP32 series of chips. 32* link:https://github.com/esp-rs[esp-rs], for the Espressif Systems ESP32 series of chips.
33* link:https://github.com/ch32-rs/ch32-hal[ch32-hal], for the WCH 32-bit RISC-V(CH32V) series of chips.
33 34
34NOTE: A common question is if one can use the Embassy HALs standalone. Yes, it is possible! There are no dependency on the executor within the HALs. You can even use them without async, 35NOTE: A common question is if one can use the Embassy HALs standalone. Yes, it is possible! There are no dependency on the executor within the HALs. You can even use them without async,
35as they implement both the link:https://github.com/rust-embedded/embedded-hal[Embedded HAL] blocking and async traits. 36as they implement both the link:https://github.com/rust-embedded/embedded-hal[Embedded HAL] blocking and async traits.
@@ -47,7 +48,7 @@ link:https://github.com/lora-rs/lora-rs[lora-rs] supports LoRa networking on a w
47link: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. 48link: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.
48 49
49=== Bootloader and DFU 50=== Bootloader and DFU
50link:https://github.com/embassy-rs/embassy/tree/master/embassy-boot[embassy-boot] is a lightweight bootloader supporting firmware application upgrades in a power-fail-safe way, with trial boots and rollbacks. 51link:https://github.com/embassy-rs/embassy/tree/main/embassy-boot[embassy-boot] is a lightweight bootloader supporting firmware application upgrades in a power-fail-safe way, with trial boots and rollbacks.
51 52
52== What is DMA? 53== What is DMA?
53 54
@@ -55,6 +56,20 @@ For most I/O in embedded devices, the peripheral doesn't directly support the tr
55 56
56The Direct Memory Access controller (DMA) is a controller that is present in MCUs that Embassy supports, including stm32 and nrf. The DMA allows the MCU to set up a transfer, either send or receive, and then wait for the transfer to complete. With DMA, once started, no MCU intervention is required until the transfer is complete, meaning that the MCU can perform other computation, or set up other I/O while the transfer is in progress. For high I/O rates, DMA can cut the time that the MCU spends handling I/O by over half. However, because DMA is more complex to set-up, it is less widely used in the embedded community. Embassy aims to change that by making DMA the first choice rather than the last. Using Embassy, there's no additional tuning required once I/O rates increase because your application is already set-up to handle them. 57The Direct Memory Access controller (DMA) is a controller that is present in MCUs that Embassy supports, including stm32 and nrf. The DMA allows the MCU to set up a transfer, either send or receive, and then wait for the transfer to complete. With DMA, once started, no MCU intervention is required until the transfer is complete, meaning that the MCU can perform other computation, or set up other I/O while the transfer is in progress. For high I/O rates, DMA can cut the time that the MCU spends handling I/O by over half. However, because DMA is more complex to set-up, it is less widely used in the embedded community. Embassy aims to change that by making DMA the first choice rather than the last. Using Embassy, there's no additional tuning required once I/O rates increase because your application is already set-up to handle them.
57 58
59== Examples
60
61Embassy provides examples for all HALs supported. You can find them in the `examples/` folder.
62
63
64Main loop example
65
66[source,rust]
67----
68include::../examples/examples/std/src/bin/tick.rs[]
69----
70
71include::embassy_in_the_wild.adoc[leveloffset = 2]
72
58== Resources 73== Resources
59 74
60For more reading material on async Rust and Embassy: 75For more reading material on async Rust and Embassy:
@@ -62,3 +77,7 @@ For more reading material on async Rust and Embassy:
62* link:https://tweedegolf.nl/en/blog/65/async-rust-vs-rtos-showdown[Comparsion of FreeRTOS and Embassy] 77* link:https://tweedegolf.nl/en/blog/65/async-rust-vs-rtos-showdown[Comparsion of FreeRTOS and Embassy]
63* link:https://dev.to/apollolabsbin/series/20707[Tutorials] 78* link:https://dev.to/apollolabsbin/series/20707[Tutorials]
64* link:https://blog.drogue.io/firmware-updates-part-1/[Firmware Updates with Embassy] 79* link:https://blog.drogue.io/firmware-updates-part-1/[Firmware Updates with Embassy]
80
81Videos:
82
83* link:https://www.youtube.com/watch?v=wni5h5vIPhU[From Zero to Async in Embedded Rust] \ No newline at end of file
diff --git a/docs/modules/ROOT/pages/project_structure.adoc b/docs/pages/project_structure.adoc
index 2adfcc1df..722ec8d9d 100644
--- a/docs/modules/ROOT/pages/project_structure.adoc
+++ b/docs/pages/project_structure.adoc
@@ -18,6 +18,7 @@ my-project
18|- rust-toolchain.toml 18|- rust-toolchain.toml
19---- 19----
20 20
21[discrete]
21== .cargo/config.toml 22== .cargo/config.toml
22 23
23This 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. 24This 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,21 +37,27 @@ target = "thumbv6m-none-eabi" # <-change for your platform
36DEFMT_LOG = "trace" # <- can change to info, warn, or error 37DEFMT_LOG = "trace" # <- can change to info, warn, or error
37---- 38----
38 39
40[discrete]
39== build.rs 41== build.rs
40 42
41This 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]. 43This 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].
42 44
45[discrete]
43== Cargo.toml 46== Cargo.toml
44 47
45This is your manifest file, where you can configure all of the embassy components to use the features you need. 48This is your manifest file, where you can configure all of the embassy components to use the features you need.
46 49
47==== Features 50[discrete]
48===== Time 51=== Features
52
53[discrete]
54==== Time
49- tick-hz-x: Configures the tick rate of `embassy-time`. Higher tick rate means higher precision, and higher CPU wakes. 55- tick-hz-x: Configures the tick rate of `embassy-time`. Higher tick rate means higher precision, and higher CPU wakes.
50- defmt-timestamp-uptime: defmt log entries will display the uptime in seconds. 56- defmt-timestamp-uptime: defmt log entries will display the uptime in seconds.
51 57
52...more to come 58...more to come
53 59
60[discrete]
54== memory.x 61== memory.x
55 62
56This 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. 63This 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.
@@ -68,6 +75,7 @@ MEMORY
68} 75}
69---- 76----
70 77
78[discrete]
71== rust-toolchain.toml 79== rust-toolchain.toml
72 80
73This file configures the rust version and configuration to use. 81This file configures the rust version and configuration to use.
diff --git a/docs/modules/ROOT/pages/runtime.adoc b/docs/pages/runtime.adoc
index f2812dd7c..f2812dd7c 100644
--- a/docs/modules/ROOT/pages/runtime.adoc
+++ b/docs/pages/runtime.adoc
diff --git a/docs/modules/ROOT/pages/sharing_peripherals.adoc b/docs/pages/sharing_peripherals.adoc
index fcba0e27b..dfb8c1ffe 100644
--- a/docs/modules/ROOT/pages/sharing_peripherals.adoc
+++ b/docs/pages/sharing_peripherals.adoc
@@ -8,6 +8,7 @@ The following examples shows different ways to use the on-board LED on a Raspber
8 8
9Using mutual exclusion is the simplest way to share a peripheral. 9Using mutual exclusion is the simplest way to share a peripheral.
10 10
11TIP: Dependencies needed to run this example link:#_the_cargo_toml[can be found here].
11[,rust] 12[,rust]
12---- 13----
13use defmt::*; 14use defmt::*;
@@ -77,6 +78,7 @@ To indicate that the pin will be set to an Output. The `AnyPin` could have been
77 78
78A 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. 79A 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.
79 80
81TIP: Dependencies needed to run this example link:#_the_cargo_toml[can be found here].
80[,rust] 82[,rust]
81---- 83----
82use defmt::*; 84use defmt::*;
@@ -123,4 +125,10 @@ async fn toggle_led(control: Sender<'static, ThreadModeRawMutex, LedState, 64>,
123---- 125----
124 126
125This 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 127This 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
126that the operation is ecompleted before continuing to do other work in your task. 128that the operation is completed before continuing to do other work in your task.
129
130An example showcasing more methods for sharing link:https://github.com/embassy-rs/embassy/blob/main/examples/rp/src/bin/sharing.rs[can be found here].
131
132== Sharing an I2C or SPI bus between multiple devices
133
134An example of how to deal with multiple devices sharing a common I2C or SPI bus link:https://github.com/embassy-rs/embassy/blob/main/examples/rp/src/bin/shared_bus.rs[can be found here].
diff --git a/docs/modules/ROOT/pages/stm32.adoc b/docs/pages/stm32.adoc
index 7bfc0592b..df139a420 100644
--- a/docs/modules/ROOT/pages/stm32.adoc
+++ b/docs/pages/stm32.adoc
@@ -1,6 +1,6 @@
1= Embassy STM32 HAL 1= Embassy STM32 HAL
2 2
3The link:https://github.com/embassy-rs/embassy/tree/master/embassy-stm32[Embassy STM32 HAL] is based on the `stm32-metapac` project. 3The link:https://github.com/embassy-rs/embassy/tree/main/embassy-stm32[Embassy STM32 HAL] is based on the `stm32-metapac` project.
4 4
5== The infinite variant problem 5== The infinite variant problem
6 6
diff --git a/docs/pages/system.adoc b/docs/pages/system.adoc
new file mode 100644
index 000000000..985f92b18
--- /dev/null
+++ b/docs/pages/system.adoc
@@ -0,0 +1,13 @@
1= System description
2
3This section describes different parts of Embassy in more detail.
4
5include::runtime.adoc[leveloffset = 2]
6include::bootloader.adoc[leveloffset = 2]
7include::time_keeping.adoc[leveloffset = 2]
8include::hal.adoc[leveloffset = 2]
9include::nrf.adoc[leveloffset = 2]
10include::stm32.adoc[leveloffset = 2]
11include::sharing_peripherals.adoc[leveloffset = 2]
12include::developer.adoc[leveloffset = 2]
13include::developer_stm32.adoc[leveloffset = 2]
diff --git a/docs/modules/ROOT/pages/time_keeping.adoc b/docs/pages/time_keeping.adoc
index 5068216ed..11ddb2b2b 100644
--- a/docs/modules/ROOT/pages/time_keeping.adoc
+++ b/docs/pages/time_keeping.adoc
@@ -16,6 +16,7 @@ The `embassy::time::Timer` type provides two timing methods.
16 16
17An example of a delay is provided as follows: 17An example of a delay is provided as follows:
18 18
19TIP: Dependencies needed to run this example link:#_the_cargo_toml[can be found here].
19[,rust] 20[,rust]
20---- 21----
21use embassy::executor::{task, Executor}; 22use embassy::executor::{task, Executor};
@@ -40,6 +41,7 @@ that expect a generic delay implementation to be provided.
40 41
41An example of how this can be used: 42An example of how this can be used:
42 43
44TIP: Dependencies needed to run this example link:#_the_cargo_toml[can be found here].
43[,rust] 45[,rust]
44---- 46----
45use embassy::executor::{task, Executor}; 47use embassy::executor::{task, Executor};