Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
20 changes: 20 additions & 0 deletions docs/development-instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,26 @@ Tests are located in ``tests/arduino-core-tests`` and included as submodule in t

If you need to run these tests locally, you'll also need to download `GNU Make <https://www.gnu.org/software/make/#download>`_ .

Debugging (VS Code)
^^^^^^^^^^^^^^^^^^^^
Debugging support described here is for Visual Studio Code. The Arduino IDE already provides a built-in debugger for supported boards.

#. Install the `Cortex-Debug` extension in VS Code.
#. Copy the `tasks.json` file from `tools/vscode-profile` to the `.vscode` directory in your project root.
#. In VS Code, run the task: **Generate launch.json for debug (XMC)**.
#. Required parameters for this task:
* **fqbn**: Fully Qualified Board Name (e.g., `arduino-git:xmc:kit_xmc47_relax`)
* **build path**: Directory where the `.elf` file will be placed
* **example path**: Path to the sketch (`.ino` file) to debug
#. Optional parameters:
* **boards.txt path**: Path to a custom `boards.txt` file
* **gdb path**: Path to a custom GDB executable

Refer to the documentation of your chosen debugger and scripts in the `tools/` folder for more details.

.. note::
If you encounter an error indicating that ``libncurses.so.5`` or a similar library cannot be found, please search online and install the appropriate package for your environment.

Release
---------
Add a git tag in the format `Vx.y.z` (e.g. V3.3.0) to trigger the release process.
Expand Down
85 changes: 85 additions & 0 deletions tools/gen_launch.sh
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}"
Copy link
Collaborator

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

Copy link
Collaborator

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


# 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)"
Copy link
Collaborator

Choose a reason for hiding this comment

The 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",
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": "vscode"
}
]
}
EOF

echo "launch.json generated for device ${DEVICE} at $LAUNCH_DIR."
echo "(Using boards.txt at $BOARDS_TXT)"


114 changes: 114 additions & 0 deletions tools/vscode_profile/tasks.json
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": ""
},
]
}
Loading