-
Notifications
You must be signed in to change notification settings - Fork 0
/
watch_rtt.sh
executable file
·69 lines (58 loc) · 2.04 KB
/
watch_rtt.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#! /bin/sh
# This script allows to print RTT output at the console while debugging with CLion + OpenOCD/GDB
#
# First, start OpenOCD from a CLion run config.
# Then run this script at the console:
# > watch_rtt.sh
#
# This script will:
# 1) tell OpenOCD to start it's RTT server
# 2) tail the RTT server's output
#
# Original recipe from https://ferrous-systems.com/blog/gdb-and-defmt/
# check that required apps are on path
type rust-nm >/dev/null 2>&1 || { echo >&2 "Missing rust-nm from cargo-binutils."; exit 1; }
type nc >/dev/null 2>&1 || { echo >&2 "Missing netcat."; exit 1; }
type openocd >/dev/null 2>&1 || { echo >&2 "Missing OpenOCD."; exit 1; }
type defmt-print >/dev/null 2>&1 || { echo >&2 "Missing defmt-print."; exit 1; }
# base env setup
BASEDIR="$( cd "$( dirname "$0" )" && pwd )"
TELNET_PORT=4444
RTT_PORT=8745
BUILD=${1:-debug}
# bluepill is default
TARGET=${2:-thumbv7em-none-eabihf}
ELF_FILE=$BASEDIR/target/$TARGET/$BUILD/dv6
# OpenOCD should be running
if ! nc -z localhost $TELNET_PORT; then
echo "OpenOCD not running? Else make sure it is listening for telnet on port $TELNET_PORT"
# TODO start OpenOCD & flash $ELF_FILE ? assumed done by IDE (for debug) for now
exit
else
echo "OpenOCD running"
fi
if ! nc -z localhost $RTT_PORT; then
# get address of static RTT buffer from binary
block_addr=0x$(rust-nm -S $ELF_FILE | grep SEGGER_RTT | cut -d' ' -f1)
echo "Starting RTT from block addr $block_addr (from $ELF_FILE)"
# Tell GDB to start its RTT server
# See https://stackoverflow.com/questions/48578664/capturing-telnet-timeout-from-bash
nc localhost $TELNET_PORT <<EOF
rtt server start $RTT_PORT 0
rtt setup $block_addr 0x8000 "SEGGER RTT"
rtt start
exit
EOF
if ! nc -z localhost $RTT_PORT; then
echo "RTT port still not up :("
exit
fi
else
echo "RTT port is open"
fi
# if using plain RTT https://crates.io/crates/rtt-target
#echo "Watching RTT/text"
#nc localhost $RTT_PORT
# if using defmt over RTT
echo "Watching RTT/defmt from '$ELF_FILE'"
nc localhost $RTT_PORT | defmt-print -e $ELF_FILE