Skip to content

Commit b2d60c4

Browse files
committed
tools: Make gen_launch.sh generic.
Signed-off-by: wxyyy0117 <wxyyy2002@outlook.com>
1 parent 04330f5 commit b2d60c4

File tree

3 files changed

+210
-31
lines changed

3 files changed

+210
-31
lines changed

docs/development-instructions.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ Debugging (VS Code)
129129
Debugging support described here is for Visual Studio Code. The Arduino IDE already provides a built-in debugger for supported boards.
130130

131131
#. Install the `Cortex-Debug` extension in VS Code.
132-
#. Copy the `tasks.json` file from `tools/vscode-profile` to the `.vscode` directory in your project root.
132+
#. Copy the `task_xmc.json` file from `tools/vscode-profile` to the `.vscode` directory and rename to `tasks.json` in your project root.
133133
#. In VS Code, run the task: **Generate launch.json for debug (XMC)**.
134134
#. Required parameters for this task:
135135
* **fqbn**: Fully Qualified Board Name (e.g., `arduino-git:xmc:kit_xmc47_relax`)
136136
* **build path**: Directory where the `.elf` file will be placed
137-
* **example path**: Path to the sketch (`.ino` file) to debug
137+
* **example path**: Path to the sketch (`.ino` file) to debug (for arduino-core-tests make sure it has been built at least once to generate the required build.ino)
138138
#. Optional parameters:
139139
* **boards.txt path**: Path to a custom `boards.txt` file
140140
* **gdb path**: Path to a custom GDB executable

tools/gen_launch.sh

Lines changed: 94 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,129 @@
11
#!/bin/bash
2-
# gen_launch.sh: Compile and generate launch.json for XMC boards
2+
# gen_launch.sh: Compile and generate launch.json for XMC or PSoC6 boards
33
# Usage: ./gen_launch.sh <fqbn> <build_path> <sketch_path> [boards.txt] [gdb_path]
4-
# <fqbn> : Fully Qualified Board Name (e.g. arduino-git:xmc:kit_xmc47_relax)
4+
# <fqbn> : Fully Qualified Board Name (e.g. infineon:psoc6:CY8CKIT_062S2_AI or arduino-git:xmc:kit_xmc47_relax)
55
# <build_path> : Directory where the .elf file will be placed
66
# <sketch_path> : Path to the sketch (.ino) file
7-
# [boards.txt] : (Optional) Path to boards.txt (default: $HOME/Arduino/hardware/arduino-git/xmc/boards.txt)
8-
# [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)
9-
# 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
7+
# [boards.txt] : (Optional) Path to boards.txt (default: inferred based on device)
8+
# [gdb_path] : (Optional) Path to GDB executable (default: inferred based on device)
109

1110
set -e
1211

13-
14-
1512
FQBN_FULL="$1"
1613
BUILD_PATH="$2"
1714
SKETCH_PATH="$3"
18-
# Allow BOARDS_TXT as optional 4th parameter, default to original absolute path
19-
BOARDS_TXT="${4:-$HOME/Arduino/hardware/arduino-git/xmc/boards.txt}"
20-
21-
# Extract board name from FQBN (e.g. arduino-git:xmc:kit_xmc47_relax -> kit_xmc47_relax)
22-
BOARD_NAME=$(echo "$FQBN_FULL" | awk -F: '{print $NF}')
23-
24-
25-
# Allow GDB_PATH as optional 5th parameter, default to Infineon toolchain path
26-
GDB_PATH="${5:-$HOME/.arduino15/packages/infineon/tools/arm-none-eabi-gcc/10.3-2021.10/bin/arm-none-eabi-gdb}"
2715

2816
if [[ -z "$FQBN_FULL" || -z "$BUILD_PATH" || -z "$SKETCH_PATH" ]]; then
2917
echo "Usage: $0 <fqbn> <build_path> <sketch_path> [boards.txt] [gdb_path]"
3018
exit 1
3119
fi
3220

33-
# 1. Compile
34-
arduino-cli compile -b "${FQBN_FULL}" --build-path "${BUILD_PATH}" "${SKETCH_PATH}" || exit 1
21+
# Get the script directory and package root
22+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
23+
PACKAGE_DIR="$(dirname "$SCRIPT_DIR")"
24+
25+
# Detect device type based on FQBN
26+
if [[ "$FQBN_FULL" == infineon:psoc6:* ]]; then
27+
DEVICE_TYPE="psoc6"
28+
BOARDS_TXT="${4:-$PACKAGE_DIR/boards.txt}"
29+
GDB_PATH="${5:-$HOME/.arduino15/packages/Infineon/tools/arm-none-eabi-gcc/10.3-2021.10/bin/arm-none-eabi-gdb}"
30+
elif [[ "$FQBN_FULL" == arduino-git:xmc:* ]]; then
31+
DEVICE_TYPE="xmc"
32+
XMC_DIR="$(dirname "$SCRIPT_DIR")"
33+
BOARDS_TXT="${4:-$XMC_DIR/boards.txt}"
34+
GDB_PATH="${5:-$HOME/.arduino15/packages/infineon/tools/arm-none-eabi-gcc/10.3-2021.10/bin/arm-none-eabi-gdb}"
35+
else
36+
echo "Unsupported device type in FQBN: $FQBN_FULL"
37+
exit 1
38+
fi
3539

36-
# 2. Parse boards.txt for variant and board.v using board name
37-
VARIANT=$(grep "^${BOARD_NAME}\.build\.variant=" "$BOARDS_TXT" | cut -d= -f2)
38-
BOARD_V=$(grep "^${BOARD_NAME}\.build\.board\.v=" "$BOARDS_TXT" | cut -d= -f2)
40+
# Extract board name from FQBN
41+
BOARD_NAME=$(echo "$FQBN_FULL" | awk -F: '{print $NF}')
3942

40-
if [[ -z "$VARIANT" || -z "$BOARD_V" ]]; then
41-
echo "Could not find variant or board.v for $BOARD_NAME in $BOARDS_TXT"
43+
# Compile the sketch
44+
arduino-cli compile -b "${FQBN_FULL}" --build-path "${BUILD_PATH}" "${SKETCH_PATH}" || exit 1
4245

46+
# Parse boards.txt for variant and other parameters
47+
VARIANT=$(grep "^${BOARD_NAME}\.build\.variant=" "$BOARDS_TXT" | cut -d= -f2)
48+
if [[ -z "$VARIANT" ]]; then
49+
echo "Could not find variant for $BOARD_NAME in $BOARDS_TXT"
4350
exit 2
4451
fi
4552

46-
DEVICE="${VARIANT}-${BOARD_V}"
53+
if [[ "$DEVICE_TYPE" == "xmc" ]]; then
54+
BOARD_V=$(grep "^${BOARD_NAME}\.build\.board\.v=" "$BOARDS_TXT" | cut -d= -f2)
55+
if [[ -z "$BOARD_V" ]]; then
56+
echo "Could not find board.v for $BOARD_NAME in $BOARDS_TXT"
57+
exit 2
58+
fi
59+
DEVICE="${VARIANT}-${BOARD_V}"
60+
else
61+
DEVICE="${VARIANT}"
62+
fi
63+
64+
# Find the .elf executable
4765
EXECUTABLE=$(find "${BUILD_PATH}" -maxdepth 1 -type f -name "*.elf" | head -n 1)
4866
if [[ -z "$EXECUTABLE" ]]; then
4967
echo "No .elf executable found in $BUILD_PATH."
5068
exit 3
5169
fi
5270

53-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
54-
XMC_DIR="$(dirname "$SCRIPT_DIR")"
55-
LAUNCH_DIR="$XMC_DIR/.vscode"
71+
# Create the .vscode directory and generate launch.json
72+
LAUNCH_DIR="$PACKAGE_DIR/.vscode"
5673
if [ ! -d "$LAUNCH_DIR" ]; then
5774
mkdir -p "$LAUNCH_DIR"
5875
fi
5976
if [ -f "$LAUNCH_DIR/launch.json" ]; then
6077
rm "$LAUNCH_DIR/launch.json"
6178
fi
62-
cat > "$LAUNCH_DIR/launch.json" <<EOF
79+
80+
if [[ "$DEVICE_TYPE" == "psoc6" ]]; then
81+
# Generate launch.json for PSoC6
82+
cat > "$LAUNCH_DIR/launch.json" <<EOF
83+
{
84+
"version": "0.2.0",
85+
"configurations": [
86+
{
87+
88+
"name": "Cortex-Debug: Debug ${DEVICE} CM4",
89+
"type": "cortex-debug",
90+
"request": "launch",
91+
"servertype": "openocd",
92+
"device": "${DEVICE}",
93+
"executable": "${EXECUTABLE}",
94+
"cwd": "\${workspaceFolder}",
95+
"interface": "swd",
96+
"gdbPath": "${GDB_PATH}",
97+
"showDevDebugOutput": "vscode",
98+
"configFiles": [
99+
"$HOME/.arduino15/packages/infineon/tools/openocd/5.2.1.3248/scripts/interface/kitprog3.cfg",
100+
"$HOME/.arduino15/packages/infineon/tools/openocd/5.2.1.3248/scripts/target/psoc6_2m.cfg"
101+
],
102+
"overrideLaunchCommands": [
103+
"set mem inaccessible-by-default off",
104+
"-enable-pretty-printing",
105+
"set remotetimeout 15",
106+
"monitor reset run",
107+
"monitor psoc6 reset_halt sysresetreq"
108+
],
109+
"numberOfProcessors": 2,
110+
"targetProcessor": 1,// Set to 0 for the CM0+, set to 1 for the CM4
111+
"postStartSessionCommands": [
112+
"monitor gdb_sync",
113+
"stepi"
114+
],
115+
"overrideRestartCommands": [
116+
"starti"
117+
],
118+
"postRestartSessionCommands": [],
119+
"breakAfterReset": true
120+
}
121+
]
122+
}
123+
EOF
124+
else
125+
# Generate launch.json for XMC
126+
cat > "$LAUNCH_DIR/launch.json" <<EOF
63127
{
64128
"version": "0.2.0",
65129
"configurations": [
@@ -78,8 +142,9 @@ cat > "$LAUNCH_DIR/launch.json" <<EOF
78142
]
79143
}
80144
EOF
145+
fi
81146

82-
echo "launch.json generated for device ${DEVICE} at $LAUNCH_DIR."
147+
echo "launch.json generated for ${DEVICE_TYPE} device ${DEVICE} at $LAUNCH_DIR."
83148
echo "(Using boards.txt at $BOARDS_TXT)"
84149

85150

tools/vscode_profile/task_xmc.json

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "Arduino Build",
6+
"type": "shell",
7+
"command": "arduino-cli",
8+
"args": [
9+
"compile",
10+
"--fqbn", "${input:boardFqbn}",
11+
"${input:examplePath}"
12+
],
13+
"group": {
14+
"kind": "build",
15+
"isDefault": false
16+
},
17+
"problemMatcher": []
18+
},
19+
{
20+
"label": "Arduino Upload",
21+
"type": "shell",
22+
"command": "arduino-cli",
23+
"args": [
24+
"upload",
25+
// "--verbose",
26+
"-p", "${input:port}",
27+
"--fqbn", "${input:boardFqbn}",
28+
"${input:examplePath}"
29+
],
30+
"dependsOn": "Arduino Build",
31+
"group": {
32+
"kind": "build",
33+
"isDefault": true
34+
},
35+
"problemMatcher": []
36+
},
37+
{
38+
"label": "Generate lauch.json for debug (XMC)",
39+
"type": "shell",
40+
"command": "${workspaceFolder}/tools/gen_launch.sh",
41+
"args": [
42+
"${input:boardFqbn}",
43+
"${input:debugBuildPath}",
44+
"${input:examplePath}",
45+
"${input:boardsTxtPath}",
46+
"${input:gdbPath}"
47+
],
48+
"group": {
49+
"kind": "build",
50+
"isDefault": false
51+
},
52+
"problemMatcher": [],
53+
"presentation": {
54+
"echo": true,
55+
"reveal": "always",
56+
"focus": false,
57+
"panel": "shared"
58+
}
59+
},
60+
{
61+
"label": "Arduino Monitor",
62+
"type": "shell",
63+
"command": "arduino-cli",
64+
"args": [
65+
"monitor",
66+
"-p", "${input:port}",
67+
"-c", "baudrate=115200"
68+
],
69+
"group": {
70+
"kind": "build",
71+
"isDefault": false
72+
},
73+
"problemMatcher": []
74+
}
75+
],
76+
"inputs": [
77+
{
78+
"id": "boardFqbn",
79+
"type": "promptString",
80+
"description": "Enter the FQBN (Fully Qualified Board Name) for the Arduino board",
81+
"default": "arduino-git:xmc:kit_xmc47_relax"
82+
},
83+
{
84+
"id": "debugBuildPath",
85+
"type": "promptString",
86+
"description": "Enter the build path where the .elf file would be placed",
87+
"default": "${workspaceFolder}/extras/arduino-core-tests/build/output"
88+
},
89+
{
90+
"id": "examplePath",
91+
"type": "promptString",
92+
"description": "Enter the path to the Arduino example sketch",
93+
"default": "${workspaceFolder}/examples/bug/bug.ino"
94+
},
95+
{
96+
"id": "port",
97+
"type": "promptString",
98+
"description": "Enter the port for the Arduino board",
99+
"default": "/dev/ttyACM0"
100+
},
101+
{
102+
"id": "boardsTxtPath",
103+
"type": "promptString",
104+
"description": "(Optional) Enter the path to boards.txt, or leave blank for default",
105+
"default": ""
106+
},
107+
{
108+
"id": "gdbPath",
109+
"type": "promptString",
110+
"description": "(Optional) Enter the path to arm-none-eabi-gdb, or leave blank for default",
111+
"default": ""
112+
},
113+
]
114+
}

0 commit comments

Comments
 (0)