Skip to content

Commit

Permalink
Update GDB settings to enable ITM, add example
Browse files Browse the repository at this point in the history
  • Loading branch information
maxekman committed Apr 28, 2020
1 parent 05ccb45 commit 523ec0a
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 23 deletions.
25 changes: 23 additions & 2 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
[target.thumbv7em-none-eabihf]
runner = 'arm-none-eabi-gdb'
[target.thumbv7m-none-eabi]
# uncomment this to make `cargo run` execute programs on QEMU
# runner = "qemu-system-arm -cpu cortex-m3 -machine lm3s6965evb -nographic -semihosting-config enable=on,target=native -kernel"

[target.'cfg(all(target_arch = "arm", target_os = "none"))']
# uncomment ONE of these three option to make `cargo run` start a GDB session
# which option to pick depends on your system
runner = "arm-none-eabi-gdb -q -x openocd.gdb"
# runner = "gdb-multiarch -q -x openocd.gdb"
# runner = "gdb -q -x openocd.gdb"

rustflags = [
# LLD (shipped with the Rust toolchain) is used as the default linker
"-C", "link-arg=-Tlink.x",

# if you run into problems with LLD switch to the GNU linker by commenting out
# this line
# "-C", "linker=arm-none-eabi-ld",

# if you need to link to pre-compiled C libraries provided by a C toolchain
# use GCC as the linker by commenting out both lines above and then
# uncommenting the three lines below
# "-C", "linker=arm-none-eabi-gcc",
# "-C", "link-arg=-Wl,-Tlink.x",
# "-C", "link-arg=-nostartfiles",
]

[build]
Expand Down
20 changes: 0 additions & 20 deletions .gdbinit

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ Cargo.lock
**.bk
**.sw*
bloat_log*
itm.txt
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ version = "0.6"
ssd1306 = "0.2"
nb = "0.1"
panic-halt = "0.2"
panic-itm = "0.4"

[profile.dev]
debug = true
Expand Down
34 changes: 34 additions & 0 deletions examples/itm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//! Sends "Hello, world!" through the ITM port 0
//!
//! ITM is much faster than semihosting. Like 4 orders of magnitude or so.
//!
//! **NOTE** Cortex-M0 chips don't support ITM.
//!
//! You'll have to connect the microcontroller's SWO pin to the SWD interface. Note that some
//! development boards don't provide this option.
//!
//! You'll need [`itmdump`] to receive the message on the host plus you'll need to uncomment two
//! `monitor` commands in the `.gdbinit` file.
//!
//! [`itmdump`]: https://docs.rs/itm/0.2.1/itm/
//!
//! ---
#![no_main]
#![no_std]

extern crate panic_itm;
extern crate stm32f407g_disc;

use cortex_m::{iprintln, Peripherals};
use cortex_m_rt::entry;

#[entry]
fn main() -> ! {
let mut p = Peripherals::take().unwrap();
let stim = &mut p.ITM.stim[0];

iprintln!(stim, "Hello, world!");

loop {}
}
File renamed without changes.
41 changes: 41 additions & 0 deletions openocd.gdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
target extended-remote :3333

# print demangled symbols
set print asm-demangle on

# set backtrace limit to not have infinite backtrace loops
set backtrace limit 32

# detect unhandled exceptions, hard faults and panics
break DefaultHandler
break HardFault
break rust_begin_unwind
# # run the next few lines so the panic message is printed immediately
# # the number needs to be adjusted for your panic handler
# commands $bpnum
# next 4
# end

# *try* to stop at the user entry point (it might be gone due to inlining)
break main

set mem inaccessible-by-default off

# monitor arm semihosting enable

# # send captured ITM to the file itm.fifo
# # (the microcontroller SWO pin must be connected to the programmer SWO pin)
# # 16000000 must match the core clock frequency
# monitor tpiu config internal itm.txt uart off 16000000

# # OR: make the microcontroller SWO pin output compatible with UART (8N1)
# # 8000000 is the frequency of the SWO pin
# monitor tpiu config external uart off 8000000 2000000

# # enable ITM port 0
monitor itm port 0 on

load

# start the process but immediately halt the processor
stepi
2 changes: 1 addition & 1 deletion openocd_program.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ if (( $# != 1 )); then
exit 1
fi

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

0 comments on commit 523ec0a

Please sign in to comment.