[Zephyr] 1.1 VSCode 环境补充

为了方便阅读Zephyr源码以及编译调试,我们可以在VsCode中安装这些插件:

  1. clangd (阅读代码跳转)
  2. CMake、CMake Tools
  3. Cortex-Debug
  4. DeviceTree
  5. Git Graph
  6. Serial Monitor (串口调试)

代码跳转

clangd需要利用compile_commands.json才能实现跳转功能,因此我们需要对west进行配置:

 west config build.cmake-args -- -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

配置完后重新编译一次,就会在build目录下生成compile_commands.json了,代码跳转也可以正常使用了

Debug

利用Cortex-Debug插件可以实现Debug功能,类似在Keil中Debug那样。

在项目根目录创建.vscode/launch.json,内容如下:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Cortex Debug",
            "cwd": "${workspaceFolder}",
            "executable": "./zephyr/build/zephyr/zephyr.elf",
            "request": "launch",
            "type": "cortex-debug",
            "runToEntryPoint": "main",
            "servertype": "openocd",
            "device": "STM32F407VET6",
            "configFiles": [
                "interface/cmsis-dap.cfg",
                "target/stm32f4x.cfg",
            ],
            "svdFile": "./zephyr/boards/arm/lcpcb_stm32f407vet6/STM32F407.svd",
            "liveWatch": {
                "enabled": true,
                "samplesPerSecond": 4
            }
        }
    ]
}

接着去ST官网下载你主控的svd文件,比如我的是STM32F407VET6

stm32F4 SVD - 资源 - Search STMicrocontrollers

把主控对应的svd文件放到前面创建的文件夹里:

 然后就可以直接调用VSCode的debug进行debug了,debug体验操作下来还是挺不错的

### 配置NS-3网络模拟器在Visual Studio Code (VSCode)中的开发环境 #### 安装必要的依赖项 为了使NS-3能够在VSCode中顺利工作,需先确保所有必需的库和工具已经安装。这通常包括构建工具链、Python支持和其他特定于操作系统的依赖关系。 对于Ubuntu系统而言,在终端执行如下命令来获取这些依赖: ```bash sudo apt-essential autoconf automake libxmu-dev g++ python3 python3-setuptools git qtbase5-dev-tools qtchooser qt5-qmake qtbase5-dev libqt5svg5-dev zlib1g-dev gdb valgrind uncrustify doxygen graphviz bison flex texinfo dia gsl-bin libgsl-dev libgslcblas0 wireshark tcpdump sqlite sqlite3 libsqlite3-dev libxml2 libxml2-dev libc6-dev libc6-dev-i386 libclang-dev llvm-dev clang cmake libc-ares-dev libboost-all-dev libevent-dev pkg-config libnl-3-dev libnl-genl-3-dev libpcap-dev libprotobuf-dev protobuf-c-compiler libprotoc-dev python3-pygraphviz python3-gnuplot swig pybind11-dev python3-numpy python3-scipy python3-matplotlib python3-pandas python3-jinja2 sphinxcontrib-runcode sphinxcontrib-bibtex sphinx-autobuild docutils-common rst2pdf rst2html.py ipython3 jupyter-core jupyter-client notebook nbconvert nbformat terminado tornado jsonschema prometheus-client pylint mypy isort black flake8 pytest coverage codecov tox virtualenv pipenv poetry pre-commit editorconfig check-manifest setuptools wheel twine cookiecutter bumpversion readthedocs-sphinx-theme nbsphinx sphinx-tabs myst-parser breathe exhale sphinx-copybutton sphinx-toggleprompt sphinx-notfound-page sphinx-book-theme furo pydata-sphinx-theme sphinx-material alabaster classic-sphinx-theme basic-sphinx-theme nature-sphinx-theme haiku-sphinx-theme pyramid-sphinx-theme sphinx-bootstrap-theme cloud-sphinx-theme krTheme business-sphinx-theme flat-sphinx-theme guzzle-sphinx-theme sage-sphinx-theme stanford-sphinx-theme tinkerbell-sphinx-theme wurtzite-sphinx-theme zephyr-sphinx-theme ``` 上述命令涵盖了从基本编译需求至文档生成等一系列广泛用途所需的软件包[^1]。 #### 下载并设置NS-3源码 前往官方GitHub仓库下载最新版本的NS-3源代码,并按照说明解压到本地目录下。接着初始化子模块以便能够访问额外资源: ```bash git clone https://github.com/nsnam/ns-3-dev.git ns-3 cd ns-3 ./bootstrap.sh ``` 此过程将准备好项目结构供后续配置使用。 #### 构建NS-3 利用`waf`脚本来完成项目的初次构建,这样做的好处是可以验证当前环境下是否存在任何潜在问题: ```bash ./waf configure --enable-examples --enable-tests ./waf build ``` 通过指定选项启用例子程序和支持测试套件有助于全面了解框架的功能特性。 #### 设置VSCode集成 打开VSCode并将工作区指向之前克隆下来的NS-3根目录;随后安装扩展插件如C/C++ IntelliSense、Code Runner等增强体验。创建`.vscode/settings.json`文件自定义编辑器行为,比如路径映射或调试参数设定: ```json { "terminal.integrated.shell.linux": "/bin/bash", "files.associations": { "*.cc": "cpp" }, "editor.tabSize": 4, "[cpp]": { "editor.defaultFormatter": "ms-vscode.cpptools" } } ``` 另外还需建立launch configuration以简化启动流程,具体做法是在同一文件夹内新建名为`launch.json`的内容如下所示: ```json { "version": "0.2.0", "configurations": [ { "name": "(GDB) Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/build/scratch/subdir/my-program", "args": [], "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], "externalConsole": true, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "compile", "miDebuggerPath": "/usr/bin/gdb" } ] } ``` 这里假设目标可执行文件位于相对路径`build/scratch/subdir/my-program`处,请根据实际情况调整相应字段取值。 最后一步是关联预处理器宏定义与包含路径信息给IntelliSense解析引擎用作索引依据,为此目的而设的任务描述符保存成tasks.json形式: ```json { "version": "2.0.0", "tasks": [ { "label": "compile", "command": "./waf", "args": ["--run", "my-program"], "group": { "kind": "build", "isDefault": true }, "problemMatcher": [] } ] } ``` 至此已完成全部准备工作,现在可以在VSCode里享受流畅高效的编码乐趣了!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

零零零耶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值