aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorFelipe Balbi <[email protected]>2025-11-07 11:00:15 -0800
committerGitHub <[email protected]>2025-11-07 11:00:15 -0800
commit5632acec18cc5906b1625a8facf530db56c73300 (patch)
treeabf2897f4b2f9814069c64611896be2d42cf2ce8 /tools
parent47e383545f4aac3bfaec0563429cc721540e665a (diff)
parent9590d94ee9ba016f65a13100c429fc56ffe58e40 (diff)
Merge pull request #1 from bogdan-petru/import/mcxa276-initial
feat(mcxa276): initial HAL import
Diffstat (limited to 'tools')
-rw-r--r--tools/run_and_attach_rtt.sh24
-rw-r--r--tools/run_jlink_noblock.sh76
2 files changed, 100 insertions, 0 deletions
diff --git a/tools/run_and_attach_rtt.sh b/tools/run_and_attach_rtt.sh
new file mode 100644
index 000000000..13041d06b
--- /dev/null
+++ b/tools/run_and_attach_rtt.sh
@@ -0,0 +1,24 @@
1#!/usr/bin/env bash
2set -euo pipefail
3
4ELF="${1:-target/thumbv8m.main-none-eabihf/debug/examples/hello}"
5PROBE_ID="${2:-1fc9:0143:H3AYDQVQMTROB}"
6CHIP="${3:-MCXA276}"
7SPEED="${4:-1000}"
8
9# 1) Flash & run using the existing run.sh (probe is in use only during this step)
10./run.sh "$ELF"
11
12# 2) Give target a short moment to boot and set up RTT CB in RAM
13sleep 0.5
14
15# 3) Attach RTT/defmt using probe-rs (no flashing)
16exec probe-rs attach \
17 --chip "$CHIP" \
18 --probe "$PROBE_ID" \
19 --protocol swd \
20 --speed "$SPEED" \
21 "$ELF" \
22 --rtt-scan-memory \
23 --log-format oneline
24
diff --git a/tools/run_jlink_noblock.sh b/tools/run_jlink_noblock.sh
new file mode 100644
index 000000000..3ea1f2b4b
--- /dev/null
+++ b/tools/run_jlink_noblock.sh
@@ -0,0 +1,76 @@
1#!/usr/bin/env bash
2set -euo pipefail
3
4ELF="${1:-}"
5PROBE_ID="${2:-1366:0101:000600110607}" # default to your J-Link
6CHIP="${3:-MCXA276}"
7SPEED="${4:-1000}"
8PORT="${PROBE_RS_GDB_PORT:-1337}"
9
10if [[ -z "${ELF}" || ! -f "${ELF}" ]]; then
11 echo "Usage: $0 <elf> [probe-id] [chip] [speed-khz]" >&2
12 exit 1
13fi
14
15if ! command -v probe-rs >/dev/null 2>&1; then
16 echo "probe-rs not found (cargo install probe-rs --features cli)" >&2
17 exit 1
18fi
19if ! command -v gdb-multiarch >/dev/null 2>&1; then
20 echo "gdb-multiarch not found; install it (e.g., sudo apt install gdb-multiarch)." >&2
21 exit 1
22fi
23
24# Start probe-rs GDB server
25SERVER_LOG=$(mktemp)
26probe-rs gdb --chip "${CHIP}" --protocol swd --speed "${SPEED}" --non-interactive "${ELF}" --probe "${PROBE_ID}" \
27 >"${SERVER_LOG}" 2>&1 &
28GDB_SERVER_PID=$!
29
30# Wait for readiness
31for _ in {1..50}; do
32 if grep -q "Firing up GDB stub" "${SERVER_LOG}"; then break; fi
33 if grep -q "Connecting to the chip was unsuccessful" "${SERVER_LOG}"; then
34 echo "probe-rs gdb server failed. Log:" >&2
35 sed -e 's/^/ /' "${SERVER_LOG}" >&2 || true
36 kill "${GDB_SERVER_PID}" 2>/dev/null || true
37 exit 1
38 fi
39 sleep 0.1
40done
41
42# GDB script: load, resume, detach
43GDB_SCRIPT=$(mktemp)
44cat >"${GDB_SCRIPT}" <<EOF
45set pagination off
46set confirm off
47set mem inaccessible-by-default off
48
49target remote :${PORT}
50monitor halt
51load
52set language c
53# Start clean from Reset vector in RAM
54set {int}0xE000ED08 = 0x20000000
55set \$xpsr = 0x01000000
56set \$sp = 0x20020000
57set \$pc = Reset
58monitor resume
59detach
60quit
61EOF
62
63# Run GDB to program and resume target, then exit (probe released)
64if ! gdb-multiarch -q -x "${GDB_SCRIPT}" "${ELF}"; then
65 echo "GDB failed; server log:" >&2
66 sed -e 's/^/ /' "${SERVER_LOG}" >&2 || true
67 kill "${GDB_SERVER_PID}" 2>/dev/null || true
68 exit 1
69fi
70
71# Stop server now that we've detached
72kill "${GDB_SERVER_PID}" 2>/dev/null || true
73rm -f "${GDB_SCRIPT}" "${SERVER_LOG}" || true
74
75echo "Flashed, resumed, and detached (probe free)."
76