VS Code开发STM32F4xx jlink接口swd模式(测试OK)
下面的代码(已验证),只作为参考,不同情况的更改参照文章末尾链接
c_cpp_properties.json代码
(其中include路径和宏定义可以参照makefile添加) :
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE",
"USE_HAL_DRIVER",
"STM32F407xx"
],
"windowsSdkVersion": "10.0.22621.0",
"compilerPath": "D:/Program Files/STN32DevelopTools/bin/arm-none-eabi-gcc.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-gcc-arm",
"browse": {
"path": [
"${workspaceFolder}/**",
"${workspaceFolder}/Core/Inc",
"${workspaceFolder}/LWIP/App",
"${workspaceFolder}/LWIP/Target",
"${workspaceFolder}/Middlewares/Third_Party/LwIP/src/include",
"${workspaceFolder}/Middlewares/Third_Party/LwIP/system",
"${workspaceFolder}/Drivers/STM32F4xx_HAL_Driver/Inc",
"${workspaceFolder}/Drivers/STM32F4xx_HAL_Driver/Inc/Legacy",
"${workspaceFolder}/Middlewares/Third_Party/FreeRTOS/Source/include",
"${workspaceFolder}/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2",
"${workspaceFolder}/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F",
"${workspaceFolder}/Drivers/BSP/Components/lan8742",
"${workspaceFolder}/Middlewares/Third_Party/LwIP/src/include/netif/ppp",
"${workspaceFolder}/Drivers/CMSIS/Device/ST/STM32F4xx/Include",
"${workspaceFolder}/Middlewares/Third_Party/LwIP/src/include/lwip",
"${workspaceFolder}/Middlewares/Third_Party/LwIP/src/include/lwip/apps",
"${workspaceFolder}/Middlewares/Third_Party/LwIP/src/include/lwip/priv",
"${workspaceFolder}/Middlewares/Third_Party/LwIP/src/include/lwip/prot",
"${workspaceFolder}/Middlewares/Third_Party/LwIP/src/include/netif",
"${workspaceFolder}/Middlewares/Third_Party/LwIP/src/include/compat/posix",
"${workspaceFolder}/Middlewares/Third_Party/LwIP/src/include/compat/posix/arpa",
"${workspaceFolder}/Middlewares/Third_Party/LwIP/src/include/compat/posix/net",
"${workspaceFolder}/Middlewares/Third_Party/LwIP/src/include/compat/posix/sys",
"${workspaceFolder}/Middlewares/Third_Party/LwIP/src/include/compat/stdc",
"${workspaceFolder}/Middlewares/Third_Party/LwIP/system/arch",
"${workspaceFolder}/Drivers/CMSIS/Include",
"${workspaceFolder}/modbus/include",
"${workspaceFolder}/canfestival/inc",
"D:/Program Files/STN32DevelopTools/arm-none-eabi/include",
"D:/Program Files/STN32DevelopTools/arm-none-eabi/include/c++/10.3.1",
"D:/Program Files/STN32DevelopTools/arm-none-eabi/include/c++/10.3.1/arm-none-eabi/thumb/v7",
"D:/Program Files/STN32DevelopTools/arm-none-eabi/include/c++/10.3.1/backward",
"D:/Program Files/STN32DevelopTools/arm-none-eabi/include/sys",
"D:/Program Files/STN32DevelopTools/lib/gcc/arm-none-eabi/10.3.1/include",
"D:/Program Files/STN32DevelopTools/lib/gcc/arm-none-eabi/10.3.1/include-fixed"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
launch.json 代码:
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/${workspaceFolderName}.elf",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "D:/Program Files/STN32DevelopTools/bin/arm-none-eabi-gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
},
]
}
settings.json代码:
{
"files.associations": {
"user_mb_app.h": "c",
"main.h": "c",
"motor.h": "c",
"can.h": "c",
"canopen_app.h": "c"
}
}
tasks.json 代码:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "编译项目",
"type": "shell",
"command": "make",
"args": [
"-j4"
],
"problemMatcher": [
"$armcc"
]
},
{
"label": "启动调试下载器",
"type": "shell",
"command": "openocd -f interface/jlink.cfg -c 'transport select swd' -f target/stm32f4x.cfg",
},
{
"label": "Build&Update",
"type": "shell",
"command": "openocd",
"args": [
"-c",
"adapter driver jlink",
"-c",
"transport select swd",
"-f",
"D:/Program Files/STN32DevelopTools/OpenOCD-20231002-0.12.0/share/openocd/scripts/interface/jlink.cfg",
"-f",
"D:/Program Files/STN32DevelopTools/OpenOCD-20231002-0.12.0/share/openocd/scripts/target/stm32f4x.cfg",
"-c",
//"D:/上海电气项目/contral_3.0_dmke_bms1.0-main/build/modbus_tcp_freertos.elf verify reset exit"
"program build/modbus_tcp_freertos.elf verify reset exit"
],
"problemMatcher": [
"$gcc"
]
}
]
}
任务使用效果:Ctrl+Shift+P----点击任务:运行任务----可以选择运行任务,分别是:调试,烧录,编译
选择编译项目:
选择启动调试: (需要电脑jink连接STM32)
选择Build&Update:
参考链接1 参考链接2 参考链接3 参考链接3的b站视频