Skip to content

Commit ce4cf5d

Browse files
committed
Add Update .cargo/config sub-section
Also, added a note that .cargo/config may need to be modified in every chapter.
1 parent bf1049e commit ce4cf5d

File tree

2 files changed

+73
-2
lines changed

2 files changed

+73
-2
lines changed

src/05-led-roulette/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ point function must have signature `fn() -> !`; this type indicates that the fun
4444
If you are a careful observer, you'll also notice there is a `.cargo` directory in the Cargo project
4545
as well. This directory contains a Cargo configuration file (`.cargo/config`) that tweaks the
4646
linking process to tailor the memory layout of the program to the requirements of the target device.
47-
This modified linking process is a requirement of the `cortex-m-rt` crate.
47+
This modified linking process is a requirement of the `cortex-m-rt` crate. You'll also be making
48+
further tweaks to `.cargo/config` in future sections to make building and debugging easier.
4849

4950
Alright, let's start by building this program.

src/05-led-roulette/flash-it.md

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,80 @@ In both failing and successful cases you should see new output in the **OpenOCD
140140
By default OpenOCD's GDB server listens on TCP port 3333 (localhost). This command is connecting to
141141
that port.
142142

143+
## Update .cargo/config
144+
145+
Now that you've successfully determined which debugger you need to use
146+
we need to change `.cargo/config` so that `cargo run` command can succeed.
147+
148+
Get back to the terminal prompt and looking at `.cargo/config`:
149+
``` console
150+
$ cat .cargo/config
151+
[target.thumbv7em-none-eabihf]
152+
runner = "arm-none-eabi-gdb -q"
153+
rustflags = [
154+
"-C", "link-arg=-Tlink.x",
155+
]
156+
157+
```
158+
Use your favorite editor to edit `.cargo/config` so that the
159+
runner line contains the name of that debugger:
160+
``` console
161+
nano .cargo/config
162+
```
163+
For example, if your debugger was `gdb-multiarch` then after
164+
editing you should have:
165+
``` console
166+
$ cat .cargo/config
167+
[target.thumbv7em-none-eabihf]
168+
runner = "gdb-mulitarch -q"
169+
rustflags = [
170+
"-C", "link-arg=-Tlink.x",
171+
]
172+
```
173+
And `git diff` should be:
174+
``` diff
175+
$ git diff .cargo/config
176+
diff --git a/src/05-led-roulette/.cargo/config b/src/05-led-roulette/.cargo/config
177+
index 01d25c8..c23dc80 100644
178+
--- a/src/05-led-roulette/.cargo/config
179+
+++ b/src/05-led-roulette/.cargo/config
180+
@@ -1,5 +1,5 @@
181+
[target.thumbv7em-none-eabihf]
182+
-runner = "arm-none-eabi-gdb -q"
183+
+runner = "gdb-multiarch -q"
184+
rustflags = [
185+
"-C", "link-arg=-Tlink.x",
186+
]
187+
```
188+
189+
Now that you have `.cargo/config` setup to let's test it and use `cargo run` to
190+
start the debug session:
191+
```
192+
~/embedded-discovery/src/05-led-roulette
193+
$ cargo run --target thumbv7em-none-eabihf
194+
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
195+
Running `arm-none-eabi-gdb -q ~/embedded-discovery/target/thumbv7em-none-eabihf/debug/led-roulette`
196+
Reading symbols from ~/embedded-discovery/target/thumbv7em-none-eabihf/debug/led-roulette...
197+
198+
(gdb) target remote :3333
199+
Remote debugging using :3333
200+
0x00000000 in ?? ()
201+
202+
(gdb)
203+
```
204+
205+
Bravo, you'll be making additional changes to `.cargo/config` in future
206+
sections to make building and debugging easier.
207+
208+
> **Note** the default `.cargo/config` in every chapter assumes
209+
> the debugger is `arm-none-eabi-gdb`. So the first thing you should
210+
> do when you start a new chapter is edit `.cargo/config`!
211+
143212
## Flash the device
144213

145-
Almost there. To flash the device, we'll use the `load` command inside the GDB shell:
214+
Assuming you have gdb running, if not start it as suggested in the previous section.
146215

216+
Now use the `load` command in `gdb` to actually flash the program into the device:
147217
```
148218
(gdb) load
149219
Loading section .vector_table, size 0x194 lma 0x8000000

0 commit comments

Comments
 (0)