aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2023-11-27 18:59:53 +0000
committerGitHub <[email protected]>2023-11-27 18:59:53 +0000
commit3a8a950bb8e8c8054aeb1338d17a3fa2e14c1b58 (patch)
treebad965647d995d14529f07f80375bc39ad1e2940
parente5fdd35bd680b30b03372d44f8b29129a8f49f3e (diff)
parent02305451b1893924effa8d036a0d379ed485a364 (diff)
Merge pull request #2226 from AdinAck/faq-update-1
FAQ Update (1)
-rw-r--r--docs/modules/ROOT/nav.adoc1
-rw-r--r--docs/modules/ROOT/pages/faq.adoc44
-rw-r--r--docs/modules/ROOT/pages/project_structure.adoc80
3 files changed, 125 insertions, 0 deletions
diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc
index 7e178df62..13459099f 100644
--- a/docs/modules/ROOT/nav.adoc
+++ b/docs/modules/ROOT/nav.adoc
@@ -1,5 +1,6 @@
1* xref:getting_started.adoc[Getting started] 1* xref:getting_started.adoc[Getting started]
2** xref:basic_application.adoc[Basic application] 2** xref:basic_application.adoc[Basic application]
3** xref:project_structure.adoc[Project Structure]
3* xref:layer_by_layer.adoc[Bare metal to async] 4* xref:layer_by_layer.adoc[Bare metal to async]
4* xref:runtime.adoc[Executor] 5* xref:runtime.adoc[Executor]
5* xref:hal.adoc[HAL] 6* xref:hal.adoc[HAL]
diff --git a/docs/modules/ROOT/pages/faq.adoc b/docs/modules/ROOT/pages/faq.adoc
index 6032985fc..2994c6278 100644
--- a/docs/modules/ROOT/pages/faq.adoc
+++ b/docs/modules/ROOT/pages/faq.adoc
@@ -36,3 +36,47 @@ For Cortex-M targets, consider making sure that ALL of the following features ar
36* `nightly` 36* `nightly`
37 37
38For Xtensa ESP32, consider using the executors and `#[main]` macro provided by your appropriate link:https://crates.io/crates/esp-hal-common[HAL crate]. 38For Xtensa ESP32, consider using the executors and `#[main]` macro provided by your appropriate link:https://crates.io/crates/esp-hal-common[HAL crate].
39
40== Why is my binary so big?
41
42The first step to managing your binary size is to set up your link:https://doc.rust-lang.org/cargo/reference/profiles.html[profiles].
43
44[source,toml]
45----
46[profile.release]
47debug = false
48lto = true
49opt-level = "s"
50incremental = true
51----
52
53All of these flags are elaborated on in the Rust Book page linked above.
54
55=== My binary is still big... filled with `std::fmt` stuff!
56
57This 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`.
58
59You can remedy this by adding the following to your `.cargo/config.toml`:
60
61[source,toml]
62----
63[unstable]
64build-std = ["core"]
65build-std-features = ["panic_immediate_abort"]
66----
67
68This replaces all panics with a `UDF` (undefined) instruction.
69
70Depending on your chipset, this will exhibit different behavior.
71
72Refer to the spec for your chipset, but for `thumbv6m`, it results in a hardfault. Which can be configured like so:
73
74[source,rust]
75----
76#[exception]
77unsafe fn HardFault(_frame: &ExceptionFrame) -> ! {
78 SCB::sys_reset() // <- you could do something other than reset
79}
80----
81
82Refer to cortex-m's link:https://docs.rs/cortex-m-rt/latest/cortex_m_rt/attr.exception.html[exception handling] for more info.
diff --git a/docs/modules/ROOT/pages/project_structure.adoc b/docs/modules/ROOT/pages/project_structure.adoc
new file mode 100644
index 000000000..3e6008ec4
--- /dev/null
+++ b/docs/modules/ROOT/pages/project_structure.adoc
@@ -0,0 +1,80 @@
1= Project Structure
2
3There are many ways to configure embassy and its components for your exact application. The link:https://github.com/embassy-rs/embassy/tree/main/examples[examples] directory for each chipset demonstrates how your project structure should look. Let's break it down:
4
5The toplevel file structure of your project should look like this:
6[source,plain]
7----
8{} = Maybe
9
10my-project
11|- .cargo
12| |- config.toml
13|- src
14| |- main.rs
15|- build.rs
16|- Cargo.toml
17|- {memory.x}
18|- rust-toolchain.toml
19----
20
21=== .cargo/config.toml
22
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.
24
25Here is a minimal example:
26
27[source,toml]
28----
29[target.thumbv6m-none-eabi] # <-change for your platform
30runner = 'probe-rs run --chip STM32F031K6Tx' # <- change for your chip
31
32[build]
33target = "thumbv6m-none-eabi" # <-change for your platform
34
35[env]
36DEFMT_LOG = "trace" # <- can change to info, warn, or error
37----
38
39=== build.rs
40
41This is the build script for your project. It links defmt (what is defmt?) and the `memory.x` file if needed. This file is pretty specific for each chipset, just copy and paste from the corresponding link:https://github.com/embassy-rs/embassy/tree/main/examples[example].
42
43=== Cargo.toml
44
45This is your manifest file, where you can configure all of the embassy components to use the features you need.
46
47TODO: someone should exhaustively describe every feature for every component!
48
49=== memory.x
50
51This 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.
52
53Here is an example for using S140 with an nRF52840:
54
55[source,x]
56----
57MEMORY
58{
59 /* NOTE 1 K = 1 KiBi = 1024 bytes */
60 /* These values correspond to the NRF52840 with Softdevices S140 7.0.1 */
61 FLASH : ORIGIN = 0x00027000, LENGTH = 868K
62 RAM : ORIGIN = 0x20020000, LENGTH = 128K
63}
64----
65
66=== rust-toolchain.toml
67
68This file configures the rust version and configuration to use.
69
70A minimal example:
71
72[source,toml]
73----
74[toolchain]
75channel = "nightly-2023-08-19" # <- as of writing, this is the exact rust version embassy uses
76components = [ "rust-src", "rustfmt" ] # <- optionally add "llvm-tools-preview" for some extra features like "cargo size"
77targets = [
78 "thumbv6m-none-eabi" # <-change for your platform
79]
80----