使用vscode+openocd+telnet+arm-gdb编写stm32程序

记录自己在Linux中配置stm32编写环境的过程

安装好arm-tool-chains工具链

https://askubuntu.com/questions/1243252/how-to-install-arm-none-eabi-gdb-on-ubuntu-20-04-lts-focal-fossa

安装好openocd

安装好openocd以后去.bashrc文件中输入:

1
alias ocd="openocd.exe -f /usr/local/share/openocd/scripts/interface/cmsis-dap.cfg -f /usr/local/share/openocd/scripts/target/stm32f1x.cfg -c \"bindto 0.0.0.0\" "

安装好telnet

cat /etc/resolv.conf查看主机地址,不要使用localhost

安装好telnet:在.bashrc

1
alias mytel="telnet  172.19.240.1 4444" 

由于我使用的是wsl,所以我在使用localhost的时候是无法正常工作的。而是要直接使用主机主机地址。

安装好vscode插件crotex-debug

配置好vscode

tasks.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "OpenOCD",
"command": "openocd.exe",
"args": [
// "-f",
// "${input:openocd.config}",
"-f",
"/usr/local/share/openocd/scripts/interface/fireDAP-mp157.cfg",
"-c",
"\"bindto 0.0.0.0\""
],
"type": "shell",
"isBackground": true,
"problemMatcher": [
"$gcc"
],//这个地方是防止vscode报错说找不到问题匹配程序
},
],
"inputs": [
{
"id": "openocd.config",
"type": "pickString",
"description": "Select the configuration file for OpenOCD",
"options": [
"/usr/local/share/openocd/scripts/target/stm32f1x.cfg"
],
"default": "/usr/local/share/openocd/scripts/target/stm32f1x.cfg"
}
]
}

配置好setting.json

1
2
3
4
5
{
"cortex-debug.gdbPath": "/usr/bin/gdb-multiarch",
"cortex-debug.openocdPath": "/mnt/d/work/openocd/xpack-openocd-0.12.0-1/bin/openocd.exe",
"cortex-debug.armToolchainPath":"/usr/bin/"
}

配置好lauch.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb-remote) Debug",
"type": "cortex-debug",
"request": "launch",
"servertype": "external",
"cwd": "${workspaceRoot}",
"runToEntryPoint": "main",
"executable": "${workspaceFolder}/config/stm32f103_elf/test.elf",
"svdFile": "${workspaceFolder}/config/stm32f103.svd/STM32F1_svd_v1.2/STM32F103.svd",
"gdbTarget": "172.19.240.1:3333",
"preLaunchTask": "OpenOCD",
},
],
}

配置好c_cpp_properties.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
{
"configurations": [
{
"name": "Linux",
"includePath": [
// "${workspaceFolder}/**",
"/home/ysc/stm32/test/User/**",
"${workspaceFolder}/STM32F10X_Std/Libraries/STM32F10x_StdPeriph_Driver/inc/**",
"${workspaceFolder}/STM32F10X_Std/Libraries/STM32F10x_StdPeriph_Driver/src/**",
"${workspaceFolder}/STM32F10X_Std/Libraries/CMSIS/**",
"${workspaceFolder}/STM32F10X_Std/Libraries/CMSIS/CM3/CoreSupport/**",
"${workspaceFolder}/STM32F10X_Std/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup/gcc_ride7/**",
"${workspaceFolder}/STM32F10X_Std/Utilities/STM32_EVAL/**",
"/home/ysc/stm32/LED/User/**"
],
"defines": [
"STM32F10X_HD",
"USE_STDPERIPH_DRIVER",
"_DEBUG",
"UNICODE",
"_UNICODE",
"__C_ARM",
"__IO",
"__STATIC_INLINE=static"
],
"compilerPath": "/usr/bin/arm-linux-gnueabi-gcc",
"cStandard": "c11",
"cppStandard": "c++98",
"intelliSenseMode": "linux-gcc-arm"
}
],
"version": 4
}

使用方法一

这个方法是直接在终端环境下进行调试的。

  1. 打开一个终端,输入ocd打开openocd服务
  2. 打卡另一个终端输出mytel,打开telnet服务
  3. 打开第三个终端,使用arm-none-linux-gdb ./test.elf进行调试。在gdb中输入target remote 172.19.240.1:3333连接telnet,之后就可以进行调试了。

使用方法二

这种方法是使用vscode中的调试插件来进行调试


使用vscode+openocd+telnet+arm-gdb编写stm32程序
https://ysc2.github.io/ysc2.github.io/2023/11/25/使用vscode-openocd-telnet-arm-gdb编写stm32程序/
作者
Ysc
发布于
2023年11月25日
许可协议