-
Notifications
You must be signed in to change notification settings - Fork 5
Integrate cortex debugger #165
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
Open
wxyyy0117
wants to merge
4
commits into
Infineon:main
Choose a base branch
from
wxyyy0117:integrate_cortex_debugger
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| 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_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`) | ||
| * **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 | ||
|
|
||
| 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 <board_fqbn> --build-path <path_to_build> --example-path <path_to_sketch> [--boards-txt <path_to_boards.txt>] [--gdb-path <path_to_gdb>] | ||
|
|
||
| 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. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| #!/bin/bash | ||
| # gen_launch.sh: Compile and generate launch.json for XMC or PSoC6 boards | ||
| # Usage: ./gen_launch.sh <fqbn> <build_path> <sketch_path> [boards.txt] [gdb_path] | ||
| # <fqbn> : Fully Qualified Board Name (e.g. infineon:psoc6:CY8CKIT_062S2_AI or 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: 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 <fqbn> <build_path> <sketch_path> [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" <<EOF | ||
| { | ||
| "version": "0.2.0", | ||
| "configurations": [ | ||
| { | ||
|
|
||
| "name": "Cortex-Debug: Debug ${DEVICE} CM4", | ||
| "type": "cortex-debug", | ||
| "request": "launch", | ||
| "servertype": "openocd", | ||
| "device": "${DEVICE}", | ||
| "executable": "${EXECUTABLE}", | ||
| "cwd": "\${workspaceFolder}", | ||
| "interface": "swd", | ||
| "gdbPath": "${GDB_PATH}", | ||
| "showDevDebugOutput": "vscode", | ||
| "configFiles": [ | ||
| "$HOME/.arduino15/packages/infineon/tools/openocd/5.2.1.3248/scripts/interface/kitprog3.cfg", | ||
| "$HOME/.arduino15/packages/infineon/tools/openocd/5.2.1.3248/scripts/target/psoc6_2m.cfg" | ||
| ], | ||
| "overrideLaunchCommands": [ | ||
| "set mem inaccessible-by-default off", | ||
| "-enable-pretty-printing", | ||
| "set remotetimeout 15", | ||
| "monitor reset run", | ||
| "monitor psoc6 reset_halt sysresetreq" | ||
| ], | ||
| "numberOfProcessors": 2, | ||
| "targetProcessor": 1,// Set to 0 for the CM0+, set to 1 for the CM4 | ||
| "postStartSessionCommands": [ | ||
| "continue" | ||
| ], | ||
| "overrideRestartCommands": [ | ||
| "starti" | ||
| ], | ||
| "postRestartSessionCommands": [], | ||
| "breakAfterReset": true | ||
| } | ||
| ] | ||
| } | ||
| EOF | ||
| else | ||
| # Generate launch.json for XMC | ||
| cat > "$LAUNCH_DIR/launch.json" <<EOF | ||
| { | ||
| "version": "0.2.0", | ||
| "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 | ||
| fi | ||
|
|
||
| echo "launch.json generated for ${DEVICE_TYPE} device ${DEVICE} at $LAUNCH_DIR." | ||
| echo "(Using boards.txt at $BOARDS_TXT)" | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| { | ||
| "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", | ||
| "-p", "${input:port}", | ||
| "--fqbn", "${input:boardFqbn}", | ||
| "${input:examplePath}" | ||
| ], | ||
| "dependsOn": "Arduino Build", | ||
| "group": { | ||
| "kind": "build", | ||
| "isDefault": true | ||
| }, | ||
| "problemMatcher": [] | ||
| }, | ||
| { | ||
| "label": "Generate launch.json for debug (PSOC)", | ||
| "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": "infineon:psoc6:cy8ckit_062s2_ai" | ||
| }, | ||
| { | ||
| "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": "" | ||
| } | ||
| ] | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.