Multiple channels in RTT

Segger RTT (Real-Time Terminal) supports multiple data channels.

RTT Viewer uses channel 0 only, and implements multiple virtual terminals on top of this. The terminal can be switched by SEGGER_RTT_SetTerminal(). Channel 0 is used by NRF_LOG. NRF_LOG does not do terminal switching, so you can do it yourself (be careful about reentracy though).

Data from other channels can be read using RTT Logger. To send data from NRF to RTT Logger:

  1. In sdk_config.h, adjust value of SEGGER_RTT_CONFIG_MAX_NUM_UP_BUFFERS. The default is 2, which gives you 1 extra channel besides channel 0. In the example below, it should be set to 3.

  2. Allocate data buffer (on heap!) for each channel

     uint8_t data1Buffer[128];
     uint8_t data2Buffer[128];
    
  3. Call SEGGER_RTT_Init() or let NRF_LOG_INIT() do it for you if you have configured logging via RTT.

  4. Call SEGGER_RTT_ConfigUpBuffer() to tell RTT to use your buffers.

     SEGGER_RTT_ConfigUpBuffer(1, "DATA1", data1Buffer, 128, SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL);
     SEGGER_RTT_ConfigUpBuffer(2, "DATA2", data2Buffer, 128, SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL);
    
  5. Call SEGGER_RTT_Write(), SEGGER_RTT_WriteString() or SEGGER_printf() specifying your channel number.

     int cnt = 0;
     char buf[32];
     while (1) {	
             for (int j=0; j<3; j++) {
                     sprintf(buf, "Message # %d channel %d\n", cnt, j);
                     SEGGER_RTT_WriteString(j, buf);
             }
             cnt++;
             nrf_delay_ms(2000);
     }
    
  6. Start RTT Logger and let the magic happen: https://i.imgur.com/GDNgoCM.png Note that by default RTT Logger creates log files in the same directory as its exe file.

  7. Detailed documentation for SEGGER_RTT_* functions can be found in chapter 13 of J-Link user manual.

  8. You can also use down buffers to send data to NRF. However, there is no host-side software to do this, except for sending data to channel 0 via RTT Viewer. But apparently you can do it yourself if you buy J-Link SDK license.

Parents
  • Yes, I call SEGGER_RTT_Init. I do everything exactly as you, except I have 2 additional channels - 3 in all. I wonder whether the buffers shouldn't be placed like they are for channel 0 in "SEGGER_RTT.h":

    SEGGER_RTT_PUT_BUFFER_SECTION(SEGGER_RTT_BUFFER_ALIGN(static char _acUpBuffer  [BUFFER_SIZE_UP]));
    SEGGER_RTT_PUT_BUFFER_SECTION(SEGGER_RTT_BUFFER_ALIGN(static char _acDownBuffer[BUFFER_SIZE_DOWN]));
    
Comment
  • Yes, I call SEGGER_RTT_Init. I do everything exactly as you, except I have 2 additional channels - 3 in all. I wonder whether the buffers shouldn't be placed like they are for channel 0 in "SEGGER_RTT.h":

    SEGGER_RTT_PUT_BUFFER_SECTION(SEGGER_RTT_BUFFER_ALIGN(static char _acUpBuffer  [BUFFER_SIZE_UP]));
    SEGGER_RTT_PUT_BUFFER_SECTION(SEGGER_RTT_BUFFER_ALIGN(static char _acDownBuffer[BUFFER_SIZE_DOWN]));
    
Children
No Data