|
26 | 26 |
|
27 | 27 | </p>
|
28 | 28 |
|
29 |
| -# Bazel Rust Embedded Tools |
| 29 | +# Rust Embedded Tools |
30 | 30 |
|
31 | 31 | This repository contains useful, cross-platform embedded tools that work out of the box in any Bazel project.
|
32 | 32 |
|
@@ -57,6 +57,21 @@ rust_embedded_deps()
|
57 | 57 |
|
58 | 58 | Head to the [Releases](https://github.com/d-asnaghi/bazel-rust-embedded/releases) page for more specific `WORKSPACE` settings
|
59 | 59 |
|
| 60 | +## Dependencies |
| 61 | + |
| 62 | +At the moment, this is still a pre-release project. The build is not completely hermetic (it will be in the future) and requires to install the following dependencies based on your operating system |
| 63 | + |
| 64 | +### Linux |
| 65 | + |
| 66 | +`sudo apt install -y pkg-config libusb-1.0-0-dev libftdi1-dev` |
| 67 | +### Windows |
| 68 | + |
| 69 | +`vcpkg install libftdi1:x64-windows-static-md libusb:x64-windows-static-md` |
| 70 | + |
| 71 | +## Examples |
| 72 | + |
| 73 | +Head to the [examples](examples) directory where you can see how to use the rules in this repo to flash and debug ARM firmware targets using a custom toolchain. |
| 74 | + |
60 | 75 | ## [Cargo Flash](https://crates.io/crates/cargo-flash)
|
61 | 76 |
|
62 | 77 | You can use cargo flash to load binaries or elf files to any target that uses a supported probe (JLink, STLink, Etc).
|
@@ -95,5 +110,64 @@ cargo_flash(
|
95 | 110 | ```
|
96 | 111 |
|
97 | 112 | Then `bazel run //package:flash_elf` and `bazel run //package:flash_bin` will load the file to the target
|
| 113 | +## [Cargo Embed](https://crates.io/crates/cargo-embed) |
| 114 | + |
| 115 | +Cargo embed is a more powerful version of cargo-flash. It can be used to start a gdb server after flashing the probe. You have an option to specify a custom config to feed into cargo flash for maximum configurability. |
| 116 | + |
| 117 | +That config can also be an actual `.toml` file if you would rather have even more options. |
98 | 118 |
|
| 119 | +```python |
| 120 | +# package/BUILD |
99 | 121 |
|
| 122 | +load("@rust_embedded//:rules.bzl", "cargo_embed_config", "cargo_embed") |
| 123 | + |
| 124 | +cc_binary( |
| 125 | + name = "firmware_elf", |
| 126 | + ... |
| 127 | +) |
| 128 | + |
| 129 | +cargo_emebd_config( |
| 130 | + name = "config", |
| 131 | + flash = "true", |
| 132 | + halt = "true", |
| 133 | + gdb_enabled = "true", |
| 134 | +) |
| 135 | + |
| 136 | +cargo_embed( |
| 137 | + name = "flash_debug", |
| 138 | + file = ":firmware_elf", |
| 139 | + chip = "STM32F103C8", |
| 140 | + custom_config = ":config", |
| 141 | +) |
| 142 | +``` |
| 143 | + |
| 144 | +# GDB targets |
| 145 | + |
| 146 | +Cargo embed exposes a GDB server, which can be connected to. For convenience, there are rules that specifically instantiate a GDB server and even launch the console for you. |
| 147 | + |
| 148 | +```python |
| 149 | +# package/BUILD |
| 150 | + |
| 151 | +load("@rust_embedded//:rules.bzl", "gdb_server", "gdb_console") |
| 152 | + |
| 153 | +cc_binary( |
| 154 | + name = "firmware_elf", |
| 155 | + ... |
| 156 | +) |
| 157 | + |
| 158 | +gdb_server( |
| 159 | + name = "gdb-server", |
| 160 | + file = ":firmware", |
| 161 | + chip = "STM32F103C8", |
| 162 | +) |
| 163 | + |
| 164 | +gdb_console( |
| 165 | + name = "gdb-console", |
| 166 | + file = ":firmware_elf", |
| 167 | + chip = "STM32F103C8", |
| 168 | + gdb = "<label to gdb binary>", |
| 169 | + gdb_commands = [ |
| 170 | + "b main", |
| 171 | + ] |
| 172 | +) |
| 173 | +``` |
0 commit comments