OpenOCD- Jlink&IAR via GDB Server

本文介绍了如何在Windows环境下利用OpenOCD与GDB Server进行STM32微控制器的远程调试,包括设置OpenOCD GDB服务器、配置IAR调试环境、以及通过本地主机地址连接进行调试的全过程。此教程适用于STM32开发人员,旨在提高开发效率并优化调试体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

After installation of OpenOCD

http://blog.youkuaiyun.com/iamlvshijie/article/details/7423611

we can test GCB Sever before development.

What is GDB Server?

from wikipedia:

gdbserver is a computer program that makes it possible to remotely debug other programs.[1] Running on the same system as the program to be debugged, it allows the GNU Debugger to connect from another system; that is, only the executable to be debugged needs to be resident on the target system, while the source code and a copy of the binary file to be debugged reside on the developer’s local computer. The connection can be either TCP or a serial line.

Step1: Run OpenOCD GDB Server

run your openocd, telling it you jtag interface and target like this, I write a bat  file for windows.

@echo OpenOCD JLink GDBServer
c:
cd cygwin\openocd\tcl
openocd -f interface/jlink.cfg -f target/stm32f1x.cfg
pause

then I check the network connecting:



Step2: IAR Setting

open a IAR Project, then make the projects.

choose project>Options>Debugger

select GDB Server,



then 



type localhost, 3333   //attention, there is a comma before 3333

so why is 3333? we check it out.

openocd use the tcp port 3333.


Step3 Debugging

then start debugging: Project>Download> Debug

check it again:



It proves what is GDB server.

Done. It is a little slower than using jlink directly. 



帮我检查一下下面的配置,并分析为什么RTT viewer能连上芯片,但是不打印log { "folders": [ { "path": "." } ], "tasks": { "version": "2.0.0", "tasks": [ { "label": "build", "command": "cmake -S . -B Debug; ninja -C Debug -d stats", "type": "shell", "args": [], "group": "build", "problemMatcher": [] }, { "label": "rebuild", "command": "cmake -S . -B Debug; ninja -C Debug -t clean; ninja -C Debug -d stats", "type": "shell", "args": [], "group": "build" }, { "label": "clean", "command": "rd -r Debug", "type": "shell", "args": [], "group": "build" }, { "label": "export to IAR", "command": "./EWPtool.exe -p . -n onboard_io_m4 -c debug", "type": "shell", "args": [], "group": "build" } ], }, "launch": { "configurations": [ { "type": "cortex-debug", "request": "launch", "name": "GDB", "cwd": "${workspaceRoot}", "gdbPath": "C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.10/bin/arm-none-eabi-gdb.exe", "executable": "${workspaceRoot}/Debug/binaries/onboard-io-firmware.elf", "serverpath": "C:/Program Files/SEGGER/JLink_V846/JLinkGDBServerCL.exe", "servertype": "jlink", "device": "MIMX8MM4_M4", "interface": "swd", // "rttConfig": { // "enabled": true, // "address": "auto", // "decoders": [ // { // "label": "", // "port": 0, // "type": "console" // } // ] // }, "svdFile": "${workspaceRoot}/MIMX8M_cm4.svd.xml", "postLaunchCommands": [ "target remote localhost:50000", // "monitor reset", "monitor halt", "load", // "monitor go", ], // "overrideResetCommands": [ // "monitor reset", // "monitor halt", // "load", // ], "runToEntryPoint": "main", "showDevDebugOutput":"raw", }, { "type": "cspy", "request": "attach", "name": "C-Spy", "target": "arm", "program": "${workspaceRoot}/Debug/binaries/onboard-io-firmware.elf", "driver": "J-Link/J-Trace", "stopOnSymbol": "main", "workbenchPath": "C:/Program Files/IAR Systems/Embedded Workbench 9.2", "projectPath": "${workspaceFolder}", "projectConfiguration": "Debug", "leaveTargetRunning": false, "trace": false, "driverOptions": [ "--plugin=C:\\Program Files\\IAR Systems\\Embedded Workbench 9.2\\arm\\bin\\armbat.dll", "--device_macro=C:\\Program Files\\IAR Systems\\Embedded Workbench 9.2\\arm/config/debugger/NXP/imx8m_trace.dmac", "--backend", "--endian=little", "--cpu=Cortex-M4", "--fpu=VFPv4_SP", "-p", "C:\\Program Files\\IAR Systems\\Embedded Workbench 9.2\\arm/config/debugger/NXP/MIMX8MM4_M4.ddf", "--drv_verify_download", "--semihosting", "--device=MIMX8MM6_M4", "--drv_communication=USB0", "--drv_interface_speed=auto", "--jlink_initial_speed=32", "--jlink_reset_strategy=0,0", "--drv_catch_exceptions=0x000", "--drv_swo_clock_setup=72000000,0,2000000" ], }, ] }, "settings": { "files.associations": { "*.h": "c", "*.hpp": "cpp", }, "C_Cpp.default.includePath": [ "C:/Program Files/IAR Systems/Embedded Workbench 9.2/arm/inc/c", "C:/Program Files/IAR Systems/Embedded Workbench 9.2/arm/inc/cpp", ], "C_Cpp.autoAddFileAssociations": false, "cortex-debug.variableUseNaturalFormat": true, "iar-debug.breakpointType": "Software", "iar-debug.enableMulticoreLockstepMode": true, "debug.allowBreakpointsEverywhere": true, "files.autoGuessEncoding": true, "iar.installationPath": "C:\\Program Files (x86)\\IAR Systems\\Embedded Workbench 6.0\\", "iar.projectFile": "f:\\trend essential\\BEATS-Essential-Controller-onboard-io-firmware\\onboard_io_m4.ewp", }, }
最新发布
07-10
当 RTT Viewer 能够连接到芯片但无法打印日志时,通常意味着底层通信链路(如 SWD 或 JTAG)已经建立,但 RTT 通道的配置或初始化存在问题。以下是对这一问题的排查与修复方法,并结合 `launch.json` 配置进行分析。 ### 检查 RTT 初始化 RTT Viewer 需要目标芯片上的固件主动初始化 SEGGER RTT 库,否则即使连接成功也无法读取日志。确保在代码中调用了 `SEGGER_RTT_Init()` 并正确启动了 RTT 通道[^1]: ```c #include "SEGGER_RTT.h" int main(void) { SEGGER_RTT_Init(); // 初始化 RTT while (1) { SEGGER_RTT_WriteString(0, "Hello from RTT!\n"); // 向通道 0 写入字符串 } } ``` 如果未调用初始化函数或写入操作被禁用,则 RTT Viewer 将无法接收到任何数据。 ### 核对 `launch.json` 配置 检查 `launch.json` 文件中的调试器配置是否启用了 RTT 支持。以 OpenOCD 为例,确认配置中包含正确的命令来启用 RTT: ```json { "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/build/project.elf", "args": [], "stopAtEntry": true, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "gdb", "debugServerPath": "/path/to/openocd", "miDebuggerPath": "/path/to/arm-none-eabi-gdb", "miDebuggerServerAddress": "localhost:3333", "debuggerArgs": [ "-c", "rtt start 0x20000000 0x2000 # 启动 RTT,指定缓冲区地址和大小" ] } ``` 上述配置中的 `rtt start` 命令用于告诉 OpenOCD 在哪个内存地址开始监听 RTT 缓冲区。若地址不匹配或未启用 RTT,Viewer 将无法捕获日志输出[^1]。 ### 检查内存地址分配 RTT 使用芯片的 RAM 区域作为数据缓冲区,因此需要确保链接脚本或运行时配置中为 RTT 分配了正确的内存空间。例如,在 `SEGGER_RTT_Conf.h` 中定义的缓冲区起始地址应与 `launch.json` 中指定的地址一致: ```c #define SEGGER_RTT_BUFFER_START (0x20000000) #define SEGGER_RTT_BUFFER_SIZE (0x1000) ``` 如果地址冲突或不可访问,RTT Viewer 可能会连接成功但无法读取内容。 ### 检查 RTT Viewer 设置 在 RTT Viewer 的界面中,确认已选择正确的 RTT 控制块地址和通道号。某些调试器(如 J-Link)要求手动输入控制块地址(通常为 `0x20000000`),否则可能无法识别日志流[^1]。 此外,确保 RTT Viewer 的通道设置为“Auto-Detect”或手动指定了正确的通道索引(如 Channel 0)。如果通道未启用或被其他任务占用,也可能导致无日志输出。 ### 总结排查步骤 1. 确认目标固件中调用了 `SEGGER_RTT_Init()` 并执行了写入操作。 2. 检查 `launch.json` 是否包含启用 RTT 的命令及正确的内存地址。 3. 核对 RTT 缓冲区地址是否与链接脚本或运行时配置一致。 4. 在 RTT Viewer 中检查控制块地址和通道设置是否正确。 通过以上步骤,可以定位并解决 RTT Viewer 连接芯片正常但无法打印日志的问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值