• [转]使用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:

    1. You are using a Segger J-Link (I’m using the J-Link CortexM)
    2. You are using Keil MDK v5 or later,which uses Software Packs.

    This guide is broken into three distinct phases:

    1. Installing the Logging Package and updating the Keil’s IDE to easily connect to Segger’s Log Viewer
    2. Configuring a project to use the Logging functions
    3. A quick demo of actual use

    Installing the Logging Package and updating the Keil

    These steps should only need to be performed once.

      1. Install the latest version of Segger’s J-Link: https://www.segger.com/jlink-software.html?step=1&file=JLink_496a.
    1. Install the Software Package I created for Logging
      1. Download Siever.Segger_RTT_Logger.1.0.1.pack. (It works with any system that Segger’s RTT supports, not just Nordic)
      2. Double click on the package. It should automatically install via Keil’s Package Installer.
    2. Update Keil’s Tools menu to allow easy access to the Log Viewer (which is the window you will use to view log messages).
      1. Open Keil.
      2. Select Tools → Customize Tools Menu... from the menu:

        1_AddCustomEntry
      3. Add a new entry for the Log Viewer. When done it should look something like:
        2_LogViewerEntryDetails

        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.

      1. Open the Project
      2. Select the Logger Package for inclusion in the project. Select Project → Manage → Select Software Packs...:

        1_AddPack
      3. Select the newly added Logger Package and set the version to fixed:

        2_SelectPackToAdd_1.0.1
    1. Add the Pack to the Run-Time Environment. Select Project → Manage → Run-Time Environment...:

      3_AddPackToRunTime
    2. Ensure that the package will be included at Run-Time. Expand it and make sure it is selected:

      4_ExpandLoggerPackAndSelect_1.0.1
    3. The package will need to be enabled via a define. Add the define to the project’s Preprocessor Symbols.
      1. Select Project → Options For Target...:

        OptionsForTarget
      2. Navigate to the C/C++ tab and add RTT_LOG_ENABLED to the Defines:

        AddDefine

    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:


    6_AddIncludeWhereNeeded

    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:


    7_AddLogMessages
    I generally start a debugging session and then launch the Log Viewer via the item added to the Tools menu:

    3_UpdatesMenu Launching

    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:

    4_LaunchSettings

    Here’s an example of the log generated by the three examples shown above:

    RunAndDebug

    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.

  • 相关阅读:
    YTU 1002: Home Work
    C++拷贝构造函数(深拷贝,浅拷贝)
    深入探讨this指针
    C++中关于strtok()函数的用法
    STL笔记之【map之移除元素】
    进程结束后,进程的所有内存都将被释放,包括堆上的内存泄露的内存。
    数组指针和指针数组的区别
    sizeof()用法汇总
    文件描述符和文件指针的区别
    字符集、字符编码、XML中的中文编码
  • 原文地址:https://www.cnblogs.com/libra13179/p/5428526.html
Copyright © 2020-2023  润新知