Skip to content

Commit 49201f0

Browse files
committed
Update GDB settings to enable ITM, add example
1 parent 05ccb45 commit 49201f0

File tree

8 files changed

+83
-23
lines changed

8 files changed

+83
-23
lines changed

.cargo/config

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
[target.thumbv7em-none-eabihf]
2-
runner = 'arm-none-eabi-gdb'
1+
[target.thumbv7m-none-eabi]
2+
3+
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
4+
runner = "arm-none-eabi-gdb -q -x openocd.gdb"
5+
36
rustflags = [
47
"-C", "link-arg=-Tlink.x",
58
]

.gdbinit

-20
This file was deleted.

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ Cargo.lock
55
**.bk
66
**.sw*
77
bloat_log*
8+
itm.txt

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ version = "0.6"
3535
ssd1306 = "0.2"
3636
nb = "0.1"
3737
panic-halt = "0.2"
38+
panic-itm = "0.4"
3839

3940
[profile.dev]
4041
debug = true

examples/itm.rs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//! Sends "Hello, world!" through the ITM port 0
2+
//!
3+
//! ITM is much faster than semihosting. Like 4 orders of magnitude or so.
4+
//!
5+
//! **NOTE** Cortex-M0 chips don't support ITM.
6+
//!
7+
//! You'll have to connect the microcontroller's SWO pin to the SWD interface. Note that some
8+
//! development boards don't provide this option.
9+
//!
10+
//! You'll need [`itmdump`] to receive the message on the host plus you'll need to uncomment two
11+
//! `monitor` commands in the `.gdbinit` file.
12+
//!
13+
//! [`itmdump`]: https://docs.rs/itm/0.2.1/itm/
14+
//!
15+
//! ---
16+
17+
#![no_main]
18+
#![no_std]
19+
20+
extern crate panic_itm;
21+
extern crate stm32f407g_disc;
22+
23+
use cortex_m::{iprintln, Peripherals};
24+
use cortex_m_rt::entry;
25+
26+
#[entry]
27+
fn main() -> ! {
28+
let mut p = Peripherals::take().unwrap();
29+
let stim = &mut p.ITM.stim[0];
30+
31+
iprintln!(stim, "Hello, world!");
32+
33+
loop {}
34+
}
File renamed without changes.

openocd.gdb

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
target extended-remote :3333
2+
3+
# print demangled symbols
4+
set print asm-demangle on
5+
6+
# set backtrace limit to not have infinite backtrace loops
7+
set backtrace limit 32
8+
9+
# detect unhandled exceptions, hard faults and panics
10+
break DefaultHandler
11+
break HardFault
12+
break rust_begin_unwind
13+
# # run the next few lines so the panic message is printed immediately
14+
# # the number needs to be adjusted for your panic handler
15+
# commands $bpnum
16+
# next 4
17+
# end
18+
19+
# *try* to stop at the user entry point (it might be gone due to inlining)
20+
break main
21+
22+
set mem inaccessible-by-default off
23+
24+
# monitor arm semihosting enable
25+
26+
# # send captured ITM to the file itm.fifo
27+
# # (the microcontroller SWO pin must be connected to the programmer SWO pin)
28+
# # 16000000 must match the core clock frequency
29+
# monitor tpiu config internal itm.txt uart off 16000000
30+
31+
# # OR: make the microcontroller SWO pin output compatible with UART (8N1)
32+
# # 8000000 is the frequency of the SWO pin
33+
# monitor tpiu config external uart off 8000000 2000000
34+
35+
# # enable ITM port 0
36+
monitor itm port 0 on
37+
38+
load
39+
40+
# start the process but immediately halt the processor
41+
stepi

openocd_program.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ if (( $# != 1 )); then
55
exit 1
66
fi
77

8-
openocd -f discovery.cfg -c "init" -c "targets" -c "reset halt" -c "program $1 verify reset exit"
8+
openocd -c "init" -c "targets" -c "reset halt" -c "program $1 verify reset exit"

0 commit comments

Comments
 (0)