Dynamically Changing RTT Blocking

 In Cortex-M, embedded C, Embedded Systems

If that title means anything to you, you’ve spent time on the internet trying to make RTT work for you. Read on for code to help you dynamically change if your RTT output blocks or not.

RTT is great for getting debug data from your device with minimal interruption to your real-time system. The only downside is that when trying to keep it real-time you often miss debug data. It would be really nice to be able to choose when the RTT output blocks so that you can get big chunks of data, say configuration data at startup, when real-time behavior is not required. After some digging in the Segger RTT libraries, I have the solution:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "SEGGER_RTT.h"
/**
 * @brief This reaches into the RTT Configuration and will change the RTT Mode.
 *
 * @param Flags This can be SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL, SEGGER_RTT_MODE_NO_BLOCK_TRIM, SEGGER_RTT_MODE_NO_BLOCK_SKIP, or SEGGER_RTT_MODE_DEFAULT
 */

void rttReconfigure(unsigned Flags)
{
    #if ENABLE_RTT
    SEGGER_RTT_LOCK();  //This keeps things thread-safe
    SEGGER_RTT_BUFFER_UP* pRing;
    pRing = (SEGGER_RTT_BUFFER_UP*)((char*)&_SEGGER_RTT.aUp[0] + SEGGER_RTT_UNCACHED_OFF);  // Access uncached to make sure we see changes made by the J-Link side and all of our changes go into HW directly
    pRing->Flags = Flags;
    SEGGER_RTT_UNLOCK();
    #else
    __NOP();
    #endif
}

Leave a Comment

Contact Us

We're not around right now. But you can send us an email and we'll get back to you, asap.

Start typing and press Enter to search