This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How do I resolve SEGGER_RTT_printf "warning: #192-D: unrecognized character escape sequence"

I have searched here on the DevZone, and also around the web, and don't see this issue mentioned elsewhere. I really appreciate any help finding a solution.

I tried following the instructions in the second half of the NordicSemi tutorial for "More advanced printing" here: devzone.nordicsemi.com/.../

But I am unable to compile due to the error in the title (main.c warning: #192-D: unrecognized character escape sequence).

I am using the nRF52832 (BMD-300 eval kit): www.rigado.com/.../

One of the tutorial steps is different for me than shown in the tutorial, and maybe this is the problem. In the step "Right-click nRF_Libraries and click Options", it doesn't show with green diamond icons, it's yellow folder icons instead by nRF_Libraries. And instead of "options for component class" it says "options for group" but it's still option Alt-F7 (so maybe that's not the problem after all, maybe just a UI change since this how-to page was published).

Anyway, I can't seem to figure out why this is happening or how to fix it. Even though it's just a warning rather than an error, it doesn't display colors in RTT Viewer, it's just a bunch of extra characters. How do I resolve this issue, please, and get colors to show in the output text on RTT Viewer?

//this is the only include that I've added for RTT: (pound)include "SEGGER_RTT.h"

LINE OF CODE: SEGGER_RTT_printf(0, RTT_CTRL_RESET"Red: " RTT_CTRL_TEXT_BRIGHT_RED"This text is red. " RTT_CTRL_TEXT_BLACK"" RTT_CTRL_BG_BRIGHT_RED"This background is red. " RTT_CTRL_RESET"Normal text again.");

OUTPUT IN RTT Viewer: 0> e[0mRed: e[1;31mThis text is red. e[2;30me[4;41mThis background is red. e[0mNormal text again.

  • Keil compiler has different set of escape characters. It doesn't understand \e. Change your color definitions in SEGGER_RTT.h so they look like this:

    //
    // Control sequences, based on ANSI.
    // Can be used to control color, and clear the screen
    //
    #if defined ( __CC_ARM ) //Keil uses different escape character
    
    #define RTT_CTRL_RESET                "\x1B[0m"         // Reset to default colors
    #define RTT_CTRL_CLEAR                "\x1B[2J"         // Clear screen, reposition cursor to top left
    
    #define RTT_CTRL_TEXT_BLACK           "\x1B[2;30m"
    #define RTT_CTRL_TEXT_RED             "\x1B[2;31m"
    #define RTT_CTRL_TEXT_GREEN           "\x1B[2;32m"
    #define RTT_CTRL_TEXT_YELLOW          "\x1B[2;33m"
    #define RTT_CTRL_TEXT_BLUE            "\x1B[2;34m"
    #define RTT_CTRL_TEXT_MAGENTA         "\x1B[2;35m"
    #define RTT_CTRL_TEXT_CYAN            "\x1B[2;36m"
    #define RTT_CTRL_TEXT_WHITE           "\x1B[2;37m"
    
    #define RTT_CTRL_TEXT_BRIGHT_BLACK    "\x1B[1;30m"
    #define RTT_CTRL_TEXT_BRIGHT_RED      "\x1B[1;31m"
    #define RTT_CTRL_TEXT_BRIGHT_GREEN    "\x1B[1;32m"
    #define RTT_CTRL_TEXT_BRIGHT_YELLOW   "\x1B[1;33m"
    #define RTT_CTRL_TEXT_BRIGHT_BLUE     "\x1B[1;34m"
    #define RTT_CTRL_TEXT_BRIGHT_MAGENTA  "\x1B[1;35m"
    #define RTT_CTRL_TEXT_BRIGHT_CYAN     "\x1B[1;36m"
    #define RTT_CTRL_TEXT_BRIGHT_WHITE    "\x1B[1;37m"
    
    #define RTT_CTRL_BG_BLACK             "\x1B[24;40m"
    #define RTT_CTRL_BG_RED               "\x1B[24;41m"
    #define RTT_CTRL_BG_GREEN             "\x1B[24;42m"
    #define RTT_CTRL_BG_YELLOW            "\x1B[24;43m"
    #define RTT_CTRL_BG_BLUE              "\x1B[24;44m"
    #define RTT_CTRL_BG_MAGENTA           "\x1B[24;45m"
    #define RTT_CTRL_BG_CYAN              "\x1B[24;46m"
    #define RTT_CTRL_BG_WHITE             "\x1B[24;47m"
    
    #define RTT_CTRL_BG_BRIGHT_BLACK      "\x1B[4;40m"
    #define RTT_CTRL_BG_BRIGHT_RED        "\x1B[4;41m"
    #define RTT_CTRL_BG_BRIGHT_GREEN      "\x1B[4;42m"
    #define RTT_CTRL_BG_BRIGHT_YELLOW     "\x1B[4;43m"
    #define RTT_CTRL_BG_BRIGHT_BLUE       "\x1B[4;44m"
    #define RTT_CTRL_BG_BRIGHT_MAGENTA    "\x1B[4;45m"
    #define RTT_CTRL_BG_BRIGHT_CYAN       "\x1B[4;46m"
    #define RTT_CTRL_BG_BRIGHT_WHITE      "\x1B[4;47m"
    
    #else
    #define RTT_CTRL_RESET                "\e[0m"         // Reset to default colors
    #define RTT_CTRL_CLEAR                "\e[2J"         // Clear screen, reposition cursor to top left
    
    #define RTT_CTRL_TEXT_BLACK           "\e[2;30m"
    #define RTT_CTRL_TEXT_RED             "\e[2;31m"
    #define RTT_CTRL_TEXT_GREEN           "\e[2;32m"
    #define RTT_CTRL_TEXT_YELLOW          "\e[2;33m"
    #define RTT_CTRL_TEXT_BLUE            "\e[2;34m"
    #define RTT_CTRL_TEXT_MAGENTA         "\e[2;35m"
    #define RTT_CTRL_TEXT_CYAN            "\e[2;36m"
    #define RTT_CTRL_TEXT_WHITE           "\e[2;37m"
    
    #define RTT_CTRL_TEXT_BRIGHT_BLACK    "\e[1;30m"
    #define RTT_CTRL_TEXT_BRIGHT_RED      "\e[1;31m"
    #define RTT_CTRL_TEXT_BRIGHT_GREEN    "\e[1;32m"
    #define RTT_CTRL_TEXT_BRIGHT_YELLOW   "\e[1;33m"
    #define RTT_CTRL_TEXT_BRIGHT_BLUE     "\e[1;34m"
    #define RTT_CTRL_TEXT_BRIGHT_MAGENTA  "\e[1;35m"
    #define RTT_CTRL_TEXT_BRIGHT_CYAN     "\e[1;36m"
    #define RTT_CTRL_TEXT_BRIGHT_WHITE    "\e[1;37m"
    
    #define RTT_CTRL_BG_BLACK             "\e[24;40m"
    #define RTT_CTRL_BG_RED               "\e[24;41m"
    #define RTT_CTRL_BG_GREEN             "\e[24;42m"
    #define RTT_CTRL_BG_YELLOW            "\e[24;43m"
    #define RTT_CTRL_BG_BLUE              "\e[24;44m"
    #define RTT_CTRL_BG_MAGENTA           "\e[24;45m"
    #define RTT_CTRL_BG_CYAN              "\e[24;46m"
    #define RTT_CTRL_BG_WHITE             "\e[24;47m"
    
    #define RTT_CTRL_BG_BRIGHT_BLACK      "\e[4;40m"
    #define RTT_CTRL_BG_BRIGHT_RED        "\e[4;41m"
    #define RTT_CTRL_BG_BRIGHT_GREEN      "\e[4;42m"
    #define RTT_CTRL_BG_BRIGHT_YELLOW     "\e[4;43m"
    #define RTT_CTRL_BG_BRIGHT_BLUE       "\e[4;44m"
    #define RTT_CTRL_BG_BRIGHT_MAGENTA    "\e[4;45m"
    #define RTT_CTRL_BG_BRIGHT_CYAN       "\e[4;46m"
    #define RTT_CTRL_BG_BRIGHT_WHITE      "\e[4;47m"
    
    #endif
    
Related