Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions tools/gen_launch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash
# gen_launch.sh: Compile and generate launch.json for XMC boards
# Usage: ./gen_launch.sh <fqbn> <build_path> <sketch_path>
# Example: ./gen_launch.sh kit_xmc47_relax ~/output ~/build/build.ino

set -e



FQBN_FULL="$1"
BUILD_PATH="$2"
SKETCH_PATH="$3"
BOARDS_TXT="$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}')

# Find arm-none-eabi-gdb
GDB_PATH=$(command -v arm-none-eabi-gdb)
if [ -z "$GDB_PATH" ]; then
# Try to find it under home directory only
GDB_PATH=$(find "$HOME" -type f -name arm-none-eabi-gdb 2>/dev/null | head -n 1)
fi
if [ -z "$GDB_PATH" ]; then
echo "arm-none-eabi-gdb not found in PATH or under your home directory."
exit 3
fi

if [[ -z "$FQBN_FULL" || -z "$BUILD_PATH" || -z "$SKETCH_PATH" ]]; then
echo "Usage: $0 <fqbn> <build_path> <sketch_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="${BUILD_PATH}/build.ino.elf"

# 3. Generate launch.json in xmc/.vscode
LAUNCH_DIR="../../.vscode"
if [ ! -d "$LAUNCH_DIR" ]; then
mkdir "$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",
Copy link
Collaborator

Choose a reason for hiding this comment

The 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?
Consider this: if we update Cortex Debug in the future, we'll have a new version of the JSON...

"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": "info"
}
]
}
EOF

echo "launch.json generated for device ${DEVICE} at $LAUNCH_DIR."


106 changes: 106 additions & 0 deletions tools/vscode_profile/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"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": "Arduino Debug",
"type": "shell",
"command": "${workspaceFolder}/tools/gen_launch.sh",
"args": [
"${input:boardFqbn}",
"${input:debugBuildPath}",
"${input:examplePath}"
],
"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 for gen_launch.sh",
"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"
},
]
}






Loading