个人小型纪录片:
关键字:cmsis-dap,vscode软件调试32单片机
应用设备:win11,stm32f103。
使用软件:Vscode。
目的:抛弃keil使用vscode。
安装扩展:Crotex-Debug
make工具链:MinGW
编译程序工具链:gcc-arm-none-eabi。
程序包:OpenOCD。
大量步骤与下面链接内容相同:不赘述,跳转到指导员,https://blog.youkuaiyun.com/pyt1234567890/article/details/122522700
一、上述链接中的makefile内容添加:
1、添加需要编译的C文件:
######################################
# source
######################################
# C sources
C_SOURCES = \
Core/Src/main.c \
Core/Src/main_combine.c \
Core/Src/stm32f1xx_it.c \
//添加hal需要编译的C文件
Core/Src/stm32f1xx_hal_msp.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_adc_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_i2c.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rtc.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rtc_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c \
Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_wwdg.c
//添加用户新增的C文件 注意反斜杠
2、添加需要编译的H文件:
# C includes
C_INCLUDES = \
//最小系统头文件
-ICore/Inc \
-IDrivers/STM32F1xx_HAL_Driver/Inc \
-IDrivers/STM32F1xx_HAL_Driver/Inc/Legacy \
-IDrivers/CMSIS/Device/ST/STM32F1xx/Include \
-IDrivers/CMSIS/Include
//用户头文件 注意反斜杠
二、c_cpp_properties.json 文件内容
{
"configurations": [
{
"name": "Win32",
//头文件路径
"includePath": [
// "${workspaceFolder}/**",
"Core/Inc",
"Drivers/STM32F1xx_HAL_Driver/Inc",
"Drivers/STM32F1xx_HAL_Driver/Inc/Legacy",
"Drivers/CMSIS/Device/ST/STM32F1xx/Include",
"Drivers/CMSIS/Include",
"UserDrivers",
"UserLib"
],
//keil c++配置的宏定义
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE",
"USE_HAL_DRIVER",
"STM32F103xE"
],
//编译的工具链地址
"compilerPath": "C:\\Software_UserTool\\gcc-arm-none-eabi-10.3-2021.10\\bin\\arm-none-eabi-gcc",
"cStandard": "c11",
"cppStandard": "gnu++14",
"intelliSenseMode": "windows-gcc-arm"
}
],
"version": 4
}
三、launch.json 文件内容
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"cwd": "",
//编译后生成的elf文件位置
"executable": "./build/TKCMainPlusVer001.elf",
//debug窗口的名字
"name": "Debug with OpenOCD",
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
//"cmsis-dap.cfg","stm32f1x.cfg"需要放在项目的根目录
"configFiles": [
"cmsis-dap.cfg",
"stm32f1x.cfg"
],
//openOCD.exe位置
"searchDir": [
"C:\\Software_UserTool\\OpenOCD-20231002-0.12.0\\bin",
],
"runToEntryPoint": "main",
"showDevDebugOutput": "none"
//Debug全速运行时变量数据动态显示
"liveWatch": {
"enabled": true,
"samplesPerSecond": 4
}
}
]
}
四、tasks.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": [
"${relativeFile}"
],
"group": "build"
},
{
"label": "download",
"type": "shell",
"command": "openocd",
"args": [
"-f",
"cmsis-dap.cfg",
"-f",
"stm32f1x.cfg",
"-c",
"program build/TKCMainPlusVer001.elf verify reset exit"
],
"group": "build"
}
]
}
五、查看Debug全速运行时,变量的动态数据:
1、Debug窗口,CORTEX LIVE WATCH选项栏激活:
setting.json添加内容:
"cortex-debug.liveWatchRefreshRate": 250,
//填写自己存放的路径
"cortex-debug.armToolchainPath": "C:/Software_UserTool/gcc-arm-none-eabi-10.3-2021.10/bin",
launch.json添加内容:
"liveWatch": {
"enabled": true,
"samplesPerSecond": 4
}