Skip to content

Commit 554d02b

Browse files
Merge #332
332: Fix some flaws in the "LED roulette" section r=adamgreig a=SimplyDanny Co-authored-by: Danny Moesch <danny.moesch@icloud.com>
2 parents 94a95b8 + 25893cb commit 554d02b

File tree

6 files changed

+26
-25
lines changed

6 files changed

+26
-25
lines changed

src/05-led-roulette/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ The `no_main` attribute says that this program won't use the standard `main` int
3636
tailored for command line applications that receive arguments. Instead of the standard `main` we'll
3737
use the `entry` attribute from the [`cortex-m-rt`] crate to define a custom entry point. In this
3838
program we have named the entry point "main", but any other name could have been used. The entry
39-
point function must have signature `fn() -> !`; this type indicates that the function can't return
40-
-- this means that the program never terminates.
39+
point function must have the signature `fn() -> !`; this type indicates that the function can't
40+
return – this means that the program never terminates.
4141

4242
[`cortex-m-rt`]: https://crates.io/crates/cortex-m-rt
4343

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ families within that architecture:
1515
- `thumbv7em-none-eabihf`, for the Cortex-M4**F** and Cortex-M7**F** processors
1616

1717
For the F3, we'll use the `thumbv7em-none-eabihf` target. Before cross compiling you have to
18-
download pre-compiled version of the standard library (a reduced version of it actually) for your
18+
download a pre-compiled version of the standard library (a reduced version of it actually) for your
1919
target. That's done using `rustup`:
2020

2121
``` console
@@ -27,7 +27,7 @@ You only need to do the above step once; `rustup` will re-install a new standard
2727

2828
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
30+
> **NOTE** Make sure you are in the `src/05-led-roulette` directory
3131
> and run `cargo build` command below to create the executable:
3232
``` console
3333
cargo build --target thumbv7em-none-eabihf
@@ -88,9 +88,9 @@ $ cargo build --target thumbv7em-none-eabihf
8888
Finished dev [unoptimized + debuginfo] target(s) in 17.91s
8989
```
9090

91-
> **NOTE** Be sure to compile this crate *without* optimizations. The provided Cargo.toml file and build command above will ensure optimizations are off.
91+
> **NOTE** Be sure to compile this crate *without* optimizations. The provided Cargo.toml file and build command above will ensure optimizations are off.
9292
93-
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:
93+
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:
9494

9595
``` console
9696
cargo readobj --target thumbv7em-none-eabihf --bin led-roulette -- --file-header

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ The starter project I've provided to you has some extra code that runs *before*
1010
At this time, we are not interested in that "pre-main" part so let's skip right to the beginning of
1111
the `main` function. We'll do that using a breakpoint. Issue `break main` at the `(gdb)` prompt:
1212

13-
> **Note** for these gdb commands I generally won't provide a copyable code block
13+
> **NOTE** For these GDB commands I generally won't provide a copyable code block
1414
> 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]
15+
> can be shortend. For instance `b` for `break` or `s` for `step`, see [GDB Quick Reference]
1616
> for more info or use Google to find your others. In addition, you can use tab completion
1717
> by typing the first few letters than one tab to complete or two tabs to
1818
> see all possible commands.
@@ -26,7 +26,7 @@ the `main` function. We'll do that using a breakpoint. Issue `break main` at the
2626
>> Argument N means step N times (or till program stops for another reason).
2727
>> ```
2828
29-
[gdb quick ref]: https://users.ece.utexas.edu/~adnan/gdb-refcard.pdf
29+
[GDB Quick Reference]: https://users.ece.utexas.edu/~adnan/gdb-refcard.pdf
3030
```
3131
(gdb) break main
3232
Breakpoint 1 at 0x80001f0: file src/05-led-roulette/src/main.rs, line 7.
@@ -49,7 +49,7 @@ which is a trampoline to the main function and where `break main` sets the break
4949
> breakpoints so it's a good idea to pay attention to these messages.
5050
5151
OK. Since we are stopped at `#[entry]` and using the `disassemble /m` we see the code
52-
for entry, which is a trampoline to main. What that means it sets up the stack and then
52+
for entry, which is a trampoline to main. That means it sets up the stack and then
5353
invokes a subroutine call to the `main` function using an ARM branch and link instruction, `bl`.
5454
```
5555
(gdb) disassemble /m
@@ -63,7 +63,7 @@ Dump of assembler code for function main:
6363
End of assembler dump.
6464
```
6565
66-
Next we need to issue a `step` gdb command which will advance the program statement
66+
Next we need to issue a `step` GDB command which will advance the program statement
6767
by statement stepping into functions/procedures. So after this first `step` command we're
6868
inside `main` and are positioned at the first executable `rust` statement, line 10, but it is
6969
**not** executed:
@@ -76,7 +76,7 @@ led_roulette::__cortex_m_rt_main () at src/05-led-roulette/src/main.rs:10
7676
Next we'll issue a second `step` which executes line 10 and stops at
7777
line `11 _y = x;`, again line 11 is **not** executed.
7878
79-
> **Note** we could have pressed enter at the second `(gdb) ` prompt and
79+
> **NOTE** We could have pressed enter at the second `(gdb) ` prompt and
8080
> it would have reissued the previous statement, `step`, but for clarity
8181
> in this tutorial we'll generally retype the command.
8282
@@ -86,7 +86,7 @@ line `11 _y = x;`, again line 11 is **not** executed.
8686
```
8787
8888
As you can see, in this mode, on each `step` command GDB will print the current statement along
89-
along with its line number. As you'll see later in the TUI mode you'll not the see the statement
89+
with its line number. As you'll see later in the TUI mode you'll not see the statement
9090
in the command area.
9191
9292
We are now "on" the `_y = x` statement; that statement hasn't been executed yet. This means that `x`

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,17 @@ In both failing and successful cases you should see new output in the **OpenOCD
135135
+Info : flash size = 256kbytes
136136
```
137137

138-
**NOTE**: If you are getting an error like `undefined debug reason 7 - target needs reset`, you can try running `monitor reset halt` as described [here](https://stackoverflow.com/questions/38994596/reason-7-target-needs-reset-unreliable-debugging-setup).
138+
> **NOTE** If you are getting an error like `undefined debug reason 7 - target needs reset`, you can try running `monitor reset halt` as described [here](https://stackoverflow.com/questions/38994596/reason-7-target-needs-reset-unreliable-debugging-setup).
139139
140140
By default OpenOCD's GDB server listens on TCP port 3333 (localhost). This command is connecting to
141141
that port.
142142

143143
## Update ../.cargo/config.toml
144144

145145
Now that you've successfully determined which debugger you need to use
146-
we need to change `../.cargo/config.toml` so that `cargo run` command will succeed.
147-
Note: `cargo` is the rust package manager and you can read about it
146+
we need to change `../.cargo/config.toml` so that the `cargo run` command will succeed.
147+
148+
> **NOTE** `cargo` is the Rust package manager and you can read about it
148149
[here](https://doc.rust-lang.org/cargo/).
149150

150151
Get back to the terminal prompt and look at `../.cargo/config.toml`:
@@ -190,11 +191,11 @@ index ddff17f..8512cfe 100644
190191
Now that you have `../.cargo/config.toml` setup let's test it using `cargo run` to
191192
start the debug session.
192193

193-
> Note the `--target thumbv7em-none-eabihf` defines which architecture
194+
> **NOTE** The `--target thumbv7em-none-eabihf` defines which architecture
194195
> to build and run. In our `../.cargo/config.toml` file we have
195196
> `target = "thumbv7em-none-eabihf"` so it is actually not necessary
196197
> to specify `--target` we do it here just so you know that parameters on
197-
> the command line can be used and they override those in `config.toml` files
198+
> the command line can be used and they override those in `config.toml` files.
198199
199200
```
200201
cargo run --target thumbv7em-none-eabihf
@@ -224,7 +225,7 @@ directory.
224225

225226
## Flash the device
226227

227-
Assuming you have gdb running, if not start it as suggested in the previous section.
228+
Assuming you have GDB running, if not start it as suggested in the previous section.
228229

229230
Now use the `load` command in `gdb` to actually flash the program into the device:
230231
```

src/05-led-roulette/the-challenge.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ entering the same commands at the beginning. We can use a `.gdb` file to execute
2626
right after GDB is started. This way you can save yourself the effort of having to enter them
2727
manually on each GDB session.
2828

29-
As it turns out we've already created `../openocd.gdb` and you can see it's doing
29+
As it turns out we've already created `../openocd.gdb` and you can see it's doing
3030
pretty much what we did in the previous section plus a few other commands. Look at
3131
the comments for additional information:
3232

src/05-led-roulette/the-led-and-delay-abstractions.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ cargo build
2828
> session ensuring you never forget to recompile your program.
2929
3030
Now we'll run and repeat the flashing procedure as we did in the previous section
31-
but with the new program. I'll let you type in the `cargo run`, *this will get easier shortly* :)
31+
but with the new program. I'll let you type in the `cargo run`, *this will get easier shortly*. :)
3232
``` console
3333
$ cargo run
3434
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
@@ -62,7 +62,7 @@ Breakpoint 1, led_roulette::__cortex_m_rt_main_trampoline ()
6262
led_roulette::__cortex_m_rt_main () at ~/embedded-discovery/src/05-led-roulette/src/main.rs:9
6363
9 let (mut delay, mut leds): (Delay, LedArray) = aux5::init();
6464

65-
(gdb)
65+
(gdb)
6666
```
6767

6868
OK. Let's step through the code. This time, we'll use the `next` command instead of `step`. The
@@ -186,7 +186,7 @@ Run till exit from #0 0x08002f80 in stm32f3xx_hal::delay::{{impl}}::delay_ms (s
186186
We are back in `main`. We have a local variable in here: `half_period`
187187

188188
```
189-
(gdb) print half_period
189+
(gdb) print half_period
190190
$3 = 500
191191
```
192192

@@ -195,14 +195,14 @@ Now, we are going to modify this variable using the `set` command:
195195
```
196196
(gdb) set half_period = 100
197197
198-
(gdb) print half_period
198+
(gdb) print half_period
199199
$5 = 100
200200
```
201201

202202
If you let program run free again using the `continue` command, you **might** see that the LED will
203203
blink at a much faster rate now, but more likely the blink rate didn't change. **What happened?**
204204

205-
Let's stop the program with `Ctrl+C` and then set a break point at `main:14`.
205+
Let's stop the program with `Ctrl+C` and then set a break point at `main:14`.
206206
``` console
207207
(gdb) continue
208208
Continuing.

0 commit comments

Comments
 (0)