diff options
| author | Adin Ackerman <[email protected]> | 2023-11-27 10:23:42 -0800 |
|---|---|---|
| committer | Adin Ackerman <[email protected]> | 2023-11-27 10:23:42 -0800 |
| commit | 5844f5ce2d704058312ea607eb976e438ad990cb (patch) | |
| tree | 600163c6d0491365fc91274f81f3c67882edec96 | |
| parent | e5fdd35bd680b30b03372d44f8b29129a8f49f3e (diff) | |
Update faq.adoc
| -rw-r--r-- | docs/modules/ROOT/pages/faq.adoc | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/docs/modules/ROOT/pages/faq.adoc b/docs/modules/ROOT/pages/faq.adoc index 6032985fc..2d49b68a6 100644 --- a/docs/modules/ROOT/pages/faq.adoc +++ b/docs/modules/ROOT/pages/faq.adoc | |||
| @@ -4,6 +4,87 @@ These are a list of unsorted, commonly asked questions and answers. | |||
| 4 | 4 | ||
| 5 | Please 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! | 5 | Please 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 | 6 | ||
| 7 | == How do I even start? | ||
| 8 | |||
| 9 | There are many ways to configure embassy and it's components for your exact application. The link:https://github.com/embassy-rs/embassy/tree/main/examples[examples] directory for each chipset demonstrate how your project structure should look. Let's break it down: | ||
| 10 | |||
| 11 | The toplevel file structure of your project should look like this: | ||
| 12 | [source,plain] | ||
| 13 | ---- | ||
| 14 | {} = Maybe | ||
| 15 | |||
| 16 | my-project | ||
| 17 | |- .cargo | ||
| 18 | | |- config.toml | ||
| 19 | |- src | ||
| 20 | | |- main.rs | ||
| 21 | |- build.rs | ||
| 22 | |- Cargo.toml | ||
| 23 | |- {memory.x} | ||
| 24 | |- rust-toolchain.toml | ||
| 25 | ---- | ||
| 26 | |||
| 27 | === .cargo/config.toml | ||
| 28 | |||
| 29 | This directory/file describes what platform you're on, and configures link:https://github.com/probe-rs/probe-rs[probe-rs] to deploy to your device. | ||
| 30 | |||
| 31 | Here is a minimal example: | ||
| 32 | |||
| 33 | [source,toml] | ||
| 34 | ---- | ||
| 35 | [target.thumbv6m-none-eabi] # <-change for your platform | ||
| 36 | runner = 'probe-rs run --chip STM32F031K6Tx' # <- change for your chip | ||
| 37 | |||
| 38 | [build] | ||
| 39 | target = "thumbv6m-none-eabi" # <-change for your platform | ||
| 40 | |||
| 41 | [env] | ||
| 42 | DEFMT_LOG = "trace" # <- can change to info, warn, or error | ||
| 43 | ---- | ||
| 44 | |||
| 45 | === build.rs | ||
| 46 | |||
| 47 | This is the build script for your project. It links defmt (what is defmt?) and the `memory.x` file if need be. 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]. | ||
| 48 | |||
| 49 | === Cargo.toml | ||
| 50 | |||
| 51 | This is your manifest file, where you can configure all of the embassy components to use the features you need. | ||
| 52 | |||
| 53 | TODO: someone should exhaustively describe every feature for every component! | ||
| 54 | |||
| 55 | === memory.x | ||
| 56 | |||
| 57 | This file outlines the flash/ram usage of your program. It is especially useful when using link:https://github.com/embassy-rs/nrf-softdevice[nrf-softdevice] on an nRF5x. | ||
| 58 | |||
| 59 | Here is an example for using S140 with an nRF52840: | ||
| 60 | |||
| 61 | [source,x] | ||
| 62 | ---- | ||
| 63 | MEMORY | ||
| 64 | { | ||
| 65 | /* NOTE 1 K = 1 KiBi = 1024 bytes */ | ||
| 66 | /* These values correspond to the NRF52840 with Softdevices S140 7.0.1 */ | ||
| 67 | FLASH : ORIGIN = 0x00027000, LENGTH = 868K | ||
| 68 | RAM : ORIGIN = 0x20020000, LENGTH = 128K | ||
| 69 | } | ||
| 70 | ---- | ||
| 71 | |||
| 72 | === rust-toolchain.toml | ||
| 73 | |||
| 74 | This file configures the rust version and configuration to use. | ||
| 75 | |||
| 76 | A minimal example: | ||
| 77 | |||
| 78 | [source,toml] | ||
| 79 | ---- | ||
| 80 | [toolchain] | ||
| 81 | channel = "nightly-2023-08-19" # <- as of writing, this is the exact rust version embassy uses | ||
| 82 | components = [ "rust-src", "rustfmt" ] # <- optionally add "llvm-tools-preview" for some extra features like "cargo size" | ||
| 83 | targets = [ | ||
| 84 | "thumbv6m-none-eabi" # <-change for your platform | ||
| 85 | ] | ||
| 86 | ---- | ||
| 87 | |||
| 7 | == How to deploy to RP2040 without a debugging probe. | 88 | == How to deploy to RP2040 without a debugging probe. |
| 8 | 89 | ||
| 9 | Install link:https://github.com/JoNil/elf2uf2-rs[elf2uf2-rs] for converting the generated elf binary into a uf2 file. | 90 | Install link:https://github.com/JoNil/elf2uf2-rs[elf2uf2-rs] for converting the generated elf binary into a uf2 file. |
| @@ -36,3 +117,47 @@ For Cortex-M targets, consider making sure that ALL of the following features ar | |||
| 36 | * `nightly` | 117 | * `nightly` |
| 37 | 118 | ||
| 38 | For Xtensa ESP32, consider using the executors and `#[main]` macro provided by your appropriate link:https://crates.io/crates/esp-hal-common[HAL crate]. | 119 | For Xtensa ESP32, consider using the executors and `#[main]` macro provided by your appropriate link:https://crates.io/crates/esp-hal-common[HAL crate]. |
| 120 | |||
| 121 | == Why is my binary so big? | ||
| 122 | |||
| 123 | The first step to managing your binary size is to set up your link:https://doc.rust-lang.org/cargo/reference/profiles.html[profiles]. | ||
| 124 | |||
| 125 | [source,toml] | ||
| 126 | ---- | ||
| 127 | [profile.release] | ||
| 128 | debug = false | ||
| 129 | lto = true | ||
| 130 | opt-level = "s" | ||
| 131 | incremental = true | ||
| 132 | ---- | ||
| 133 | |||
| 134 | All of these flags are elaborated on in the Rust Book page linked above. | ||
| 135 | |||
| 136 | === My binary is still big... filled with `std::fmt` stuff! | ||
| 137 | |||
| 138 | This 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`. | ||
| 139 | |||
| 140 | You can remedy this by adding the following to your `.cargo/config.toml`: | ||
| 141 | |||
| 142 | [source,toml] | ||
| 143 | ---- | ||
| 144 | [unstable] | ||
| 145 | build-std = ["core"] | ||
| 146 | build-std-features = ["panic_immediate_abort"] | ||
| 147 | ---- | ||
| 148 | |||
| 149 | This replaces all panics with a `UDF` (undefined) instruction. | ||
| 150 | |||
| 151 | Depending on your chipset, this will exhibit different behavior. | ||
| 152 | |||
| 153 | Refer to the spec for your chipset, but for `thumbv6m`, it results in a hardfault. Which can be configured like so: | ||
| 154 | |||
| 155 | [source,rust] | ||
| 156 | ---- | ||
| 157 | #[exception] | ||
| 158 | unsafe fn HardFault(_frame: &ExceptionFrame) -> ! { | ||
| 159 | SCB::sys_reset() // <- you could do something other than reset | ||
| 160 | } | ||
| 161 | ---- | ||
| 162 | |||
| 163 | Refer to cortex-m's link:https://docs.rs/cortex-m-rt/latest/cortex_m_rt/attr.exception.html[exception handling] for more info. | ||
