Skip to content

Commit

Permalink
Merge pull request #122 from ut-ras/remote-debug
Browse files Browse the repository at this point in the history
Add remote debugging capabilities
  • Loading branch information
calebchalmers authored May 23, 2024
2 parents 94ba858 + c0d1db8 commit 45e7eec
Show file tree
Hide file tree
Showing 17 changed files with 4,359 additions and 168 deletions.
11 changes: 9 additions & 2 deletions .devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@
"customizations": {
"vscode": {
"extensions": [
"ms-vscode.cpptools"
"ms-vscode.cpptools",
"marus25.cortex-debug"
]
}
},
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"configureZshAsDefaultShell": true
}
},
"postCreateCommand": "zsh -c '. ~/.oh-my-zsh/lib/cli.zsh && omz theme set frontcube'",
"runArgs": [
// Ensure our workspace gets mounted under the non-root user (podman)
"--userns=keep-id:uid=1000,gid=1000",
// Disable SELinux labeling (see https://docs.podman.io/en/latest/markdown/podman-run.1.html#volume-v-source-volume-host-dir-container-dir-options)
"--security-opt",
"label=disable"
]
}
}
29 changes: 23 additions & 6 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,30 @@
"type": "cortex-debug",
"request": "launch",
"servertype": "openocd",
"configFiles": [
"ut-robomaster/openocd.cfg"
],
"cwd": "${workspaceRoot}",
"preLaunchTask": "Flash - Debug",
"executable": "./ut-robomaster/build/hardware/scons-debug/ut-robomaster.elf",
"preLaunchTask": "Build - Debug",
"executable": "ut-robomaster/build/hardware/scons-debug/ut-robomaster.elf",
"device": "STM32F427II",
"configFiles": [
"./ut-robomaster/openocd.cfg"
]
}
"liveWatch": {
"enabled": true,
"samplesPerSecond": 10
},
"rttConfig": {
"enabled": true,
"address": "auto",
"decoders": [
{
"port": 0,
"type": "console"
}
]
},
"postResetCommands": [
"monitor rtt start"
],
},
]
}
10 changes: 8 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,16 @@
"SConscript": "python",
"stop_token": "cpp",
"cassert": "cpp",
"string.h": "c",
"bit": "cpp",
"compare": "cpp",
"concepts": "cpp",
"numbers": "cpp",
"ranges": "cpp",
"span": "cpp"
"span": "cpp",
"stdlib.h": "c",
"stdarg.h": "c",
"reent.h": "c"
},
"C_Cpp.errorSquiggles": "enabled",
"C_Cpp.default.includePath": [
Expand All @@ -98,5 +102,7 @@
"editor.rulers": [
100
]
}
},
"remote.autoForwardPorts": false,
"cortex-debug.variableUseNaturalFormat": true,
}
34 changes: 18 additions & 16 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,26 @@
{
"label": "Build - Release",
"type": "shell",
"command": "scons build robot=${input:robot} ",
"command": "scons build robot=${input:robot}",
"group": "build",
"options": {
"cwd": "${workspaceRoot}/ut-robomaster"
}
},
{
"label": "Flash - Debug",
"label": "Connect to Remote Debugger",
"type": "shell",
"command": "scons run robot=${input:robot} profile=debug profiling=true",
"group": "build",
"options": {
"cwd": "${workspaceRoot}/ut-robomaster"
"command": "ssh -L 7184:localhost:7184 ${input:debug_dest}",
"problemMatcher": [],
"isBackground": true,
"presentation": {
"echo": true,
"focus": true,
"panel": "dedicated",
"showReuseMessage": false,
"clear": false
}
},
{
"label": "Flash - Release",
"type": "shell",
"command": "scons run robot=${input:robot}",
"group": "build",
"options": {
"cwd": "${workspaceRoot}/ut-robomaster"
}
},
}
],
"inputs": [
{
Expand All @@ -55,5 +51,11 @@
],
"default": "standard"
},
{
"id": "debug_dest",
"description": "Remote destination (SSH):",
"type": "promptString",
"default": ""
},
]
}
32 changes: 14 additions & 18 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,12 @@ RUN apt-get update -qq \
&& rm -rf /var/lib/apt/lists/*

RUN ARCH=$(uname -m) \
URL=https://developer.arm.com/-/media/Files/downloads/gnu-rm/${ARM_GCC_VERSION}/gcc-arm-none-eabi-${ARM_GCC_VERSION}-${ARCH}-linux.tar.bz2 \
&& wget -qO- $URL | tar xj \
&& mv gcc-arm-none-eabi-${ARM_GCC_VERSION} gcc-arm
URL="https://developer.arm.com/-/media/Files/downloads/gnu-rm/${ARM_GCC_VERSION}/gcc-arm-none-eabi-${ARM_GCC_VERSION}-${ARCH}-linux.tar.bz2" \
&& mkdir gcc-arm \
&& wget -qO- "$URL" | tar xj --strip-components=1 -C gcc-arm

# Main stage
FROM ubuntu:22.04

ARG USERNAME=dev
ARG USER_UID=1000
ARG USER_GID=$USER_UID
FROM ubuntu:24.04

COPY --from=gcc-arm /gcc-arm /gcc-arm
ENV PATH="/gcc-arm/bin:$PATH"
Expand All @@ -30,21 +26,21 @@ RUN apt-get update -qq \
bash-completion \
doxygen \
git \
libncurses5 \
libncurses6 \
nano \
openocd \
openssh-client \
python3-pip \
scons \
python-is-python3 \
sudo \
&& rm -rf /var/lib/apt/lists/*

# Setup non-root user
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME -s /usr/bin/bash \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME
WORKDIR /home/$USERNAME
USER $USERNAME
# Create symlinks for old GCC compilers
RUN cd /usr/lib/x86_64-linux-gnu \
&& ln -s libncurses.so.6.4 libncurses.so.5 \
&& ln -s libtinfo.so.6.4 libtinfo.so.5

# Install tools (user-space)
RUN pip3 install lbuild pyelftools modm
USER ubuntu
# --break-system-packages is fine because we are not installing these through apt
RUN pip3 install lbuild pyelftools modm scons==3.1.2 --break-system-packages
8 changes: 6 additions & 2 deletions ut-robomaster/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ IGNORED_FILES_WHILE_TESTING = ["src/main.cpp"]

# Parse and validate arguments
args = parse_args.parse_args()
c_flags = [args["ROBOT_TYPE"]]

if args["DEMO_MODE"] == "true":
c_flags.append("DEMO_MODE")


def _get_hosted_target_name_for_current_platform():
Expand Down Expand Up @@ -59,7 +63,7 @@ sources = []
# Building all libraries (read from sconscript files located in provided dirs)
# Ensure that modm is first, since Taproot depends on modm
# Append include path to environment so both src/test environments have access to them
env.SConscript(dirs=[TAPROOT_PATH, SRC_PATH, TEST_PATH], exports=["env", "args", "sources"])
env.SConscript(dirs=[TAPROOT_PATH, SRC_PATH, TEST_PATH], exports=["env", "args", "c_flags", "sources"])


# Tests must be included as sources (rather than built as a separate library) in order for
Expand All @@ -70,7 +74,7 @@ if args["TARGET_ENV"] == "tests":


print("Configured {0} parallel build jobs (-j{0}), {1}"
.format(GetOption("num_jobs"), args["ROBOT_TYPE"]))
.format(GetOption("num_jobs"), c_flags))


if args["TARGET_ENV"] == "hardware":
Expand Down
13 changes: 9 additions & 4 deletions ut-robomaster/build_tools/parse_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
SIM_BUILD_TARGET_ACCEPTED_ARGS = ["build-sim", "run-sim"]
HARDWARE_BUILD_TARGET_ACCEPTED_ARGS = ["build", "run", "size", "gdb", "all"]
VALID_BUILD_PROFILES = ["debug", "release", "fast"]
VALID_PROFILING_TYPES = ["true", "false"]
VALID_BOOL_TYPES = ["true", "false"]
ROBOT_TYPE_DEFINES = {"standard": "TARGET_STANDARD",
"hero": "TARGET_HERO",
"sentry": "TARGET_SENTRY"}

USAGE = "Usage: scons <target> robot=<standard|hero|sentry> [profile=<debug|release|fast>] [profiling=<true|false>]\n\
USAGE = "Usage: scons <target> robot=<standard|hero|sentry> [profile=<debug|release|fast>] [profiling=<true|false>] [demo=<true|false>]\n\
\"<target>\" is one of:\n\
- \"build\": build all code for the hardware platform.\n\
- \"run\": build all code for the hardware platform, and deploy it to the board via a connected ST-Link.\n\
Expand All @@ -32,6 +32,7 @@ def parse_args():
"BUILD_PROFILE": "",
"PROFILING": "",
"ROBOT_TYPE": "",
"DEMO_MODE": "",
}
if len(COMMAND_LINE_TARGETS) > CMD_LINE_ARGS:
throw_error("You entered too many arguments.")
Expand Down Expand Up @@ -68,7 +69,11 @@ def parse_args():
throw_error("You specified an invalid build profile.")

args["PROFILING"] = ARGUMENTS.get("profiling", "false")
if args["PROFILING"] not in VALID_PROFILING_TYPES:
throw_error("You specified an invalid profiling type.")
if args["PROFILING"] not in VALID_BOOL_TYPES:
throw_error("You specified an invalid profiling setting.")

args["DEMO_MODE"] = ARGUMENTS.get("demo", "false")
if args["DEMO_MODE"] not in VALID_BOOL_TYPES:
throw_error("You specified an invalid demo setting.")

return args
3 changes: 3 additions & 0 deletions ut-robomaster/openocd.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
source [find interface/stlink.cfg]
hla_stlink_backend tcp 7184

transport select hla_swd

Expand All @@ -9,3 +10,5 @@ source [find target/stm32f4x.cfg]

reset_config none

# bindto 0.0.0.0
# gdb_port 3333
5 changes: 3 additions & 2 deletions ut-robomaster/src/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ from os.path import abspath

Import("env")
Import("args")
Import("c_flags")
Import("sources")


Expand All @@ -16,8 +17,8 @@ if args["TARGET_ENV"] == "tests":

env_cpy = env.Clone()

# Append on the global robot target build flag
env_cpy.AppendUnique(CCFLAGS=["-D " + args["ROBOT_TYPE"]])
# Append global build flags
env_cpy.AppendUnique(CCFLAGS=[f"-D {x}" for x in c_flags])

ignored_files.append("main_src_not_compiled.cpp")
rawSrcs = env_cpy.FindSourceFiles(".", ignorePaths=ignored_dirs, ignoreFiles=ignored_files)
Expand Down
17 changes: 17 additions & 0 deletions ut-robomaster/src/communication/rtt.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stdio.h>

#include "rtt/SEGGER_RTT.h"

int printf_rtt(const char* fmt, ...)
{
int r;
char data[64];
va_list params;

va_start(params, fmt);
r = vsnprintf(data, 64, fmt, params);
va_end(params);

SEGGER_RTT_Write(0, data, r);
return r;
}
36 changes: 36 additions & 0 deletions ut-robomaster/src/communication/rtt/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

SEGGER Microcontroller GmbH
The Embedded Experts

(c) 1995 - 2021 SEGGER Microcontroller GmbH
www.segger.com Support: [email protected]

SEGGER RTT Real Time Transfer for embedded targets


All rights reserved.

SEGGER strongly recommends to not make any changes
to or modify the source code of this software in order to stay
compatible with the RTT protocol and J-Link.

Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the following
condition is met:

- Redistributions of source code must retain the above copyright
notice, this condition and the following disclaimer.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
Loading

0 comments on commit 45e7eec

Please sign in to comment.