Skip to content

Commit

Permalink
Merge pull request project-chip#86 from lukgni/flash_command
Browse files Browse the repository at this point in the history
Add vscode tasks for flashing and debugging Mbed Shell examples
  • Loading branch information
pan- authored Mar 2, 2021
2 parents 7503ee9 + 2e55ece commit 3928de0
Show file tree
Hide file tree
Showing 5 changed files with 313 additions and 4 deletions.
6 changes: 5 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ RUN apt-get -fy install git vim emacs sudo \
build-essential cmake cppcheck valgrind \
wget curl telnet \
docker.io \
iputils-ping net-tools
iputils-ping net-tools \
libncurses5

RUN python3 -m pip install pyocd pyusb

RUN groupadd -g $USER_GID $USERNAME
RUN useradd -s /bin/bash -u $USER_UID -g $USER_GID -G docker -m $USERNAME
RUN echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME
Expand Down
6 changes: 5 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined",
"--network=host"
"--network=host",
"-v",
"/dev/bus/usb:/dev/bus/usb:ro",
"--device-cgroup-rule=a 189:* rmw",
"--add-host=host.docker.internal:host-gateway"
],
"mounts": [
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind"
Expand Down
188 changes: 188 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,194 @@
"ignoreFailures": true
}
]
},
{
"name": "Shell Mbed Example Debug [remote]",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/examples/shell/mbed/build-${input:mbedTarget}/${input:mbedProfile}/chip-mbed-shell-example",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceRoot}/examples/shell/mbed",
"environment": [],
"externalConsole": false,
"debugServerArgs": "",
"serverLaunchTimeout": 20000,
"filterStderr": true,
"filterStdout": false,
"serverStarted": "GDB\\ server\\ started",
"setupCommands": [
{
"text": "-target-select remote host.docker.internal:3333",
"description": "connect to target",
"ignoreFailures": false
},
{
"text": "-file-exec-and-symbols ${workspaceRoot}/examples/shell/mbed/build-${input:mbedTarget}/${input:mbedProfile}/chip-mbed-shell-example",
"description": "load file",
"ignoreFailures": false
},
{
"text": "-interpreter-exec console \"monitor reset\"",
"ignoreFailures": false
},
{
"text": "-interpreter-exec console \"monitor halt\"",
"ignoreFailures": false
},
{
"text": "-interpreter-exec console \"monitor arm semihosting enable\"",
"ignoreFailures": false
},
{
"text": "-target-download",
"description": "flash target",
"ignoreFailures": false
}
],
"logging": {
"moduleLoad": true,
"trace": true,
"engineLogging": true,
"programOutput": true,
"exceptions": true
},
"linux": {
"MIMode": "gdb",
"MIDebuggerPath": "arm-none-eabi-gdb"
}
},
{
"name": "Shell Mbed Example Debug [local: nrf52840]",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/examples/shell/mbed/build-NRF52840_DK/${input:mbedProfile}/chip-mbed-shell-example",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceRoot}/examples/shell/mbed",
"environment": [],
"externalConsole": false,
"debugServerArgs": "",
"serverLaunchTimeout": 20000,
"filterStderr": true,
"filterStdout": false,
"serverStarted": "GDB\\ server\\ started",
"logging": {
"moduleLoad": true,
"trace": true,
"engineLogging": true,
"programOutput": true,
"exceptions": true
},
"setupCommands": [
{
"text": "-target-select remote localhost:3333",
"description": "connect to target",
"ignoreFailures": false
},
{
"text": "-file-exec-and-symbols ${workspaceRoot}/examples/shell/mbed/build-NRF52840_DK/${input:mbedProfile}/chip-mbed-shell-example",
"description": "load file",
"ignoreFailures": false
},
{
"text": "-interpreter-exec console \"monitor reset\"",
"ignoreFailures": false
},
{
"text": "-interpreter-exec console \"monitor halt\"",
"ignoreFailures": false
},
{
"text": "-interpreter-exec console \"monitor arm semihosting enable\"",
"ignoreFailures": false
},
{
"text": "-target-download",
"description": "flash target",
"ignoreFailures": false
}
],
"linux": {
"MIMode": "gdb",
"MIDebuggerPath": "arm-none-eabi-gdb",
"debugServerPath": "pyocd-gdbserver",
"debugServerArgs": "-t nrf52840"
}
},
{
"name": "Shell Mbed Example Debug [local: stm32l475xg]",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/examples/shell/mbed/build-DISCO_L475VG_IOT01A/${input:mbedProfile}/chip-mbed-shell-example",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceRoot}/examples/shell/mbed",
"environment": [],
"externalConsole": false,
"debugServerArgs": "",
"serverLaunchTimeout": 20000,
"filterStderr": true,
"filterStdout": false,
"serverStarted": "GDB\\ server\\ started",
"logging": {
"moduleLoad": true,
"trace": true,
"engineLogging": true,
"programOutput": true,
"exceptions": true
},
"setupCommands": [
{
"text": "-target-select remote localhost:3333",
"description": "connect to target",
"ignoreFailures": false
},
{
"text": "-file-exec-and-symbols ${workspaceRoot}/examples/shell/mbed/build-DISCO_L475VG_IOT01A/${input:mbedProfile}/chip-mbed-shell-example",
"description": "load file",
"ignoreFailures": false
},
{
"text": "-interpreter-exec console \"monitor reset\"",
"ignoreFailures": false
},
{
"text": "-interpreter-exec console \"monitor halt\"",
"ignoreFailures": false
},
{
"text": "-interpreter-exec console \"monitor arm semihosting enable\"",
"ignoreFailures": false
},
{
"text": "-target-download",
"description": "flash target",
"ignoreFailures": false
}
],
"linux": {
"MIMode": "gdb",
"MIDebuggerPath": "arm-none-eabi-gdb",
"debugServerPath": "pyocd-gdbserver",
"debugServerArgs": "-t stm32l475xg"
}
}
],
"inputs": [
{
"type": "pickString",
"id": "mbedTarget",
"description": "What mbed target will be used?",
"options": ["NRF52840_DK", "DISCO_L475VG_IOT01A"],
"default": "NRF52840_DK"
},
{
"type": "pickString",
"id": "mbedProfile",
"description": "What mbed profile do you want to use?",
"options": ["debug", "develop"],
"default": "develop"
}
]
}
36 changes: 34 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,14 @@
}
},
{
"label": "Build nRF mbed shell Example",
"label": "Build Mbed Shell Example",
"type": "shell",
"command": "scripts/examples/mbed_example.sh",
"args": ["-a=shell", "-b=NRF52840_DK", "-p=release"],
"args": [
"-a=shell",
"-b=${input:mbedTarget}",
"-p=${input:mbedProfile}"
],
"group": "build",
"problemMatcher": {
"base": "$gcc",
Expand All @@ -245,6 +249,34 @@
"${workspaceFolder}/examples/shell/mbed/build"
]
}
},
{
"label": "Flash Mbed Shell Example",
"type": "shell",
"command": "scripts/examples/mbed_example_utils.sh",
"args": [
"-a=shell",
"-b=${input:mbedTarget}",
"-p=${input:mbedProfile}"
],
"problemMatcher": [],
"group": "build"
}
],
"inputs": [
{
"type": "pickString",
"id": "mbedTarget",
"description": "What mbed target will be used?",
"options": ["NRF52840_DK", "DISCO_L475VG_IOT01A"],
"default": "NRF52840_DK"
},
{
"type": "pickString",
"id": "mbedProfile",
"description": "What mbed profile do you want to use?",
"options": ["release", "debug", "develop"],
"default": "develop"
}
]
}
81 changes: 81 additions & 0 deletions scripts/examples/mbed_example_utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env bash

#
# Copyright (c) 2020 Project CHIP Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

cd "$(dirname "$0")/../../examples"

SUPPORTED_TARGET_BOARD=(DISCO_L475VG_IOT01A NRF52840_DK)
SUPPORTED_APP=(shell)
SUPPORTED_PROFILES=(release develop debug)

APP=
TARGET_BOARD=
PYOCD_TARGET=
PROFILE=

for i in "$@"; do
case $i in
-a=* | --app=*)
APP="${i#*=}"
shift
;;
-b=* | --board=*)
TARGET_BOARD="${i#*=}"
shift
;;
-p=* | --profile=*)
PROFILE="${i#*=}"
shift
;;
*)
# unknown option
;;
esac
done

case $TARGET_BOARD in
NRF52840_DK)
PYOCD_TARGET=nrf52840
;;

DISCO_L475VG_IOT01A)
PYOCD_TARGET=stm32l475xg
;;

*)
# unknown option
;;
esac

if [[ ! " ${SUPPORTED_TARGET_BOARD[@]} " =~ " ${TARGET_BOARD} " ]]; then
echo "ERROR: Target $TARGET_BOARD not supported"
exit 1
fi

if [[ ! " ${SUPPORTED_APP[@]} " =~ " ${APP} " ]]; then
echo "ERROR: Application $APP not supported"
exit 1
fi

if [[ ! " ${SUPPORTED_PROFILES[@]} " =~ " ${PROFILE} " ]]; then
echo "ERROR: Profile $PROFILE not supported"
exit 1
fi

echo "############################"
pyocd flash -t $PYOCD_TARGET $PWD/$APP/mbed/build-$TARGET_BOARD/$PROFILE/chip-mbed-$APP-example.hex
echo "############################"

0 comments on commit 3928de0

Please sign in to comment.