不要忘记将工具链加入系统环境变量


Project Manager -> Project,
设置 Project Name 和 Project Location,
将 Application Structure 修改为 Basic,
将 Toolchain/IDE 修改为 Makefile,
勾选 Use latest available version

Project Manager -> Code Generator,
STM32Cube MCU packages and embedded software packs 选择 Copy only the necessary library files,
Generated files 勾选 Generate peripheral initialization as a pair of '.c/.h' files per peripheral

Project Manager -> Advanced Settings,将 HAL 改为 LL

- 点击
GENETATE CODE -> Open Folder



- 安装插件
Chinese (Simplified) Language,C/C++,C++ Intellisense 和 Cortex-Debug

- 按
F1 键或者 ctrl+shift+P,输入 编辑配置JSON,然后选择下图选项

用以下内容替换原内容
{
"configurations": [
{
"name": "ARM",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"USE_FULL_LL_DRIVER",
"USE_HAL_DRIVER",
"STM32MCU"
],
"cStandard": "gnu11",
"cppStandard": "gnu++11",
"compilerPath": "arm-none-eabi-gcc",
"intelliSenseMode": "gcc-arm"
}
],
"version": 4
}
| 字符 |
解释 |
includePath |
头文件路径 |
defines |
宏定义 |
cStandard |
C标准 |
cppStandard |
C++标准 |
compilerPath |
编译器路径 |
intelliSenseMode |
智能感知模式 |
source [find interface/stlink-v2.cfg]
source [find target/stm32f1x.cfg]
| 字符 |
解释 |
interface |
调试器 |
target |
目标板 |
运行 -> 添加配置 -> Cortex Debug 或者按下图操作

{
"version": "0.2.0",
"configurations": [
{
"cwd": "${workspaceRoot}",
"executable": "build/ELFNAME.elf",
"name": "Debug",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
"configFiles": ["openocd.cfg"],
"preLaunchTask": "Build",
"postDebugTask": "Reset"
}
]
}
| 字符 |
解释 |
executable |
工程的 .elf 文件路径 |
servertype |
调试应用 |
configFiles |
配置文件路径 |
preLaunchTask |
调试开始前运行的任务 |
postDebugTask |
调试结束后运行的任务 |
flash:
openocd -f ../openocd.cfg -c init -c halt -c "program $(BUILD_DIR)/$(TARGET).hex verify reset exit"
reset:
openocd -f ../openocd.cfg -c init -c halt -c reset -c shutdown
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "Build",
"command": "make -j",
"problemMatcher": [
"$gcc"
],
"group": "build",
},
{
"type": "shell",
"label": "Flash",
"command": "make -j;make flash",
"problemMatcher": [
"$gcc"
],
"group": "build",
},
{
"type": "shell",
"label": "Reset",
"command": "make reset",
"problemMatcher": [
"$gcc"
],
"group": "build",
},
]
}
终端 -> 运行任务,会出现三个任务 Build、Flash 和 Reset
| 任务 |
解释 |
Build |
构建工程 |
Flash |
下载程序 |
Reset |
复位单片机 |
| 命令 |
解释 |
make |
编译工程代码 |
make flash |
将代码烧录进单片机 |
make reset |
将单片机复位 |