如何配置VSCode IDE以支持LibOpenCM3(四)开发?

2026-05-27 17:221阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计801个文字,预计阅读时间需要4分钟。

如何配置VSCode IDE以支持LibOpenCM3(四)开发?

如果使用 PlatformIO 创建 libopencm3 项目,可以实现零配置。只需注意,libopencm3 的版本可能会有些过时。以下是在 VSCode 中创建 C/PP 项目时的配置说明:

VSCode 提供代码提示、定位源代码和多种快捷键,非常适合日常使用。

如果用 PlatformIO 创建 libopencm3 项目可以做到零配置, 只是 libopencm3 的版本会旧一点. 这里说的是仅使用 VSCode 创建C/CPP项目时的配置. VSCode 有代码提示, 定位来源和各种快捷键, 更适合日常编码工作. 目录
  • LibOpenCM3(一) Linux下命令行开发环境配置
  • LibOpenCM3(二) 项目模板 Makefile分析
  • LibOpenCM3(三) .ld文件(连接器脚本)和startup代码说明
  • LibOpenCM3(四) VSCode IDE 环境配置
说明

因为 PlatformIO 的 platform:st-stm32 自带 libopencm3, 如果用 PlatformIO 创建 libopencm3 项目可以做到零配置, 只是 libopencm3 的版本会旧一点. 这里说的是仅使用 VSCode 创建C/CPP项目时的配置. VSCode 有代码提示, 定位来源和各种快捷键, 更适合日常编码工作.

前提条件

参考 Linux下命令行开发环境配置, 先将 GNU Arm Embedded Toolchain 和 st-flash 工具准备好

创建项目 导出模板项目

git clone --recurse-submodules github.com/libopencm3/libopencm3-template.git 或者 git clone --recurse-submodules gitee.com/iosetting/libopencm3-template.git VSCode 创建项目

用 VSCode 的 Open Folder 打开. 需要修改一下 my-project/Makefile 中的配置, 将 DEVICE 修改为实际使用的MCU型号

如何配置VSCode IDE以支持LibOpenCM3(四)开发?

DEVICE=stm32f103c8t6 配置C/CPP环境

快捷键Ctrl+Shift+P, 在打开的对话框中, 输入/找到 C/C++: Edit Configurations (JSON), 用JSON进行配置

配置内容

{ "configurations": [ { "name": "Linux", "includePath": [ "${workspaceFolder}/**", "${workspaceFolder}/libopencm3/include" ], "defines": [ "STM32F1" ], "compilerPath": "/opt/gcc-arm/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-gcc", "cStandard": "gnu11", "cppStandard": "gnu++14", "intelliSenseMode": "gcc-arm" } ], "version": 4 }

  1. compilerPath 根据自己的工具链路径进行修改
  2. defines 下的 STM32F1 与编译无关(编译使用的是DEVICE和链接库), 不设置也能正确编译, 设置这个是为了 VSCode 能正确定位变量和函数声明
配置编译任务

快捷键Ctrl+Shift+P, 在打开的对话框中, 输入/找到 Tasks: Configure Task, 用others模板创建

配置内容, 其中TARGETS=stm32/f1根据实际的MCU型号修改

{ // See go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "build libopencm3", "type": "shell", "command": "PREFIX=/opt/gcc-arm/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi- TARGETS=stm32/f1 make -C libopencm3", "problemMatcher": [] }, { "label": "build clean libopencm3", "type": "shell", "command": "PREFIX=/opt/gcc-arm/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi- make -C libopencm3 clean", "problemMatcher": [] }, { "label": "build", "type": "shell", "command": "PREFIX=/opt/gcc-arm/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi- make -C my-project", "problemMatcher": [] }, { "label": "build clean", "type": "shell", "command": "PREFIX=/opt/gcc-arm/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi- make -C my-project clean", "problemMatcher": [] }, { "label": "build download", "type": "shell", "command": "st-flash --reset write my-project/awesomesauce.bin 0x8000000", "problemMatcher": [] } ] }

使用时, 通过Shift + Alt + F10调出菜单并选中执行.

先执行一次 build libopencm3 , 生成 libopencm3 的链接库之后, 编译项目就只需要执行 build 了.

本文共计801个文字,预计阅读时间需要4分钟。

如何配置VSCode IDE以支持LibOpenCM3(四)开发?

如果使用 PlatformIO 创建 libopencm3 项目,可以实现零配置。只需注意,libopencm3 的版本可能会有些过时。以下是在 VSCode 中创建 C/PP 项目时的配置说明:

VSCode 提供代码提示、定位源代码和多种快捷键,非常适合日常使用。

如果用 PlatformIO 创建 libopencm3 项目可以做到零配置, 只是 libopencm3 的版本会旧一点. 这里说的是仅使用 VSCode 创建C/CPP项目时的配置. VSCode 有代码提示, 定位来源和各种快捷键, 更适合日常编码工作. 目录
  • LibOpenCM3(一) Linux下命令行开发环境配置
  • LibOpenCM3(二) 项目模板 Makefile分析
  • LibOpenCM3(三) .ld文件(连接器脚本)和startup代码说明
  • LibOpenCM3(四) VSCode IDE 环境配置
说明

因为 PlatformIO 的 platform:st-stm32 自带 libopencm3, 如果用 PlatformIO 创建 libopencm3 项目可以做到零配置, 只是 libopencm3 的版本会旧一点. 这里说的是仅使用 VSCode 创建C/CPP项目时的配置. VSCode 有代码提示, 定位来源和各种快捷键, 更适合日常编码工作.

前提条件

参考 Linux下命令行开发环境配置, 先将 GNU Arm Embedded Toolchain 和 st-flash 工具准备好

创建项目 导出模板项目

git clone --recurse-submodules github.com/libopencm3/libopencm3-template.git 或者 git clone --recurse-submodules gitee.com/iosetting/libopencm3-template.git VSCode 创建项目

用 VSCode 的 Open Folder 打开. 需要修改一下 my-project/Makefile 中的配置, 将 DEVICE 修改为实际使用的MCU型号

如何配置VSCode IDE以支持LibOpenCM3(四)开发?

DEVICE=stm32f103c8t6 配置C/CPP环境

快捷键Ctrl+Shift+P, 在打开的对话框中, 输入/找到 C/C++: Edit Configurations (JSON), 用JSON进行配置

配置内容

{ "configurations": [ { "name": "Linux", "includePath": [ "${workspaceFolder}/**", "${workspaceFolder}/libopencm3/include" ], "defines": [ "STM32F1" ], "compilerPath": "/opt/gcc-arm/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-gcc", "cStandard": "gnu11", "cppStandard": "gnu++14", "intelliSenseMode": "gcc-arm" } ], "version": 4 }

  1. compilerPath 根据自己的工具链路径进行修改
  2. defines 下的 STM32F1 与编译无关(编译使用的是DEVICE和链接库), 不设置也能正确编译, 设置这个是为了 VSCode 能正确定位变量和函数声明
配置编译任务

快捷键Ctrl+Shift+P, 在打开的对话框中, 输入/找到 Tasks: Configure Task, 用others模板创建

配置内容, 其中TARGETS=stm32/f1根据实际的MCU型号修改

{ // See go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "build libopencm3", "type": "shell", "command": "PREFIX=/opt/gcc-arm/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi- TARGETS=stm32/f1 make -C libopencm3", "problemMatcher": [] }, { "label": "build clean libopencm3", "type": "shell", "command": "PREFIX=/opt/gcc-arm/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi- make -C libopencm3 clean", "problemMatcher": [] }, { "label": "build", "type": "shell", "command": "PREFIX=/opt/gcc-arm/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi- make -C my-project", "problemMatcher": [] }, { "label": "build clean", "type": "shell", "command": "PREFIX=/opt/gcc-arm/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi- make -C my-project clean", "problemMatcher": [] }, { "label": "build download", "type": "shell", "command": "st-flash --reset write my-project/awesomesauce.bin 0x8000000", "problemMatcher": [] } ] }

使用时, 通过Shift + Alt + F10调出菜单并选中执行.

先执行一次 build libopencm3 , 生成 libopencm3 的链接库之后, 编译项目就只需要执行 build 了.