-
Notifications
You must be signed in to change notification settings - Fork 73
Integrate cortex debugger #398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.0.0-pre-release
Are you sure you want to change the base?
Changes from all commits
0b84add
20e93fe
8486d4f
398e5b8
9abae43
04330f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/bin/bash | ||
# gen_launch.sh: Compile and generate launch.json for XMC boards | ||
# Usage: ./gen_launch.sh <fqbn> <build_path> <sketch_path> [boards.txt] [gdb_path] | ||
# <fqbn> : Fully Qualified Board Name (e.g. arduino-git:xmc:kit_xmc47_relax) | ||
# <build_path> : Directory where the .elf file will be placed | ||
# <sketch_path> : Path to the sketch (.ino) file | ||
# [boards.txt] : (Optional) Path to boards.txt (default: $HOME/Arduino/hardware/arduino-git/xmc/boards.txt) | ||
# [gdb_path] : (Optional) Path to GDB executable (default: $HOME/.arduino15/packages/Infineon/tools/arm-none-eabi-gcc/10.3-2021.10/bin/arm-none-eabi-gdb) | ||
# Example: ./gen_launch.sh arduino-git:xmc:kit_xmc47_relax ~/output ~/build/Blink.ino ~/Arduino/hardware/arduino-git/xmc/boards.txt /usr/bin/arm-none-eabi-gdb | ||
|
||
set -e | ||
|
||
|
||
|
||
FQBN_FULL="$1" | ||
BUILD_PATH="$2" | ||
SKETCH_PATH="$3" | ||
# Allow BOARDS_TXT as optional 4th parameter, default to original absolute path | ||
BOARDS_TXT="${4:-$HOME/Arduino/hardware/arduino-git/xmc/boards.txt}" | ||
|
||
# Extract board name from FQBN (e.g. arduino-git:xmc:kit_xmc47_relax -> kit_xmc47_relax) | ||
BOARD_NAME=$(echo "$FQBN_FULL" | awk -F: '{print $NF}') | ||
|
||
|
||
# Allow GDB_PATH as optional 5th parameter, default to Infineon toolchain path | ||
GDB_PATH="${5:-$HOME/.arduino15/packages/infineon/tools/arm-none-eabi-gcc/10.3-2021.10/bin/arm-none-eabi-gdb}" | ||
|
||
if [[ -z "$FQBN_FULL" || -z "$BUILD_PATH" || -z "$SKETCH_PATH" ]]; then | ||
echo "Usage: $0 <fqbn> <build_path> <sketch_path> [boards.txt] [gdb_path]" | ||
exit 1 | ||
fi | ||
|
||
# 1. Compile | ||
arduino-cli compile -b "${FQBN_FULL}" --build-path "${BUILD_PATH}" "${SKETCH_PATH}" || exit 1 | ||
|
||
# 2. Parse boards.txt for variant and board.v using board name | ||
VARIANT=$(grep "^${BOARD_NAME}\.build\.variant=" "$BOARDS_TXT" | cut -d= -f2) | ||
BOARD_V=$(grep "^${BOARD_NAME}\.build\.board\.v=" "$BOARDS_TXT" | cut -d= -f2) | ||
|
||
if [[ -z "$VARIANT" || -z "$BOARD_V" ]]; then | ||
echo "Could not find variant or board.v for $BOARD_NAME in $BOARDS_TXT" | ||
|
||
exit 2 | ||
fi | ||
|
||
DEVICE="${VARIANT}-${BOARD_V}" | ||
EXECUTABLE=$(find "${BUILD_PATH}" -maxdepth 1 -type f -name "*.elf" | head -n 1) | ||
if [[ -z "$EXECUTABLE" ]]; then | ||
echo "No .elf executable found in $BUILD_PATH." | ||
exit 3 | ||
fi | ||
|
||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like to place all optional variables at the beginning of the shell script, as this makes modifications later easier. |
||
XMC_DIR="$(dirname "$SCRIPT_DIR")" | ||
LAUNCH_DIR="$XMC_DIR/.vscode" | ||
if [ ! -d "$LAUNCH_DIR" ]; then | ||
mkdir -p "$LAUNCH_DIR" | ||
fi | ||
if [ -f "$LAUNCH_DIR/launch.json" ]; then | ||
rm "$LAUNCH_DIR/launch.json" | ||
fi | ||
cat > "$LAUNCH_DIR/launch.json" <<EOF | ||
{ | ||
"version": "0.2.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a better way to separate the JSON format from the shell script? |
||
"configurations": [ | ||
{ | ||
"name": "Cortex-Debug: Debug ${DEVICE}", | ||
"type": "cortex-debug", | ||
"request": "launch", | ||
"servertype": "jlink", | ||
"device": "${DEVICE}", | ||
"executable": "${EXECUTABLE}", | ||
"cwd": "\${workspaceFolder}", | ||
"interface": "swd", | ||
"gdbPath": "${GDB_PATH}", | ||
"showDevDebugOutput": "vscode" | ||
} | ||
] | ||
} | ||
EOF | ||
|
||
echo "launch.json generated for device ${DEVICE} at $LAUNCH_DIR." | ||
echo "(Using boards.txt at $BOARDS_TXT)" | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"label": "Arduino Build", | ||
"type": "shell", | ||
"command": "arduino-cli", | ||
"args": [ | ||
"compile", | ||
"--fqbn", "${input:boardFqbn}", | ||
"${input:examplePath}" | ||
], | ||
"group": { | ||
"kind": "build", | ||
"isDefault": false | ||
}, | ||
"problemMatcher": [] | ||
}, | ||
{ | ||
"label": "Arduino Upload", | ||
"type": "shell", | ||
"command": "arduino-cli", | ||
"args": [ | ||
"upload", | ||
// "--verbose", | ||
"-p", "${input:port}", | ||
"--fqbn", "${input:boardFqbn}", | ||
"${input:examplePath}" | ||
], | ||
"dependsOn": "Arduino Build", | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
}, | ||
"problemMatcher": [] | ||
}, | ||
{ | ||
"label": "Generate lauch.json for debug (XMC)", | ||
"type": "shell", | ||
"command": "${workspaceFolder}/tools/gen_launch.sh", | ||
"args": [ | ||
"${input:boardFqbn}", | ||
"${input:debugBuildPath}", | ||
"${input:examplePath}", | ||
"${input:boardsTxtPath}", | ||
"${input:gdbPath}" | ||
], | ||
"group": { | ||
"kind": "build", | ||
"isDefault": false | ||
}, | ||
"problemMatcher": [], | ||
"presentation": { | ||
"echo": true, | ||
"reveal": "always", | ||
"focus": false, | ||
"panel": "shared" | ||
} | ||
}, | ||
{ | ||
"label": "Arduino Monitor", | ||
"type": "shell", | ||
"command": "arduino-cli", | ||
"args": [ | ||
"monitor", | ||
"-p", "${input:port}", | ||
"-c", "baudrate=115200" | ||
], | ||
"group": { | ||
"kind": "build", | ||
"isDefault": false | ||
}, | ||
"problemMatcher": [] | ||
} | ||
], | ||
"inputs": [ | ||
{ | ||
"id": "boardFqbn", | ||
"type": "promptString", | ||
"description": "Enter the FQBN (Fully Qualified Board Name) for the Arduino board", | ||
"default": "arduino-git:xmc:kit_xmc47_relax" | ||
}, | ||
{ | ||
"id": "debugBuildPath", | ||
"type": "promptString", | ||
"description": "Enter the build path where the .elf file would be placed", | ||
"default": "${workspaceFolder}/extras/arduino-core-tests/build/output" | ||
}, | ||
{ | ||
"id": "examplePath", | ||
"type": "promptString", | ||
"description": "Enter the path to the Arduino example sketch", | ||
"default": "${workspaceFolder}/examples/bug/bug.ino" | ||
}, | ||
{ | ||
"id": "port", | ||
"type": "promptString", | ||
"description": "Enter the port for the Arduino board", | ||
"default": "/dev/ttyACM0" | ||
}, | ||
{ | ||
"id": "boardsTxtPath", | ||
"type": "promptString", | ||
"description": "(Optional) Enter the path to boards.txt, or leave blank for default", | ||
"default": "" | ||
}, | ||
{ | ||
"id": "gdbPath", | ||
"type": "promptString", | ||
"description": "(Optional) Enter the path to arm-none-eabi-gdb, or leave blank for default", | ||
"default": "" | ||
}, | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest set the default path to the working dir and relativ path- so os independent and less confusing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one another idea will be set the default in task.json