[转]使用RTT(Real-Time Terminal)
Logging events with on Nordic’s nRF series via Seger’s J-Link Real-Time Terminal
One of the most most common debugging techniques is “logging”, or creating a history of what happens while code runs. Logging can be especially difficult in embedded systems, which often lack a natural way to log events, like a console. Commonly UARTs are used to log messages via a serial port, but this approach can consume significant run-time that may undermine the timing constraints of the software. It also requires the use of additional pins to support development.
I’ve found it especially difficult to debug applications using Nordic’s Bluetooth Low Energy products (nRF family). Fortunately, due to some helpful hints by fellow Nordic developers (Thanks Jeremy) and great products from Segger, I’ve got a solution that suits my needs fairly well. Segger’s Real-Time Terminal is a perfect solution to the problem. I’ve taken the example’s provided by Segger and made a package from them (easier to configure on multiple projects). I’ve also added some wrapper functions that provide additional data I find helpful when debugging.
The following explains how to setup a logger for the nRF series of chips, but assumes that:
- You are using a Segger J-Link (I’m using the J-Link CortexM)
- You are using Keil MDK v5 or later,which uses Software Packs.
This guide is broken into three distinct phases:
- Installing the Logging Package and updating the Keil’s IDE to easily connect to Segger’s Log Viewer
- Configuring a project to use the Logging functions
- A quick demo of actual use
Installing the Logging Package and updating the Keil
These steps should only need to be performed once.
- Install the latest version of Segger’s J-Link: https://www.segger.com/jlink-software.html?step=1&file=JLink_496a.
- Install the Software Package I created for Logging
- Download Siever.Segger_RTT_Logger.1.0.1.pack. (It works with any system that Segger’s RTT supports, not just Nordic)
- Double click on the package. It should automatically install via Keil’s Package Installer.
- Update Keil’s Tools menu to allow easy access to the Log Viewer (which is the window you will use to view log messages).
- Open Keil.
- Select Tools → Customize Tools Menu... from the menu:
- Add a new entry for the Log Viewer. When done it should look something like:
There are a few things to notice here:- I typed Log Viewer in the first available slot. This will be the name of the new item on the Tools menu.
- The Command is the JLinkRTTViewer.exe. Verify that the path is correct for your installation.
- Note that Run Independent is checked.
The Tools menu should now have a new item that will be used to launcher the Log Viewer.
Configuring a project to use the Logging functions
You will need to do this for each project on which you want to use these logging functions.
- Open the Project
- Select the Logger Package for inclusion in the project. Select Project → Manage → Select Software Packs...:
- Select the newly added Logger Package and set the version to fixed:
- Add the Pack to the Run-Time Environment. Select Project → Manage → Run-Time Environment...:
- Ensure that the package will be included at Run-Time. Expand it and make sure it is selected:
- The package will need to be enabled via a define. Add the define to the project’s Preprocessor Symbols.
- Select Project → Options For Target...:
- Navigate to the C/C++ tab and add RTT_LOG_ENABLED to the Defines:
- Select Project → Options For Target...:
Demo of Use
In order to use the logging functions you will need to add calls to
the logging functions to your code. You can use primitive functions
provided by Segger, but I choose to use my own wrappers. In order to use
my wrappers you will need to include the header file:
and insert calls into your code. I’ve provided three functions that each have printf semantics (and each call Segger’s SEGGER_RTT_vprintf()). My functions are:
- loge(…)
- Used for logging run-time errors (shown in red)
- logw(…)
- Used for logging warnings (shown in yellow)
- logi(…)
- Used for logging general information (shown in white)
Here are some examples in code:
I generally start a debugging session and then launch the Log Viewer via the item added to the Tools menu:
The Log Viewer you will ask how it should connect to a debugger
session. When being run with an existing debugging session just
indicate it should connect to the debugging session:
Here’s an example of the log generated by the three examples shown above:
Notice that:
- The different warning styles are color coded.
- The log macros I’ve created insert the file name and line
number. This does consume additional flash memory, so don’t get too
carried away with log messages. - Currently I have all log messages going to the tab for Terminal 0.
It would be easy to update the approach to include different messages to
different terminal tabs for different modules.
Disclaimers
This work is provided as-is with no warranty or guarantee of any
sort. I’m new to Segger’s RTT and haven’t done any review of performance
issues. I’m also new to CMSIS Packages and haven’t verified that I’ve
followed all appropriate package conventions. At this point this is an
alpha version, but any input or suggestions are welcome. The log
macros were made for my needs when I developed them and may not suite
other’s needs. The formatting used for them could certainly be improved.
Credits
The package includes unmodified code provided by Segger at: http://download.segger.com/J-Link/RTT/RTT_Implementation_141217.zip. Code by Segger includes a copyright notice, but they have given me permission to share the package.
[转]使用RTT(Real-Time Terminal)的更多相关文章
- Segger RTT : Real Time Terminal SRAM 调试解决方法
http://segger.com/jlink-real-time-terminal.html Real Time Terminal SEGGER's Real Time Terminal (RTT) ...
- STM32 使用 printf 发送数据配置方法 -- 串口 UART, JTAG SWO, JLINK RTT
STM32串口通信中使用printf发送数据配置方法(开发环境 Keil RVMDK) http://home.eeworld.com.cn/my/space-uid-338727-blogid-47 ...
- segger rtt 输出 log
调试 mcu 的时候,使用 jlink 的 rtt 可以方便的输出信息. 输出有两种模式, client 和 logger. client 必须依附其他程序,比如说 mdk 调试状态,或者 logge ...
- Segger Real Time Terminal RTT JLINK 客户端软件 GUI 版本
- How RTT works
13.2 How RTT works 13.2.1 Target implementation Real Time Terminal uses a SEGGER RTT Control Block s ...
- RTT
Segger RTT的使用 一般arm系统中,如何通过电脑键盘和显示器同mcu进行交互最有效的有两种形式:arm7的semihost,cm时代的traceswo.现在jlink推出了颇具特色的rtt( ...
- 调试备忘录-J-Link RTT的使用(原理 + 教程 + 应用 + 代码)
MCU:STM32F407VE MDK:5.29 IAR:8.32 目录--点击可快速直达 目录 写在前面 什么是RTT? RTT的工作原理 RTT的性能 快速使用教程 高级使用教程 附上测试代码 2 ...
- mac-改造你的terminal
今天在知乎上看到了一篇关于<程序员如何优雅使用Mac>,里面介绍了不少Mac的高端使用技巧,其中关于terminal的部分更是深深的吸引了我,于是我也开始了我的terminal改造计划. ...
- Hive启动报错: Found class jline.Terminal, but interface was expected
报错: [ERROR] Terminal initialization failed; falling back to unsupported java.lang.IncompatibleClassC ...
随机推荐
- hdu1059 dp(多重背包二进制优化)
hdu1059 题意,现在有价值为1.2.3.4.5.6的石头若干块,块数已知,问能否将这些石头分成两堆,且两堆价值相等. 很显然,愚蠢的我一开始并想不到什么多重背包二进制优化```因为我连听都没有听 ...
- 【java规则引擎】《Drools7.0.0.Final规则引擎教程》第4章 4.3 定时器
定时器 规则用基于 interval(间隔)和cron的定时器(timer),替代了被标注过时的duration 属性.timer属性的使用示例: timer ( int: <initial d ...
- CUDA H624解码性能测试
测试环境: Cpu: Inter(R)Core(TM)i7-4790 CPU @3.6GHZ GPU: NVIDIA GeForce GTX960* 1 操作系统: W ...
- oracle在进行跨库访问时,采用dblink实现
首先了解下环境:在tnsnames.ora中配置两个数据库别名:test1/test1@11orcl1.tets2/tets2@12orlc2,在orcl1中创建database link来访问orc ...
- Javascript 在严格模式下禁止指向 this
如下代码, f() 输出的是 false,而 f2() 输出的是 true. 这是因为 f2 在严格模式下禁止 this 指向全局,所以 this 是 undefined, !this 当然是 tru ...
- 异常: java.security.InvalidKeyException: Illegal key size
今天在做接口测试的时候遇到个异常: java.security.InvalidKeyException: Illegal key size. SecretKeySpec secretKeySpec = ...
- linux上通过lighttpd上跑一个C语言的CGI小页面以及所遇到的坑
Common Gateway Interface如雷贯耳,遗憾的是一直以来都没玩过CGI,今天尝试一把.Tomcat可以是玩CGI的,但得改下配置.为了方便,直接使用一款更轻量级的web服务器ligh ...
- github高效搜索使用总结
swoole 普通搜索 in:name swoole 搜索仓库的名称,搜索仓库名称包含swoole关键字的所有项目 in:description swoole 搜索描述中包含swoole关键字的项目 ...
- IO测试工具之fio详解(转)
http://www.cnblogs.com/raykuan/p/6914748.html 目前主流的第三方IO测试工具有fio.iometer和Orion,这三种工具各有千秋. fio在Linux系 ...
- java学习之路之javaSE基础3
所有代码都未经测试.. 1:for循环的格式? for循环格式: for(初始化表达式;条件表达式;循环后的操作表达式) { 循环体; } 执行流程: * a:执行初始化语句 * b:执行判断条件语句 ...