Skip to content

Commit bc34d73

Browse files
Merge #309
309: Update 06 hello world to use shared cargo config r=eldruin a=winksaville This is dependent on #308 but there is a reduction in number of lines for 06-hello-world, usually a positive :) Co-authored-by: Wink Saville <wink@saville.com>
2 parents 0da0f43 + 1fdb1c9 commit bc34d73

File tree

4 files changed

+50
-132
lines changed

4 files changed

+50
-132
lines changed

src/06-hello-world/.cargo/config

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/06-hello-world/README.md

Lines changed: 21 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -77,95 +77,36 @@ from `/tmp` directory (on Windows `%TEMP%`) to launch OpenOCD similar as describ
7777

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

80-
To avoid passing the `--target thumbv7em-none-eabihf` flag to every Cargo invocation we
81-
have added `[build]` with a default target, `target = "thumbv7em-none-eabihf"`, to .cargo/config.
82-
Now if `--target` is not specified `cargo` will assume that the target is `thumbv7em-none-eabihf`.
83-
84-
```
85-
[target.thumbv7em-none-eabihf]
86-
runner = "arm-none-eabi-gdb -q -x openocd.gdb"
87-
rustflags = [
88-
"-C", "link-arg=-Tlink.x",
89-
]
90-
91-
[build]
92-
target = "thumbv7em-none-eabihf"
93-
```
94-
95-
In addition, our `opendocd.gdb` has some additional lines. Compared to the previous
96-
section `set`'s and initialize `monitor`ing so `iprint!` and `iprintln!`
97-
macros work and output is visible on a console. Below the contents with comments:
98-
99-
``` console
100-
$ cat openocd.gdb
101-
# Connect to gdb remote server
102-
target remote :3333
103-
104-
# Load will flash the code
105-
load
106-
107-
# Enable demangling asm names on disassembly
108-
set print asm-demangle on
109-
110-
# Enable pretty printing
111-
set print pretty on
112-
113-
# Disable style sources as the default colors can be hard to read
114-
set style sources off
115-
116-
# Have the tpiu send the data to a file itm.txt
117-
monitor tpiu config internal itm.txt uart off 8000000
118-
119-
# Turn on the itm port
120-
monitor itm port 0 on
121-
122-
# Set a breakpoint at main
123-
break main
124-
125-
# Continue running and we'll hit the main breakpoint
126-
continue
127-
```
128-
129-
We will now run the application and single step through it. Since we've added
130-
the `monitor` commands in `openocd.gdb` OpenOCD will redirect the ITM output to
131-
itm.txt and `itmdump` will write it to its terminal window.
80+
We will now build and run the application, `cargo run`. And step through it using `next`.
81+
Since `openocd.gdb` contains the `monitor` commands in `openocd.gdb` OpenOCD will redirect
82+
the ITM output to itm.txt and `itmdump` will write it to its terminal window. Also, it setup
83+
break points and stepped through the trampoline we are at the first executable
84+
statement in `fn main()`:
13285

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

147-
Breakpoint 1, hello_world::__cortex_m_rt_main_trampoline () at src/06-hello-world/src/main.rs:8
104+
Breakpoint 1, hello_world::__cortex_m_rt_main_trampoline () at ~/embedded-discovery/src/06-hello-world/src/main.rs:8
148105
8 #[entry]
149-
```
150-
151-
We are now stopped at `#[entry]` and since, as before, it's a trampoline:
106+
hello_world::__cortex_m_rt_main () at ~/embedded-discovery/src/06-hello-world/src/main.rs:10
107+
10 let mut itm = aux6::init();
152108

153-
``` console
154-
(gdb) disassemble /m
155-
Dump of assembler code for function main:
156-
8 #[entry]
157-
0x080001ec <+0>: push {r7, lr}
158-
0x080001ee <+2>: mov r7, sp
159-
=> 0x080001f0 <+4>: bl 0x80001f6 <hello_world::__cortex_m_rt_main>
160-
0x080001f4 <+8>: udf #254 ; 0xfe
161-
```
162-
163-
We need to initially `step` into the main function which will position us at line 10:
164-
165-
``` text
166-
(gdb) step
167-
hello_world::__cortex_m_rt_main () at src/06-hello-world/src/main.rs:10
168-
10 let mut itm = aux6::init();
109+
(gdb)
169110
```
170111

171112
Now issue a `next` command which will exectue `aux6::init()` and

src/06-hello-world/openocd.gdb

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/06-hello-world/panic.md

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,31 @@ define hook-quit
2222
end
2323
```
2424

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

2727
``` console
2828
$ cargo run
29-
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
30-
Running `arm-none-eabi-gdb -q -x openocd.gdb ~/prgs/rust/tutorial/embedded-discovery/target/thumbv7em-none-eabihf/debug/hello-world`
31-
Reading symbols from ~/prgs/rust/tutorial/embedded-discovery/target/thumbv7em-none-eabihf/debug/hello-world...
32-
panic_itm::panic (info=0x20009fa0) at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/panic-itm-0.4.2/src/lib.rs:57
33-
57 atomic::compiler_fence(Ordering::SeqCst);
29+
Compiling hello-world v0.2.0 (~/embedded-discovery/src/06-hello-world)
30+
Finished dev [unoptimized + debuginfo] target(s) in 0.11s
31+
Running `arm-none-eabi-gdb -q -x ../openocd.gdb ~/embedded-discovery/target/thumbv7em-none-eabihf/debug/hello-world`
32+
Reading symbols from ~/embedded-discovery/target/thumbv7em-none-eabihf/debug/hello-world...
33+
hello_world::__cortex_m_rt_main () at ~/embedded-discovery/src/06-hello-world/src/main.rs:10
34+
10 panic!("Hello, world!");
3435
Loading section .vector_table, size 0x194 lma 0x8000000
35-
Loading section .text, size 0x2198 lma 0x8000194
36-
Loading section .rodata, size 0x5d8 lma 0x800232c
37-
Start address 0x08000194, load size 10500
38-
Transfer rate: 17 KB/sec, 3500 bytes/write.
39-
Breakpoint 1 at 0x80001f0: file src/06-hello-world/src/main.rs, line 8.
36+
Loading section .text, size 0x20fc lma 0x8000194
37+
Loading section .rodata, size 0x554 lma 0x8002290
38+
Start address 0x08000194, load size 10212
39+
Transfer rate: 17 KB/sec, 3404 bytes/write.
40+
Breakpoint 1 at 0x80001f0: file ~/embedded-discovery/src/06-hello-world/src/main.rs, line 8.
4041
Note: automatically using hardware breakpoints for read-only addresses.
41-
42-
Breakpoint 1, hello_world::__cortex_m_rt_main_trampoline () at src/06-hello-world/src/main.rs:8
43-
8 #[entry]
42+
Breakpoint 2 at 0x8000222: file ~/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-rt-0.6.13/src/lib.rs, line 570.
43+
Breakpoint 3 at 0x800227a: file ~/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-rt-0.6.13/src/lib.rs, line 560.
44+
45+
Breakpoint 1, hello_world::__cortex_m_rt_main_trampoline () at ~/embedded-discovery/src/06-hello-world/src/main.rs:8
46+
8 #[entry]
47+
hello_world::__cortex_m_rt_main () at ~/embedded-discovery/src/06-hello-world/src/main.rs:10
48+
10 panic!("Hello, world!");
49+
(gdb)
4450
```
4551

4652
We'll use short command names to save typing, enter `c` then the `Enter` or `Return` key:
@@ -93,19 +99,24 @@ xPSR: 0x01000000 pc: 0x08000194 msp: 0x2000a000
9399
(gdb) disable 1
94100
95101
(gdb) break rust_begin_unwind
96-
Breakpoint 2 at 0x80010f0: file ~/.cargo/registry/src/github.com-1ecc6299db9ec823/panic-itm-0.4.2/src/lib.rs, line 47.
102+
Breakpoint 4 at 0x800106c: file ~/.cargo/registry/src/github.com-1ecc6299db9ec823/panic-itm-0.4.2/src/lib.rs, line 47.
97103
98104
(gdb) info break
99105
Num Type Disp Enb Address What
100-
1 breakpoint keep n 0x080001f0 in hello_world::__cortex_m_rt_main_trampoline at src/06-hello-world/src/main.rs:8
106+
1 breakpoint keep n 0x080001f0 in hello_world::__cortex_m_rt_main_trampoline
107+
at ~/prgs/rust/tutorial/embedded-discovery/src/06-hello-world/src/main.rs:8
101108
breakpoint already hit 1 time
102-
2 breakpoint keep y 0x080010f0 in panic_itm::panic
109+
2 breakpoint keep y 0x08000222 in cortex_m_rt::DefaultHandler_
110+
at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-rt-0.6.13/src/lib.rs:570
111+
3 breakpoint keep y 0x0800227a in cortex_m_rt::HardFault_
112+
at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-rt-0.6.13/src/lib.rs:560
113+
4 breakpoint keep y 0x0800106c in panic_itm::panic
103114
at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/panic-itm-0.4.2/src/lib.rs:47
104115
105116
(gdb) c
106117
Continuing.
107118
108-
Breakpoint 2, panic_itm::panic (info=0x20009fa0) at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/panic-itm-0.4.2/src/lib.rs:47
119+
Breakpoint 4, panic_itm::panic (info=0x20009fa0) at ~/.cargo/registry/src/github.com-1ecc6299db9ec823/panic-itm-0.4.2/src/lib.rs:47
109120
47 interrupt::disable();
110121
```
111122

0 commit comments

Comments
 (0)