-
推荐使用 msys2 安装工具链
pacman -S mingw-w64-x86_64-make pacman -S mingw-w64-x86_64-python pacman -S mingw-w64-x86_64-stlink pacman -S mingw-w64-x86_64-openocd pacman -S mingw-w64-x86_64-arm-none-eabi-toolchain
不要忘记将工具链加入系统环境变量
File
->New Project
- 选择匹配的芯片,点击
Start Project
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
- 右键通过
Code
打开
- 安装插件
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 |
智能感知模式 |
- 新建文件
openocd.cfg
,写入以下内容
source [find interface/stlink-v2.cfg]
source [find target/stm32f1x.cfg]
字符 | 解释 |
---|---|
interface |
调试器 |
target |
目标板 |
{
"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 |
调试结束后运行的任务 |
- 打开
Makefile
文件,追加以下内容
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 |
复位单片机 |
ctrl+`
切换终端,输入以下命令
命令 | 解释 |
---|---|
make |
编译工程代码 |
make flash |
将代码烧录进单片机 |
make reset |
将单片机复位 |
Python
脚本