- 个人笔记
- 安装VSCODE。
- 安装CYGWIN以及里面的一套东西。
- 安装OPENOCD。
- 安装STM32CUBE以及一套库的下载。
帮助: CYGWIN:https://cygwin.com/
ARM: https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads
OPENOCD:http://openocd.org/
STM32-LINK UTILITY:https://www.st.com/content/st_com/en/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-programmers/stsw-link004.html
STM32CUBE:https://www.st.com/en/embedded-software/stm32cubef4.html
- 开发环境搭建 用stm32cube生成一个带makefile的文件,里面部分头文件可能需要自己添加。
- 用VSCODE打开此文件夹,配置好以c_cpp_properaties.json,特别是include目录。
{ "configurations": [ { "name": "Win32", "includePath": [ "${workspaceFolder}/**" ], "defines": [ "_DEBUG", "UNICODE", "_UNICODE" ], "compilerPath": "/usr/bin/gcc", "cStandard": "c11", "cppStandard": "c++17", "intelliSenseMode": "clang-x64" } ], "version": 4 }
- 配置好setting.json。
- launch.json配置如下,如果使用openocd的话:
{ "version": "0.2.0", "configurations": [ { "name": "ARM Debug", "type": "cppdbg", "request": "launch", "miDebuggerPath": "C:/Program Files (x86)/GNU Tools Arm Embedded/5.4 2016q3/bin/arm-none-eabi-gdb.exe", "targetArchitecture": "arm", "program": "${workspaceRoot}/build/pwmTest.elf", "setupCommands": [ { "text": "file 'C:/Users/Cairne/OneDrive/Code/stm32/nucleo/PWMTest/CubeMX/PWMTest/build/pwmTest.elf'" }, { "text": "target remote localhost:3333" }, { "text": "monitor reset" }, { "text": "monitor halt" }, { "text": "load" } ], "preLaunchTask": "build", "launchCompleteCommand": "None", "externalConsole": true, "cwd": "${workspaceRoot}" } ] }
关于端口的解释:
- 在安装完openocd后可以使用代码
PS C:\OpenOCD-20190828-0.10.0\share\openocd\scripts\interface> openocd -v
Open On-Chip Debugger 0.10.0 (2019-08-28) [https://github.com/sysprogs/openocd]
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
来查看是否安装成功,然后安装成功STLINK驱动后可以查到到
这个设备。
- 使用命令:
openocd -f .\stlink-v2-1.cfg -f C:\OpenOCD-20190828-0.10.0\share\openocd\scripts\target\stm32f3x.cfg
Open On-Chip Debugger 0.10.0 (2019-08-28) [https://github.com/sysprogs/openocd]
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
WARNING: interface/stlink-v2-1.cfg is deprecated, please switch to interface/stlink.cfg
Info : auto-selecting first available session transport "hla_swd". To override use 'transport select <transport>'.
Info : The selected transport took over low-level target control. The results might differ compared to plain JTAG/SWD
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : clock speed 1000 kHz
Info : STLINK V2J28M17 (API v2) VID:PID 0483:374B
Info : Target voltage: 3.252528
Info : stm32f3x.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 3333 for gdb connections
Info : accepting 'gdb' connection on tcp/3333
可以看到端口是3333,对应上面的VSCODE的配置文件里的设置。可以在每次调试前输入这个命令以连上openocd。或者在launch.json里写一个任务,每次调试之前都自动连接。
- 成功界面: