所需软件
编号 | 作用 | 软件 |
---|---|---|
1 | make工具 | make minigw-make |
2 | 编译工具 | arm-none-eabi-gcc |
3 | 调试工具 | OpenOCD |
4 | STM32 配置工具 | STM32CUBEMX |
5 | 编辑工具 | vscode |
6 | 版本控制 | git |
7 | 调试工具 | Cortex-Debug |
安装软件
-
git 工具
优先安装git管理工具。可以用于验证后面环境变量的配置是否成功。 -
make 工具
make可用于执行make命令
minigwminigw内的make工具为minigw-make所以建议重命名为make。
两个工具二选一,都是执行make命令的工具,需要添加环境变量。验证环境变量
【右键】–>【git bash】make -v //会显示工具版本信息
-
编译工具
arm 编译工具
双击安装后,添加环境变量
验证环境变量
【右键】–>【git bash】arm-none-eabi-gcc -v //会显示工具版本信息
-
调试工具
openocd是压缩包,解压到安装位置后添加环境变量
验证环境变量
【右键】–>【git bash】openocd -v //会显示工具版本信息
测试编译工具链
-
使用stm32cubemx创建一个测试项目,项目类型为makefile类型
注意,需要是能mcu的调试功能,否则无法二次链接mcu -
打开测试项目文件夹
-
【右键】–>【git bash】
make ---------------------------------------------------------------- arm-none-eabi-size build/STM32F103_TEST.elf text data bss dec hex filename 3776 20 1636 5432 1538 build/STM32F103_TEST.el arm-none-eabi-objcopy -O ihex build/STM32F103_TEST.elf build/ST arm-none-eabi-objcopy -O binary -S build/STM32F103_TEST.elf bui
配置vscode 进行编译
通过vscode 打开测试项目文件夹
编号 | 文件名 | 说明 | 作用 |
---|---|---|---|
2 | c_cpp_properties.json | c语言项目配置文件 | 包含头文件路径 和编译器信息等 |
3 | launch.json | 调试配置文件 | |
4 | task.json | 任务配置文件 | 可用于创建相关任务 |
-
编辑c语言项目配置文件
创建 c_cpp_properties.json
【F1】–>【输入 “C++”】 -->【C/C++编辑配置(JSON)】{ "configurations": [ { "name": "Win32", "includePath": [ "${workspaceFolder}/**", "${workspaceFolder}/stm32_cubemx/Drivers/STM32F7xx_HAL_Driver/Inc", "${workspaceFolder}/stm32_cubemx/Drivers/CMSIS/Device/ST/STM32F7xx/Include", "${workspaceFolder}/stm32_cubemx/Drivers/CMSIS/Include", "D:/Program Files (x86)/GNU Tools ARM Embedded/5.4 2016q3/arm-none-eabi/include", "D:/Program Files (x86)/GNU Tools ARM Embedded/5.4 2016q3/arm-none-eabi/include/c++/5.4.1", //"D:/Program Files (x86)/GNU Tools ARM Embedded/5.4 2016q3/arm-none-eabi/include/c++/5.4.1/arm-none-eabi/thumb/v7-m", "D:/Program Files (x86)/GNU Tools ARM Embedded/5.4 2016q3/arm-none-eabi/include/c++/5.4.1/backward", "D:/Program Files (x86)/GNU Tools ARM Embedded/5.4 2016q3/arm-none-eabi/include/sys", "D:/Program Files (x86)/GNU Tools ARM Embedded/5.4 2016q3/lib/gcc/arm-none-eabi/5.4.1/include", "D:/Program Files (x86)/GNU Tools ARM Embedded/5.4 2016q3/lib/gcc/arm-none-eabi/5.4.1/include-fixed" ], "defines": [ "_DEBUG", "UNICODE", "_UNICODE" ], "compilerPath": "D:/Program Files (x86)/GNU Tools ARM Embedded/5.4 2016q3/bin/arm-none-eabi-gcc.exe", "cStandard": "gnu11", "cppStandard": "gnu++14", "intelliSenseMode": "windows-gcc-x86" } ], "version": 4
}
-
任务配置文件
创建 tasks.json
【F1】–>【输入 “tasks”】 -->【任务:配置默认生成任务】{ // 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": [], "group": "build", }, { "label": "clean", "type": "shell", "command": "make", "args": [ "clean" ], "group": "build", } ] }
-
编译项目
[CTRL + SHIF +B]
Cortex Debug
-
创建 launch.json
点击【调试按钮】–>【创建 launch.json 文件】–>【 Cortex Debug】{ "version": "0.2.0", "configurations": [ { "cwd": "${workspaceRoot}", "executable": "./build/${workspaceRootFolderName}.elf", "name": "Debug stlink", "request": "launch", "type": "cortex-debug", "servertype": "openocd", "runToMain": true, "configFiles": [ "interface/stlink.cfg", "target/stm32f1x.cfg", ] }, { "cwd": "${workspaceRoot}", "executable": "./build/${workspaceRootFolderName}.elf", "name": "Debug Jink", "request": "launch", "type": "cortex-debug", "servertype": "jlink", "interface": "swd", "runToMain": true, "device": "STM32F103C8", "configFiles": [ "interface/jlink.cfg", "target/stm32f1x.cfg", ] } ] }
由于 jlinkv8不支持stm32f7故只保留stlink配置
注意供电不足会造成能够连接mcu,但是无法正常仿真的情况
{
"version": "0.2.0",
"configurations": [
{
"cwd": "${workspaceRoot}",
"executable": "./build/${workspaceRootFolderName}.elf",
"name": "Debug stlink",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
"runToEntryPoint": "main",
"runToMain": true,
"configFiles": [
"interface/stlink.cfg",
"target/stm32f7x.cfg",
]
},
]
}