时间:2022-10-30 11:08:59 | 栏目:C代码 | 点击:次
如果用 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 工具准备好
git clone --recurse-submodules https://github.com/libopencm3/libopencm3-template.git 或者 git clone --recurse-submodules https://gitee.com/iosetting/libopencm3-template.git
用 VSCode 的 Open Folder 打开. 需要修改一下 my-project/Makefile 中的配置, 将 DEVICE 修改为实际使用的MCU型号
DEVICE=stm32f103c8t6
快捷键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 }
快捷键Ctrl
+Shift
+P
, 在打开的对话框中, 输入/找到 Tasks: Configure Task
, 用others模板创建
配置内容, 其中TARGETS=stm32/f1
根据实际的MCU型号修改
{ // 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 了.