写这篇文章的目的主要是为了记录下在Ubuntu 18.04环境下利用vscode 软件编译并且debug px4代码的过程
看这篇文章前提你已经有了一个Ubuntu 18.04系统 并且在系统中安装了VScode软件
整个文章主要分以下几个部分
在linux上配置PX4 的整个编译环境其实是一个老生常谈的事情,官方给出了很多种解决方案,主要的难点就是配置好基本的依赖包,坑点就是依赖的版本问题,我编译的PX4固件版本是最新的版本。值得注意的有几点
sudo apt-get update -y --quiet
sudo DEBIAN_FRONTEND=noninteractive apt-get -y --quiet --no-install-recommends install \
astyle \
build-essential \
cmake \
cppcheck \
file \
g++ \
gcc \
gdb \
git \
lcov \
libxml2-dev \
libxml2-utils \
make \
ninja-build \
python3 \
python3-dev \
python3-pip \
python3-setuptools \
python3-wheel \
rsync \
shellcheck \
unzip \
zip \
;
-安装python3 默认系统自带,主要是安装python依赖库文件
python3 -m pip install --user -r argcomplete
argparse>=1.2
cerberus
coverage
empy>=3.3
future
jinja2>=2.8
jsonschema
kconfiglib
lxml
matplotlib>=3.0.*
numpy>=1.13
nunavut>=1.1.0
packaging
pandas>=0.21
pkgconfig
psutil
pygments
wheel>=0.31.1
pymavlink
pyros-genmsg
pyserial
pyulog>=0.5.0
pyyaml
requests
setuptools>=39.2.0
six>=1.12.0
toml>=0.9
sudo apt-get install python-serial openocd \
flex bison libncurses5-dev autoconf texinfo \
libftdi-dev libtool zlib1g-dev -y
# Clean up old GCC
sudo apt-get remove gcc-arm-none-eabi gdb-arm-none-eabi binutils-arm-none-eabi gcc-arm-embedded -y
sudo add-apt-repository --remove ppa:team-gcc-arm-embedded/ppa -y
# GNU Arm Embedded Toolchain: 7-2017-q4-major December 18, 2017
gcc_dir=$HOME/gcc-arm-none-eabi-7-2017-q4-major
echo "Installing GCC to: $gcc_dir"
if [ -d "$gcc_dir" ]
then
echo " GCC already installed."
else
pushd .
cd ~
wget https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/7-2017q4/gcc-arm-none-eabi-7-2017-q4-major-linux.tar.bz2
tar -jxf gcc-arm-none-eabi-7-2017-q4-major-linux.tar.bz2
exportline="export PATH=$HOME/gcc-arm-none-eabi-7-2017-q4-major/bin:\$PATH"
if grep -Fxq "$exportline" ~/.profile; then echo " GCC path already set." ; else echo $exportline >> ~/.profile; fi
. ~/.profile
popd
fi
cd PX4-Autopilot
# 开始编译 输入make之后Tab可以查到具体固件的编译命令
# make *******
# 我使用的是雷迅的x7pro硬件
make cuav_x7pro
sudo apt-get install git make cmake libusb-1.0-0-dev
sudo apt-get install gcc build-essential
git clone https://github.com/stlink-org/stlink
cd stlink
cmake .
make
在配置cmake的时候建议看一下配置输出cd bin
sudo cp st-* /usr/local/bin
cd ../lib
sudo cp *.so* /lib32
sudo cp stlink/config/udev/rules.d/49-stlinkv* /etc/udev/rules.d/
{
"version": "0.2.0",
"configurations": [
{
"name": "jlink (cuav_x7pro)",
"device": "STM32H743XI",
"svdFile": "",
"executable": "${command:cmake.launchTargetPath}",
"request": "launch",
"type": "cortex-debug",
"servertype": "jlink",
"interface": "swd",
//"ipAddress": "server:19020",
"cwd": "${workspaceFolder}",
"internalConsoleOptions": "openOnSessionStart",
"preLaunchCommands": [
"source ${workspaceFolder}/platforms/nuttx/Debug/PX4",
"source ${workspaceFolder}/platforms/nuttx/Debug/NuttX",
"source ${workspaceFolder}/platforms/nuttx/Debug/ARMv7M",
"set mem inaccessible-by-default off",
"set print pretty",
]
},
{
"name": "stlink (cuav_x7pro)",
"device": "STM32H743XI",
"svdFile": "",
"executable": "${command:cmake.launchTargetPath}",
"request": "launch",
"type": "cortex-debug",
"servertype": "stutil",
"cwd": "${workspaceFolder}",
"internalConsoleOptions": "openOnSessionStart",
"preLaunchCommands": [
"source ${workspaceFolder}/platforms/nuttx/Debug/PX4",
"source ${workspaceFolder}/platforms/nuttx/Debug/NuttX",
"source ${workspaceFolder}/platforms/nuttx/Debug/ARMv7M",
"set mem inaccessible-by-default off",
"set print pretty",
]
},
{
"name": "blackmagic (cuav_x7pro)",
"device": "STM32H743XI",
"svdFile": "",
"executable": "${command:cmake.launchTargetPath}",
"request": "launch",
"type": "cortex-debug",
"servertype": "bmp",
"BMPGDBSerialPort": "/dev/ttyACM0",
"interface": "swd",
"cwd": "${workspaceFolder}",
"internalConsoleOptions": "openOnSessionStart",
"preLaunchCommands": [
"source ${workspaceFolder}/platforms/nuttx/Debug/PX4",
"source ${workspaceFolder}/platforms/nuttx/Debug/NuttX",
"source ${workspaceFolder}/platforms/nuttx/Debug/ARMv7M",
"set mem inaccessible-by-default off",
"set print pretty",
]
}
]
}