如果用 PlatformIO 创建 libopencm3 项目可以做到零配置, 只是 libopencm3 的版本会旧一点. 这里说的是仅使用 VSCode 创建C/CPP项目时的配置. VSCode 有代码提示, 定位来源和各种快捷键, 更适合日常编码工作.
说明
因为 PlatformIO 的 platform:st-stm32 自带 libopencm3, 如果用 PlatformIO 创建 libopencm3 项目可以做到零配置, 只是 libopencm3 的版本会旧一点. 这里说的是仅使用 VSCode 创建C/CPP项目时的配置. VSCode 有代码提示, 定位来源和各种快捷键, 更适合日常编码工作.
前提条件
参考如何linux环境下配置环境变量过程图解 ,自行百度先将 GNU Arm Embedded Toolchain 和 st-flash 工具准备好
创建项目
导出模板项目
1
2
3
|
git clone --recurse-submodules https: //github.com/libopencm3/libopencm3-template.git 或者 git clone --recurse-submodules https: //gitee.com/iosetting/libopencm3-template.git |
VSCode 创建项目
用 VSCode 的 Open Folder 打开. 需要修改一下 my-project/Makefile 中的配置, 将 DEVICE 修改为实际使用的MCU型号
1
|
DEVICE=stm32f103c8t6 |
配置C/CPP环境
快捷键Ctrl
+Shift
+P
, 在打开的对话框中, 输入/找到 C/C++: Edit Configurations (JSON)
, 用JSON进行配置
配置内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
{ "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 } |
- compilerPath 根据自己的工具链路径进行修改
- defines 下的 STM32F1 与编译无关(编译使用的是DEVICE和链接库), 不设置也能正确编译, 设置这个是为了 VSCode 能正确定位变量和函数声明
配置编译任务
快捷键Ctrl
+Shift
+P
, 在打开的对话框中, 输入/找到 Tasks: Configure Task
, 用others模板创建
配置内容, 其中TARGETS=stm32/f1
根据实际的MCU型号修改
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
{ // See https://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 了.
到此这篇关于VSCode IDE 环境配置的文章就介绍到这了,更多相关VSCode IDE 环境配置内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!
原文链接:https://www.cnblogs.com/milton/p/15929905.html