From 080ed3b49be70760aba7f6107fbec1294b171526 Mon Sep 17 00:00:00 2001 From: wxyyy0117 Date: Thu, 30 Oct 2025 13:50:37 +0100 Subject: [PATCH 1/4] tools: Integrate Corex-debugger. Signed-off-by: wxyyy0117 --- docs/debugging-instructions.rst | 20 ++++ tools/gen_launch.sh | 150 ++++++++++++++++++++++++++++ tools/vscode_profile/task_psoc.json | 114 +++++++++++++++++++++ 3 files changed, 284 insertions(+) create mode 100644 docs/debugging-instructions.rst create mode 100755 tools/gen_launch.sh create mode 100644 tools/vscode_profile/task_psoc.json diff --git a/docs/debugging-instructions.rst b/docs/debugging-instructions.rst new file mode 100644 index 00000000..94ef7717 --- /dev/null +++ b/docs/debugging-instructions.rst @@ -0,0 +1,20 @@ +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 `task_psoc6.json` file from `tools/vscode-profile` to the `.vscode` directory and rename it to `tasks.json` in your project root. +#. In VS Code, run the task: **Generate launch.json for debug (PSoC6)**. +#. Required parameters for this task: + * **fqbn**: Fully Qualified Board Name (e.g., `infineon:psoc6:cy8ckit_062s2_ai`) + * **build path**: Directory where the `.elf` file will be placed + * **example path**: Path to the sketch (`.ino` file) to debug (ensure it has been built at least once to generate the required build files) +#. 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. \ No newline at end of file diff --git a/tools/gen_launch.sh b/tools/gen_launch.sh new file mode 100755 index 00000000..296eaac4 --- /dev/null +++ b/tools/gen_launch.sh @@ -0,0 +1,150 @@ +#!/bin/bash +# gen_launch.sh: Compile and generate launch.json for XMC or PSoC6 boards +# Usage: ./gen_launch.sh [boards.txt] [gdb_path] +# : Fully Qualified Board Name (e.g. infineon:psoc6:CY8CKIT_062S2_AI or arduino-git:xmc:kit_xmc47_relax) +# : Directory where the .elf file will be placed +# : Path to the sketch (.ino) file +# [boards.txt] : (Optional) Path to boards.txt (default: inferred based on device) +# [gdb_path] : (Optional) Path to GDB executable (default: inferred based on device) + +set -e + +FQBN_FULL="$1" +BUILD_PATH="$2" +SKETCH_PATH="$3" + +if [[ -z "$FQBN_FULL" || -z "$BUILD_PATH" || -z "$SKETCH_PATH" ]]; then + echo "Usage: $0 [boards.txt] [gdb_path]" + exit 1 +fi + +# Get the script directory and package root +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PACKAGE_DIR="$(dirname "$SCRIPT_DIR")" + +# Detect device type based on FQBN +if [[ "$FQBN_FULL" == infineon:psoc6:* ]]; then + DEVICE_TYPE="psoc6" + BOARDS_TXT="${4:-$PACKAGE_DIR/boards.txt}" + GDB_PATH="${5:-$HOME/.arduino15/packages/infineon/tools/mtb-gcc-arm-none-eabi/11.3.1.67/bin/arm-none-eabi-gdb}" +elif [[ "$FQBN_FULL" == arduino-git:xmc:* ]]; then + DEVICE_TYPE="xmc" + XMC_DIR="$(dirname "$SCRIPT_DIR")" + BOARDS_TXT="${4:-$XMC_DIR/boards.txt}" + GDB_PATH="${5:-$HOME/.arduino15/packages/infineon/tools/arm-none-eabi-gcc/10.3-2021.10/bin/arm-none-eabi-gdb}" +else + echo "Unsupported device type in FQBN: $FQBN_FULL" + exit 1 +fi + +# Extract board name from FQBN +BOARD_NAME=$(echo "$FQBN_FULL" | awk -F: '{print $NF}') + +# Compile the sketch +arduino-cli compile -b "${FQBN_FULL}" --build-path "${BUILD_PATH}" "${SKETCH_PATH}" || exit 1 + +# Parse boards.txt for variant and other parameters +VARIANT=$(grep "^${BOARD_NAME}\.build\.variant=" "$BOARDS_TXT" | cut -d= -f2) +if [[ -z "$VARIANT" ]]; then + echo "Could not find variant for $BOARD_NAME in $BOARDS_TXT" + exit 2 +fi + +if [[ "$DEVICE_TYPE" == "xmc" ]]; then + BOARD_V=$(grep "^${BOARD_NAME}\.build\.board\.v=" "$BOARDS_TXT" | cut -d= -f2) + if [[ -z "$BOARD_V" ]]; then + echo "Could not find board.v for $BOARD_NAME in $BOARDS_TXT" + exit 2 + fi + DEVICE="${VARIANT}-${BOARD_V}" +else + DEVICE="${VARIANT}" +fi + +# Find the .elf executable +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 + +# Create the .vscode directory and generate launch.json +LAUNCH_DIR="$PACKAGE_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 + +if [[ "$DEVICE_TYPE" == "psoc6" ]]; then + # Generate launch.json for PSoC6 + cat > "$LAUNCH_DIR/launch.json" < "$LAUNCH_DIR/launch.json" < Date: Thu, 30 Oct 2025 13:52:48 +0100 Subject: [PATCH 2/4] tools: Modify shell script. Signed-off-by: wxyyy0117 --- tools/gen_launch.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/gen_launch.sh b/tools/gen_launch.sh index 296eaac4..6a7386a1 100755 --- a/tools/gen_launch.sh +++ b/tools/gen_launch.sh @@ -109,8 +109,7 @@ if [[ "$DEVICE_TYPE" == "psoc6" ]]; then "numberOfProcessors": 2, "targetProcessor": 1,// Set to 0 for the CM0+, set to 1 for the CM4 "postStartSessionCommands": [ - "monitor gdb_sync", - "stepi" + "continue" ], "overrideRestartCommands": [ "starti" From e89170ac851020e67335357418bbb1a2d77c72d6 Mon Sep 17 00:00:00 2001 From: wxyyy0117 Date: Thu, 6 Nov 2025 11:12:57 +0100 Subject: [PATCH 3/4] tools/vscode_profile: Change typo. Signed-off-by: wxyyy0117 --- tools/vscode_profile/task_psoc.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/vscode_profile/task_psoc.json b/tools/vscode_profile/task_psoc.json index f6974ddb..aa4d3ea0 100644 --- a/tools/vscode_profile/task_psoc.json +++ b/tools/vscode_profile/task_psoc.json @@ -22,7 +22,6 @@ "command": "arduino-cli", "args": [ "upload", - // "--verbose", "-p", "${input:port}", "--fqbn", "${input:boardFqbn}", "${input:examplePath}" @@ -35,7 +34,7 @@ "problemMatcher": [] }, { - "label": "Generate lauch.json for debug (PSOC)", + "label": "Generate launch.json for debug (PSOC)", "type": "shell", "command": "${workspaceFolder}/tools/gen_launch.sh", "args": [ @@ -109,6 +108,6 @@ "type": "promptString", "description": "(Optional) Enter the path to arm-none-eabi-gdb, or leave blank for default", "default": "" - }, + } ] } \ No newline at end of file From d5fcc1907d2748da908c0c0133944afb583e0588 Mon Sep 17 00:00:00 2001 From: wxyyy0117 Date: Thu, 27 Nov 2025 11:30:19 +0100 Subject: [PATCH 4/4] docs: Fix typo and add command. Signed-off-by: wxyyy0117 --- docs/debugging-instructions.rst | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/debugging-instructions.rst b/docs/debugging-instructions.rst index 94ef7717..eccc87f9 100644 --- a/docs/debugging-instructions.rst +++ b/docs/debugging-instructions.rst @@ -4,7 +4,7 @@ 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 `task_psoc6.json` file from `tools/vscode-profile` to the `.vscode` directory and rename it to `tasks.json` in your project root. +#. Copy the `task_psoc.json` file from `tools/vscode-profile` to the `.vscode` directory and rename it to `tasks.json` in your project root. #. In VS Code, run the task: **Generate launch.json for debug (PSoC6)**. #. Required parameters for this task: * **fqbn**: Fully Qualified Board Name (e.g., `infineon:psoc6:cy8ckit_062s2_ai`) @@ -14,6 +14,15 @@ Debugging support described here is for Visual Studio Code. The Arduino IDE alre * **boards.txt path**: Path to a custom `boards.txt` file * **gdb path**: Path to a custom GDB executable +Manual Usage +------------ + +You can also generate the `launch.json` file manually using the `gen_launch.sh` script: + +.. code-block:: bash + + ./tools/gen_launch.sh --fqbn --build-path --example-path [--boards-txt ] [--gdb-path ] + Refer to the documentation of your chosen debugger and scripts in the `tools/` folder for more details. .. note::