Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/06-hello-world/.cargo/config

This file was deleted.

101 changes: 21 additions & 80 deletions src/06-hello-world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,95 +77,36 @@ from `/tmp` directory (on Windows `%TEMP%`) to launch OpenOCD similar as describ

Alright. Now, let's build the starter code and flash it into the microcontroller.

To avoid passing the `--target thumbv7em-none-eabihf` flag to every Cargo invocation we
have added `[build]` with a default target, `target = "thumbv7em-none-eabihf"`, to .cargo/config.
Now if `--target` is not specified `cargo` will assume that the target is `thumbv7em-none-eabihf`.

```
[target.thumbv7em-none-eabihf]
runner = "arm-none-eabi-gdb -q -x openocd.gdb"
rustflags = [
"-C", "link-arg=-Tlink.x",
]

[build]
target = "thumbv7em-none-eabihf"
```

In addition, our `opendocd.gdb` has some additional lines. Compared to the previous
section `set`'s and initialize `monitor`ing so `iprint!` and `iprintln!`
macros work and output is visible on a console. Below the contents with comments:

``` console
$ cat openocd.gdb
# Connect to gdb remote server
target remote :3333

# Load will flash the code
load

# Enable demangling asm names on disassembly
set print asm-demangle on

# Enable pretty printing
set print pretty on

# Disable style sources as the default colors can be hard to read
set style sources off

# Have the tpiu send the data to a file itm.txt
monitor tpiu config internal itm.txt uart off 8000000

# Turn on the itm port
monitor itm port 0 on

# Set a breakpoint at main
break main

# Continue running and we'll hit the main breakpoint
continue
```

We will now run the application and single step through it. Since we've added
the `monitor` commands in `openocd.gdb` OpenOCD will redirect the ITM output to
itm.txt and `itmdump` will write it to its terminal window.
We will now build and run the application, `cargo run`. And step through it using `next`.
Since `openocd.gdb` contains the `monitor` commands in `openocd.gdb` OpenOCD will redirect
the ITM output to itm.txt and `itmdump` will write it to its terminal window. Also, it setup
break points and stepped through the trampoline we are at the first executable
statement in `fn main()`:

``` console
~/embedded-discovery/src/06-hello-world
$ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
Running `arm-none-eabi-gdb -q -x openocd.gdb ~/prgs/rust/tutorial/embedded-discovery/target/thumbv7em-none-eabihf/debug/hello-world`
Reading symbols from ~/prgs/rust/tutorial/embedded-discovery/target/thumbv7em-none-eabihf/debug/hello-world...
0x00000000 in ?? ()
Running `arm-none-eabi-gdb -q -x ../openocd.gdb ~/embedded-discovery/target/thumbv7em-none-eabihf/debug/hello-world`
Reading symbols from ~/embedded-discovery/target/thumbv7em-none-eabihf/debug/hello-world...
hello_world::__cortex_m_rt_main () at ~/embedded-discovery/src/06-hello-world/src/main.rs:14
14 loop {}
Loading section .vector_table, size 0x194 lma 0x8000000
Loading section .text, size 0x28d8 lma 0x8000194
Loading section .rodata, size 0x6b8 lma 0x8002a6c
Start address 0x08000194, load size 12580
Transfer rate: 18 KB/sec, 4193 bytes/write.
Breakpoint 1 at 0x80001f0: file src/06-hello-world/src/main.rs, line 8.
Loading section .text, size 0x2828 lma 0x8000194
Loading section .rodata, size 0x638 lma 0x80029bc
Start address 0x08000194, load size 12276
Transfer rate: 18 KB/sec, 4092 bytes/write.
Breakpoint 1 at 0x80001f0: file ~/embedded-discovery/src/06-hello-world/src/main.rs, line 8.
Note: automatically using hardware breakpoints for read-only addresses.
Breakpoint 2 at 0x800092a: file /home/wink/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-rt-0.6.13/src/lib.rs, line 570.
Breakpoint 3 at 0x80029a8: file /home/wink/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-rt-0.6.13/src/lib.rs, line 560.

Breakpoint 1, hello_world::__cortex_m_rt_main_trampoline () at src/06-hello-world/src/main.rs:8
Breakpoint 1, hello_world::__cortex_m_rt_main_trampoline () at ~/embedded-discovery/src/06-hello-world/src/main.rs:8
8 #[entry]
```

We are now stopped at `#[entry]` and since, as before, it's a trampoline:
hello_world::__cortex_m_rt_main () at ~/embedded-discovery/src/06-hello-world/src/main.rs:10
10 let mut itm = aux6::init();

``` console
(gdb) disassemble /m
Dump of assembler code for function main:
8 #[entry]
0x080001ec <+0>: push {r7, lr}
0x080001ee <+2>: mov r7, sp
=> 0x080001f0 <+4>: bl 0x80001f6 <hello_world::__cortex_m_rt_main>
0x080001f4 <+8>: udf #254 ; 0xfe
```

We need to initially `step` into the main function which will position us at line 10:

``` text
(gdb) step
hello_world::__cortex_m_rt_main () at src/06-hello-world/src/main.rs:10
10 let mut itm = aux6::init();
(gdb)
```

Now issue a `next` command which will exectue `aux6::init()` and
Expand Down
26 changes: 0 additions & 26 deletions src/06-hello-world/openocd.gdb

This file was deleted.

47 changes: 29 additions & 18 deletions src/06-hello-world/panic.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,31 @@ define hook-quit
end
```

OK, now use `cargo run` and it stops at `#[entry]`:
OK, now use `cargo run` and it stops at the first line of `fn main()`:

``` console
$ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
Running `arm-none-eabi-gdb -q -x openocd.gdb ~/prgs/rust/tutorial/embedded-discovery/target/thumbv7em-none-eabihf/debug/hello-world`
Reading symbols from ~/prgs/rust/tutorial/embedded-discovery/target/thumbv7em-none-eabihf/debug/hello-world...
panic_itm::panic (info=0x20009fa0) at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/panic-itm-0.4.2/src/lib.rs:57
57 atomic::compiler_fence(Ordering::SeqCst);
Compiling hello-world v0.2.0 (~/embedded-discovery/src/06-hello-world)
Finished dev [unoptimized + debuginfo] target(s) in 0.11s
Running `arm-none-eabi-gdb -q -x ../openocd.gdb ~/embedded-discovery/target/thumbv7em-none-eabihf/debug/hello-world`
Reading symbols from ~/embedded-discovery/target/thumbv7em-none-eabihf/debug/hello-world...
hello_world::__cortex_m_rt_main () at ~/embedded-discovery/src/06-hello-world/src/main.rs:10
10 panic!("Hello, world!");
Loading section .vector_table, size 0x194 lma 0x8000000
Loading section .text, size 0x2198 lma 0x8000194
Loading section .rodata, size 0x5d8 lma 0x800232c
Start address 0x08000194, load size 10500
Transfer rate: 17 KB/sec, 3500 bytes/write.
Breakpoint 1 at 0x80001f0: file src/06-hello-world/src/main.rs, line 8.
Loading section .text, size 0x20fc lma 0x8000194
Loading section .rodata, size 0x554 lma 0x8002290
Start address 0x08000194, load size 10212
Transfer rate: 17 KB/sec, 3404 bytes/write.
Breakpoint 1 at 0x80001f0: file ~/embedded-discovery/src/06-hello-world/src/main.rs, line 8.
Note: automatically using hardware breakpoints for read-only addresses.

Breakpoint 1, hello_world::__cortex_m_rt_main_trampoline () at src/06-hello-world/src/main.rs:8
8 #[entry]
Breakpoint 2 at 0x8000222: file ~/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-rt-0.6.13/src/lib.rs, line 570.
Breakpoint 3 at 0x800227a: file ~/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-rt-0.6.13/src/lib.rs, line 560.

Breakpoint 1, hello_world::__cortex_m_rt_main_trampoline () at ~/embedded-discovery/src/06-hello-world/src/main.rs:8
8 #[entry]
hello_world::__cortex_m_rt_main () at ~/embedded-discovery/src/06-hello-world/src/main.rs:10
10 panic!("Hello, world!");
(gdb)
```

We'll use short command names to save typing, enter `c` then the `Enter` or `Return` key:
Expand Down Expand Up @@ -93,19 +99,24 @@ xPSR: 0x01000000 pc: 0x08000194 msp: 0x2000a000
(gdb) disable 1

(gdb) break rust_begin_unwind
Breakpoint 2 at 0x80010f0: file ~/.cargo/registry/src/github.com-1ecc6299db9ec823/panic-itm-0.4.2/src/lib.rs, line 47.
Breakpoint 4 at 0x800106c: file ~/.cargo/registry/src/github.com-1ecc6299db9ec823/panic-itm-0.4.2/src/lib.rs, line 47.

(gdb) info break
Num Type Disp Enb Address What
1 breakpoint keep n 0x080001f0 in hello_world::__cortex_m_rt_main_trampoline at src/06-hello-world/src/main.rs:8
1 breakpoint keep n 0x080001f0 in hello_world::__cortex_m_rt_main_trampoline
at ~/prgs/rust/tutorial/embedded-discovery/src/06-hello-world/src/main.rs:8
breakpoint already hit 1 time
2 breakpoint keep y 0x080010f0 in panic_itm::panic
2 breakpoint keep y 0x08000222 in cortex_m_rt::DefaultHandler_
at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-rt-0.6.13/src/lib.rs:570
3 breakpoint keep y 0x0800227a in cortex_m_rt::HardFault_
at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-rt-0.6.13/src/lib.rs:560
4 breakpoint keep y 0x0800106c in panic_itm::panic
at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/panic-itm-0.4.2/src/lib.rs:47

(gdb) c
Continuing.

Breakpoint 2, panic_itm::panic (info=0x20009fa0) at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/panic-itm-0.4.2/src/lib.rs:47
Breakpoint 4, panic_itm::panic (info=0x20009fa0) at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/panic-itm-0.4.2/src/lib.rs:47
47 interrupt::disable();
```

Expand Down