需要安装的软件
vscode
必装插件:
C/C++:用于提供高亮显示和代码补全
Cortex-Debug:用于提供调试配置
make
make工具可以直接下载xPack项目提供的windows-build-tools工具里面带了make工具。
Release xPack Windows Build Tools v4.2.1-2 · xpack-dev-tools/windows-build-tools-xpack (github.com)
openocd
arm-none-eabi
stm32CubeMX
上述软件具体的安装教程网上有很多详细的介绍资料,这里就不详细介绍了。需要注意的是记得将make,openocd,arm-none-eabi等可执行程序的路径添加到环境变量中
以下章节的内容都是根据stm32CubeMX生成的vscode_stm32f411 Makefile工程为例子来进行讲解的。
配置开发环境
实际上就是打造代码的编辑环境,实现类似于keil中编辑代码和代码补全等功能。在通过vscode打开vscode_stm32f411文件夹后,其实已经具备了编辑和代码补全功能(前提是必装的插件已经安装好),只是会有很多报错的波浪线,这时候便需配置c_cpp_properties.json文件来解决源文件的各种报错提示:
如果提示**uint32_t是未定义的类型**在defines下添加__GNUC__
c_cpp_properties.json文件:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE",
"USE_HAL_DRIVER", //
"STM32F411xE", //
"__GNUC__" //
],
// "compilerPath": "C:\Program Files\LLVM\bin\clang.exe",
"compilerPath": "C:/Program Files (x86)/GNU Tools Arm Embedded/7 2018-q2-update/bin/arm-none-eabi-gcc.exe",
"cStandard": "c17",
"cppStandard": "c++14",
// "intelliSenseMode": "windows-clang-x64"
"intelliSenseMode": "gcc-arm"
}
],
"version": 4
}
配置编译下载功能
新建task.json文件
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "make",
"args": [
"-j4"
],
"group": { //group用于将当前任务设置为默认的build任务,可以直接通过Ctrl+Shift+B直接执行
"kind": "build",
"isDefault": true
},
"problemMatcher":[
"$gcc"
]
},
{
"label": "clean",
"type": "shell",
"command": "make",
"args": [
"clean"
]
},
{
"label": "flash - ST-Link", //用于执行makefile文件中实现的下载指令
"type": "shell",
"command": "make flash",
"problemMatcher": []
},
{
"label": "download", //下载并运行
"type": "shell",
"command": "openocd",
"args": [
"-f",
"interface/stlink-v2.cfg",
"-f",
"target/stm32f4x.cfg",
"-c",
"program build/vscode_stm32f411.elf verify reset exit" //TODO:这里的下载文件的路径不能够用${workspaceFolder}来指定
],
"dependsOn":"build", //download任务的依赖任务,即download任务执行前会先执行build任务
},
{
"label": "reset", //复位程序
"type": "shell",
"command":"openocd",
"args": [
"-f",
"interface/stlink-v2.cfg",
"-f",
"target/stm32f4x.cfg",
"-c init",
"-c reset",
"-c exit",
],
"problemMatcher": []
},
{
"label": "halt", //挂起程序
"type": "shell",
"command":"openocd",
"args": [
"-f",
"interface/stlink-v2.cfg",
"-f",
"target/stm32f4x.cfg",
"-c init",
"-c halt",
"-c exit",
],
"problemMatcher": []
},
{
"label": "run", //运行程序
"type": "shell",
"command":"openocd",
"args": [
"-f",
"interface/stlink-v2.cfg",
"-f",
"target/stm32f4x.cfg",
"-c init",
"-c resume",
"-c exit",
],
"problemMatcher": []
},
]
}
build任务用于编译工程(实质上是执行makefile文件 make)
clean任务用于清除编译生成的中间文件(实质是执行makefile文件中的 make clean)
flash - ST-Link任务用于下载代码到STM32芯片中,这里需要在makefile中添加flash伪目标,伪目标flash实现如下:
#flash the stm32
OPENOCD := openocd -f interface/stlink-v2.cfg -f target/stm32f4x_stlink.cfg
FIRMWARE = $(BUILD_DIR)/vscode_stm32f411.elf
flash:
$(OPENOCD) -c init
-c 'reset halt'
-c 'flash write_image erase $(FIRMWARE)'
-c 'reset run'
-c exit
download任务用于下载代码到STM32芯片中,这里是完全在tasks.json文件中实现的(通过openocd实现下载目标文件)
reset任务用于复位目标板程序
halt任务用于挂起目标板程序
run任务用于运行挂起的目标程序
配置调试功能
添加launch.json文件配置调试环境
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Cortex Debug",
"cwd": "${workspaceRoot}",
"executable": "${workspaceRoot}/build/vscode_stm32f411.elf",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
"device": "STM32F411xx",
"interface": "swd",
"configFiles": [
"${workspaceRoot}/openocd.cfg"
],
"runToMain": true,
"showDevDebugTimestamps": true,
上一篇:STM32_USB_CDC学习笔记
下一篇:Arduino_Core_STM32---pinMode()实现分析
推荐阅读最新更新时间:2024-11-01 18:52
设计资源 培训 开发板 精华推荐
- 直播已结束【大唐恩智浦具有阻抗检测功能的新能源锂电芯电池管理方案】
- 有奖问答 | 富士通铁电随机存储器 FRAM 知多少
- Follow me第2期来袭,与得捷一起解锁开源硬件 Adafruit ESP32-S3 TFT Feather!
- 免费申请TI 样片,晒单赢好礼!
- nanoPower技术:延长电池寿命,提升传感器性能 2021年1月20日 上午10:00在线研讨会
- TE 智能电表特训营,产品、技术、市场全解锁!
- Fluke高分辨率热像仪~小细节也不放过!免费体验报名中
- 早睡早起,为自己的健康打个卡
- 如何读懂牛掰的USB Tybe-C新闻稿!
- 有奖直播|瑞萨电子 Arm MCU 的新能源进击:RA6T2