Skip to content

Commit 243db15

Browse files
committed
Update 05 led-roulette
Cargo.toml to use stm32f3-discovery v0.6.0 crate. Update `.md` files with additional information and to make console commands amenable to copy/paste operations.
1 parent 8ea5d2c commit 243db15

File tree

6 files changed

+251
-125
lines changed

6 files changed

+251
-125
lines changed

src/05-led-roulette/auxiliary/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ version = "0.2.0"
1111
[dependencies]
1212
cortex-m = "0.6.4"
1313
cortex-m-rt = "0.6.13"
14-
stm32f3-discovery = "0.5.0"
14+
stm32f3-discovery = "0.6.0"
1515
panic-halt = "0.2.0"
1616
panic-itm = "0.4.2"

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

Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,89 @@ download pre-compiled version of the standard library (a reduced version of it a
1919
target. That's done using `rustup`:
2020

2121
``` console
22-
$ rustup target add thumbv7em-none-eabihf
22+
rustup target add thumbv7em-none-eabihf
2323
```
2424

2525
You only need to do the above step once; `rustup` will re-install a new standard library
2626
(`rust-std` component) whenever you update your toolchain.
2727

28-
With the `rust-std` component in place you can now cross compile the program using Cargo:
28+
With the `rust-std` component in place you can now cross compile the program using Cargo.
2929

30+
> Note: make sure you are in the `src/05-led-roulette` directory
31+
> and run `cargo build` command below to create the executable:
32+
``` console
33+
cargo build --target thumbv7em-none-eabihf
34+
```
35+
On your console you should see something like:
3036
``` console
31-
$ # make sure you are in the `src/05-led-roulette` directory
32-
3337
$ cargo build --target thumbv7em-none-eabihf
3438
Compiling typenum v1.12.0
3539
Compiling semver-parser v0.7.0
3640
Compiling version_check v0.9.2
37-
Compiling cortex-m v0.6.4
41+
Compiling nb v1.0.0
42+
Compiling void v1.0.2
43+
Compiling autocfg v1.0.1
44+
Compiling cortex-m v0.7.1
45+
Compiling proc-macro2 v1.0.24
46+
Compiling vcell v0.1.3
47+
Compiling unicode-xid v0.2.1
48+
Compiling stable_deref_trait v1.2.0
49+
Compiling syn v1.0.60
50+
Compiling bitfield v0.13.2
51+
Compiling cortex-m v0.6.7
3852
Compiling cortex-m-rt v0.6.13
39-
Compiling stm32f3-discovery v0.5.0
40-
...
53+
Compiling r0 v0.2.2
54+
Compiling stm32-usbd v0.5.1
55+
Compiling stm32f3 v0.12.1
56+
Compiling usb-device v0.2.7
57+
Compiling cfg-if v1.0.0
58+
Compiling paste v1.0.4
59+
Compiling stm32f3-discovery v0.6.0
60+
Compiling panic-halt v0.2.0
61+
Compiling embedded-dma v0.1.2
62+
Compiling volatile-register v0.2.0
63+
Compiling nb v0.1.3
64+
Compiling embedded-hal v0.2.4
65+
Compiling semver v0.9.0
66+
Compiling generic-array v0.14.4
67+
Compiling switch-hal v0.3.2
68+
Compiling num-traits v0.2.14
69+
Compiling num-integer v0.1.44
70+
Compiling rustc_version v0.2.3
71+
Compiling bare-metal v0.2.5
72+
Compiling cast v0.2.3
73+
Compiling quote v1.0.9
74+
Compiling generic-array v0.13.2
75+
Compiling generic-array v0.12.3
76+
Compiling generic-array v0.11.1
4177
Compiling panic-itm v0.4.2
78+
Compiling lsm303dlhc v0.2.0
79+
Compiling as-slice v0.1.4
80+
Compiling micromath v1.1.0
81+
Compiling accelerometer v0.12.0
82+
Compiling chrono v0.4.19
83+
Compiling aligned v0.3.4
84+
Compiling rtcc v0.2.0
4285
Compiling cortex-m-rt-macros v0.1.8
43-
Compiling stm32f3xx-hal v0.5.0
44-
Compiling aux5 v0.2.0 (file://$PWD/auxiliary)
45-
Compiling led-roulette v0.2.0 (file://$PWD/)
46-
Finished dev [unoptimized + debuginfo] target(s) in 19.45s
86+
Compiling stm32f3xx-hal v0.6.1
87+
Compiling aux5 v0.2.0 (~/embedded-discovery/src/05-led-roulette/auxiliary)
88+
Compiling led-roulette v0.2.0 (~/embedded-discovery/src/05-led-roulette)
89+
Finished dev [unoptimized + debuginfo] target(s) in 17.91s
4790
```
4891

4992
> **NOTE** Be sure to compile this crate *without* optimizations. The provided Cargo.toml file and build command above will ensure optimizations are off.
5093
5194
OK, now we have produced an executable. This executable won't blink any leds, it's just a simplified version that we will build upon later in the chapter. As a sanity check, let's verify that the produced executable is actually an ARM binary:
5295

5396
``` console
54-
$ # equivalent to `readelf -h target/thumbv7em-none-eabihf/debug/led-roulette`
55-
$ cargo readobj --target thumbv7em-none-eabihf --bin led-roulette -- -file-headers
56-
Finished dev [unoptimized + debuginfo] target(s) in 0.03s
97+
cargo readobj --target thumbv7em-none-eabihf --bin led-roulette -- --file-header
98+
```
99+
The `cargo readobj ..` above is equivalent to
100+
`readelf -h target/thumbv7em-none-eabihf/debug/led-roulette`
101+
and should produce something similar to:
102+
``` console
103+
$ cargo readobj --target thumbv7em-none-eabihf --bin led-roulette -- --file-header
104+
Finished dev [unoptimized + debuginfo] target(s) in 0.02s
57105
ELF Header:
58106
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
59107
Class: ELF32
@@ -66,7 +114,7 @@ ELF Header:
66114
Version: 0x1
67115
Entry point address: 0x8000195
68116
Start of program headers: 52 (bytes into file)
69-
Start of section headers: 797192 (bytes into file)
117+
Start of section headers: 818328 (bytes into file)
70118
Flags: 0x5000400
71119
Size of this header: 52 (bytes)
72120
Size of program headers: 32 (bytes)

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

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,32 @@ processor / CPU will execute first.
88

99
The starter project I've provided to you has some extra code that runs *before* the `main` function.
1010
At this time, we are not interested in that "pre-main" part so let's skip right to the beginning of
11-
the `main` function. We'll do that using a breakpoint:
12-
11+
the `main` function. We'll do that using a breakpoint. Issue `break main` at the `(gdb)` prompt:
12+
13+
> **Note** for these gdb commands I generally won't provide a copyable code block
14+
> as these are short and it's faster just to type them yourself. In addition most
15+
> can be shortend. For instance `b` for `break` or `s` for `step`, see [gdb quick ref]
16+
> for more info or use Google to find your others. In addition, you can use tab completion
17+
> by typing the first few letters than one tab to complete or two tabs to
18+
> see all possible commands.
19+
>
20+
>> Finally, `help xxxx` where xxxx is the comand will provide short names and other info:
21+
>> ```
22+
>> (gdb) help s
23+
>> step, s
24+
>> Step program until it reaches a different source line.
25+
>> Usage: step [N]
26+
>> Argument N means step N times (or till program stops for another reason).
27+
>> ```
28+
29+
[gdb quick ref]: https://users.ece.utexas.edu/~adnan/gdb-refcard.pdf
1330
```
1431
(gdb) break main
1532
Breakpoint 1 at 0x80001f0: file src/05-led-roulette/src/main.rs, line 7.
1633
Note: automatically using hardware breakpoints for read-only addresses.
17-
34+
```
35+
Next issue a `continue` command:
36+
```
1837
(gdb) continue
1938
Continuing.
2039

@@ -57,9 +76,9 @@ led_roulette::__cortex_m_rt_main () at src/05-led-roulette/src/main.rs:10
5776
Next we'll issue a second `step` which executes line 10 and stops at
5877
line `11 _y = x;`, again line 11 is **not** executed.
5978
60-
> **Note** we could have pressed enter at the second `<gdb> ` prompt and
61-
> it would have reissued the previous statement, `step`, but for clarity in this tutorial
62-
> we'll generally retype the command.
79+
> **Note** we could have pressed enter at the second `(gdb) ` prompt and
80+
> it would have reissued the previous statement, `step`, but for clarity
81+
> in this tutorial we'll generally retype the command.
6382
6483
```
6584
(gdb) step
@@ -71,16 +90,17 @@ along with its line number. As you'll see later in the TUI mode you'll not the s
7190
in the command area.
7291
7392
We are now "on" the `_y = x` statement; that statement hasn't been executed yet. This means that `x`
74-
is initialized but `_y` is not. Let's inspect those stack/local variables using the `print` command:
93+
is initialized but `_y` is not. Let's inspect those stack/local variables using the `print`
94+
command, `p` for short:
7595
7696
```
7797
(gdb) print x
7898
$1 = 42
79-
(gdb) print &x
99+
(gdb) p &x
80100
$2 = (*mut i32) 0x20009fe0
81-
(gdb) print _y
101+
(gdb) p _y
82102
$3 = 536870912
83-
(gdb) print &_y
103+
(gdb) p &_y
84104
$4 = (*mut i32) 0x20009fe4
85105
```
86106
@@ -154,15 +174,15 @@ See the fat arrow `=>` on the left side? It shows the instruction the processor
154174
155175
Also, as mentioned above if you were to execute the `step` command GDB gets stuck because it
156176
is executing a branch instruction to itself and never gets past it. So you need to use
157-
`Ctrl+C` to regain control. An alternative is to use the `stepi` GDB command, which steps
177+
`Ctrl+C` to regain control. An alternative is to use the `stepi`(`si`) GDB command, which steps
158178
one asm instruction, and GDB will print the address **and** line number of the statement
159179
the processor will execute next and it won't get stuck.
160180
161181
```
162182
(gdb) stepi
163183
0x08000194 14 loop {}
164184

165-
(gdb) stepi
185+
(gdb) si
166186
0x08000194 14 loop {}
167187
```
168188
@@ -233,35 +253,40 @@ mode enter one of the following commands in the GDB shell:
233253
> **NOTE** Apologies to Windows users, the GDB shipped with the GNU ARM Embedded Toolchain
234254
> may not support this TUI mode `:-(`.
235255
236-
Below is an example of setting up for a layout split by executing the follow commands:
256+
Below is an example of setting up for a `layout split` by executing the follow commands:
237257
238258
``` console
239259
$ cargo run --target thumbv7em-none-eabihf
240-
<gdb> target remote :3333
241-
<gdb> load
242-
<gdb> set print asm-demangle on
243-
<gdb> set style sources off
244-
<gdb> break main
245-
<gdb> continue
246-
<gdb> layout split
260+
(gdb) target remote :3333
261+
(gdb) load
262+
(gdb) set print asm-demangle on
263+
(gdb) set style sources off
264+
(gdb) break main
265+
(gdb) continue
247266
```
248267

249-
And below the result after `layout split` command is executed:
268+
Here is a command line with the above commands as `-ex` parameters to save you some typing:
269+
270+
```
271+
cargo run --target thumbv7em-none-eabihf -- -q -ex 'target remote :3333' -ex 'load' -ex 'set print asm-demangle on' -ex 'set style sources off' -ex 'b main' -ex 'c' target/thumbv7em-none-eabihf/debug/led-roulette
272+
```
273+
274+
And below is the result:
250275

251276
![GDB session layout split](../assets/gdb-layout-split-1.png "GDB TUI layout split 1")
252277

253-
Now we'll scroll the top source window down so we see the entire file and execute `step`:
278+
Now we'll scroll the top source window down so we see the entire file and execute `layout split` and then `step`:
254279

255280
![GDB session layout split](../assets/gdb-layout-split-2.png "GDB TUI layout split 2")
256281

257282
Then we'll execute a few `info locals` and `step`'s:
258283

259284
``` console
260-
<gdb> info locals
261-
<gdb> step
262-
<gdb> info locals
263-
<gdb> step
264-
<gdb> info locals
285+
(gdb) info locals
286+
(gdb) step
287+
(gdb) info locals
288+
(gdb) step
289+
(gdb) info locals
265290
```
266291

267292
![GDB session layout split](../assets/gdb-layout-split-3.png "GDB TUI layout split 3")

0 commit comments

Comments
 (0)