当前位置:   article > 正文

2-VisualStudioCode嵌入式开发

vscode target-select remote

Visual Studio Code 嵌入式开发

大多数时候我们使用集成开发环境如: Keil,IAR等进行开发,但随着VSCode的流行,它的简介,丰富的插件,开源免费等优点,让越来越多的嵌入式开发者也转入它的怀抱。

Visual Studio Code 是由微软开发,同时支持 Windows 、 Linux 和 macOS 等操作系统且开放源代码的代码编辑器,支持测试,并内置了 Git 版本控制功能,同时也具有开发环境功能,例如代码补全、代码片段和代码重构等。[维基百科]

我们使用VSCode + GNU ARM 工具链可以替代其他嵌入式的IDE。代码编译用 GCC、调试代码用 GDB.

软件工具

  1. Visual Studio Code
  2. C/C++ 插件
  3. pyOCD
  4. GNU Arm Embedded Toolchain ---- gcc-arm-none-eabi-10-2020-q4-major-win32.exe / gcc-arm-none-eabi-10-2020-q4-major-win32.zip
  5. LLVM 或者LLVM-GitHub

参考文章

  1. Visual Studio Code 嵌入式开发环境
  2. 使用VScode 编写嵌入式C代码,实现代码提醒补充,函数跳转

软件安装

后续更新……

配置试功能

Visual Studio Code 使用 launch.json 文件来对调试功能进行配置,可以参考以下步骤:

  1. 打开项目工程目录
  2. 在项目根目录下找到 .vscode/launch.json 文件,没有的话则自己新建。在该文件中输入以下配置:
  1. {
  2. "version": "0.2.0",
  3. "configurations": [
  4. {
  5. "name": "C++ Launch",
  6. "type": "cppdbg",
  7. "request": "launch",
  8. "program": "${workspaceRoot}/armgcc/_build/nrf52840_xxaa.out",
  9. "args": [],
  10. "stopAtEntry": true,
  11. "cwd": "${workspaceRoot}",
  12. "environment": [],
  13. "externalConsole": false,
  14. "debugServerArgs": "",
  15. "serverLaunchTimeout": 20000,
  16. "filterStderr": true,
  17. "filterStdout": false,
  18. "serverStarted": "GDB\\ server\\ started",
  19. "preLaunchTask": "make",
  20. "setupCommands": [
  21. { "text": "-target-select remote localhost:3333", "description": "connect to target", "ignoreFailures": false },
  22. { "text": "-file-exec-and-symbols ${workspaceRoot}/armgcc/_build/nrf52840_xxaa.out", "description": "load file", "ignoreFailures": false},
  23. { "text": "-interpreter-exec console \"monitor endian little\"", "ignoreFailures": false },
  24. { "text": "-interpreter-exec console \"monitor reset\"", "ignoreFailures": false },
  25. { "text": "-interpreter-exec console \"monitor halt\"", "ignoreFailures": false },
  26. { "text": "-interpreter-exec console \"monitor arm semihosting enable\"", "ignoreFailures": false },
  27. { "text": "-target-download", "description": "flash target", "ignoreFailures": false }
  28. ],
  29. "logging": {
  30. "moduleLoad": true,
  31. "trace": true,
  32. "engineLogging": true,
  33. "programOutput": true,
  34. "exceptions": true
  35. },
  36. "linux": {
  37. "MIMode": "gdb",
  38. "MIDebuggerPath": "arm-none-eabi-gdb",
  39. "debugServerPath": "pyocd-gdbserver"
  40. },
  41. "osx": {
  42. "MIMode": "gdb",
  43. "MIDebuggerPath": "arm-none-eabi-gdb",
  44. "debugServerPath": "pyocd-gdbserver"
  45. },
  46. "windows": {
  47. "preLaunchTask": "make.exe",
  48. "MIMode": "gdb",
  49. "MIDebuggerPath": "arm-none-eabi-gdb.exe",
  50. "debugServerPath": "pyocd-gdbserver.exe",
  51. "setupCommands": [
  52. { "text": "-environment-cd ${workspaceRoot}\\armgcc\\_build" },
  53. { "text": "-target-select remote localhost:3333", "description": "connect to target", "ignoreFailures": false },
  54. { "text": "-file-exec-and-symbols nrf52840_xxaa.out", "description": "load file", "ignoreFailures": false},
  55. { "text": "-interpreter-exec console \"monitor endian little\"", "ignoreFailures": false },
  56. { "text": "-interpreter-exec console \"monitor reset\"", "ignoreFailures": false },
  57. { "text": "-interpreter-exec console \"monitor halt\"", "ignoreFailures": false },
  58. { "text": "-interpreter-exec console \"monitor arm semihosting enable\"", "ignoreFailures": false },
  59. { "text": "-target-download", "description": "flash target", "ignoreFailures": false }
  60. ]
  61. }
  62. }
  63. ]
  64. }
  1. 在.vscode/tasks.json(没有该文件则新建)中创建一个make任务,这样在进入调试功能时可以自动重新编译代码:
  1. {
  2. // See https://go.microsoft.com/fwlink/?LinkId=733558
  3. // for the documentation about the tasks.json format
  4. "version": "2.0.0",
  5. "tasks": [
  6. {
  7. "label": "make",
  8. "options": {
  9. "cwd": "${workspaceRoot}/armgcc"
  10. },
  11. "problemMatcher": {
  12. "owner": "cpp",
  13. "fileLocation": ["relative", "${workspaceRoot}"],
  14. "pattern": {
  15. "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
  16. "file": 1,
  17. "line": 2,
  18. "column": 3,
  19. "severity": 4,
  20. "message": 5
  21. }
  22. },
  23. "args": [],
  24. "linux": {
  25. "command": "make"
  26. },
  27. "osx": {
  28. "command": "make"
  29. },
  30. "windows": {
  31. "command": "make.exe"
  32. }
  33. }
  34. ]
  35. }
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/214368
推荐阅读
相关标签
  

闽ICP备14008679号