Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Example that logs over Segger RTT requiring no configuration changes by me

I'm trying to get debug output to appear in my Segger J-LINK SWO viewer (from an NR52840 SDK board with NRF5 v16) which I understand is a potentially complicated process; I've received nothing in the SWO viewer so far.  Do you have an example which sends debug output to Segger RTT by default, without me screwing anything up, i.e. all I have to do is make flash, just so that I can check that the connection and the Segger tools are good (not that there's much that can go wrong with them)?

FYI, in my sdk_config.h I have NRF_LOG_ENABLED 1,  NRF_LOG_BACKEND_RTT_ENABLED 1, NRF_LOG_BACKEND_UART_ENABLED 0NRF_LOG_DEFERRED 0 and NRF_LOG_DEFAULT_LEVEL 3 and in main.c I start with:

NRF_LOG_INIT(NULL);
NRF_LOG_DEFAULT_BACKENDS_INIT();

NRF_LOG_INFO("Hello world.\n");

In the Segger SWO viewer I've selected nRF52840_xxAA, let it measure the clock, selected channel 0, the green LED near the PCA10056 on the board is flashing regularly and I pressed the reset button on the board. Nada.

Oh, and I also have the defaults for the Segger RTT settings, i.e.:

#define SEGGER_RTT_CONFIG_BUFFER_SIZE_UP 512
#define SEGGER_RTT_CONFIG_MAX_NUM_UP_BUFFERS 2
#define SEGGER_RTT_CONFIG_BUFFER_SIZE_DOWN 16
#define SEGGER_RTT_CONFIG_MAX_NUM_DOWN_BUFFERS 2
#define SEGGER_RTT_CONFIG_DEFAULT_MODE 0

Rob

Parents
  • I've generally had more success with the RTTClient. Could you try that as well? I have included some screenshots below to show how I tested it here. We do not have any examples for SWO that I'm aware of. I'm actually not sure if this output is even available on the Jlink lite we have on our DKs. I will find out if you are interested.

    RTT viewer:

    RTT Client:

  • Yes, I would be interested in SWO I think, seems simpler for me.

    I did have auto-detect on in the RTT Viewer.  Just did what you suggested and started JLink in one DOS box:

    Connecting to target via SWD
    Found SW-DP with ID 0x2BA01477
    Found SW-DP with ID 0x2BA01477
    Scanning AP map to find all available APs
    AP[2]: Stopped AP scan as end of AP map has been reached
    AP[0]: AHB-AP (IDR: 0x24770011)
    AP[1]: JTAG-AP (IDR: 0x02880000)
    Iterating through AP map to find AHB-AP to use
    AP[0]: Core found
    AP[0]: AHB-AP ROM base: 0xE00FF000
    CPUID register: 0x410FC241. Implementer code: 0x41 (ARM)
    Found Cortex-M4 r0p1, Little endian.
    FPUnit: 6 code (BP) slots and 2 literal slots
    CoreSight components:
    ROMTbl[0] @ E00FF000
    ROMTbl[0][0]: E000E000, CID: B105E00D, PID: 000BB00C SCS-M7
    ROMTbl[0][1]: E0001000, CID: B105E00D, PID: 003BB002 DWT
    ROMTbl[0][2]: E0002000, CID: B105E00D, PID: 002BB003 FPB
    ROMTbl[0][3]: E0000000, CID: B105E00D, PID: 003BB001 ITM
    ROMTbl[0][4]: E0040000, CID: B105900D, PID: 000BB9A1 TPIU
    ROMTbl[0][5]: E0041000, CID: B105900D, PID: 000BB925 ETM
    Cortex-M4 identified.
    J-Link>g
    
    **************************
    WARNING: T-bit of XPSR is 0 but should be 1. Changed to 1.
    **************************
    
    J-Link>r
    Reset delay: 0 ms
    Reset type NORMAL: Resets core & peripherals via SYSRESETREQ & VECTRESET bit.
    Reset: Halt core after reset via DEMCR.VC_CORERESET.
    Reset: Reset device via AIRCR.SYSRESETREQ.
    J-Link>

    ...but when I start jlinkrttclient in another window it looks the same as yours except no debug is printed below it:

    C:\Program Files (x86)\SEGGER\JLink_V641a>jlinkrttclient
    ###RTT Client: ************************************************************
    ###RTT Client: *               SEGGER Microcontroller GmbH                *
    ###RTT Client: *   Solutions for real time microcontroller applications   *
    ###RTT Client: ************************************************************
    ###RTT Client: *                                                          *
    ###RTT Client: *       (c) 2012 - 2016  SEGGER Microcontroller GmbH       *
    ###RTT Client: *                                                          *
    ###RTT Client: *     www.segger.com     Support: [email protected]       *
    ###RTT Client: *                                                          *
    ###RTT Client: ************************************************************
    ###RTT Client: *                                                          *
    ###RTT Client: * SEGGER J-Link RTT Client   Compiled Nov 27 2018 14:10:37 *
    ###RTT Client: *                                                          *
    ###RTT Client: ************************************************************
    
    ###RTT Client: -----------------------------------------------
    ###RTT Client: Connecting to J-Link RTT Server via localhost:19021  Connected.
    SEGGER J-Link V6.41a (beta) - Real time terminal output
    J-Link OB-SAM3U128-V2-NordicSemi compiled Jan 21 2020 17:30:48 V1.0, SN=683253856
    Process: JLink.exe
    

    This is with the ble_peripheral build still on the NRF52840 DK board.  What am I doing wrong?

  • Ooo!  Belay that, I just built and download my own build to my board and J-Link RTT client suddenly burst into life:

    <info> app: Hello world.
    
    <info> app: CELLULAR_PORT_TEST: tick time now is 0.
    
    <info> app: CELLULAR_PORT_TEST: creating a mutex...
    
    <info> app:                     returned error code 0, handle 0x20000978.
    
    <info> app: CELLULAR_PORT_TEST: creating a queue...
    
    <info> app:                     returned error code 0, handle 0x200009c0.
    
    <info> app: CELLULAR_PORT_TEST: creating a test task with stack 2048 byte(s) and priority 12, passing it the pointer 0x20000220 containing

    Obviously I'm doing something right, just need to figure out the sequence.  Thanks for your help, if you have anything on using SWO then do let me know.

Reply
  • Ooo!  Belay that, I just built and download my own build to my board and J-Link RTT client suddenly burst into life:

    <info> app: Hello world.
    
    <info> app: CELLULAR_PORT_TEST: tick time now is 0.
    
    <info> app: CELLULAR_PORT_TEST: creating a mutex...
    
    <info> app:                     returned error code 0, handle 0x20000978.
    
    <info> app: CELLULAR_PORT_TEST: creating a queue...
    
    <info> app:                     returned error code 0, handle 0x200009c0.
    
    <info> app: CELLULAR_PORT_TEST: creating a test task with stack 2048 byte(s) and priority 12, passing it the pointer 0x20000220 containing

    Obviously I'm doing something right, just need to figure out the sequence.  Thanks for your help, if you have anything on using SWO then do let me know.

Children
  • Hmmm.  Haven't been able to do it again though.  Any hints on reliability?  I've tried reducing the speed from 4000 kHz to 1000 kHz but that doesn't seem to have helped.

  • It seems to work only the first time after JLink connects.  If I do a reset (pressing 'r' in JLink commander, or pressing the reset button on the board) nothing more comes out; I have to restart JLink commander and then does stuffs appear in the RTT viewer once more.

    Any clues as to why that might be?

  • No, even that's not consistent, it just seems to be unreliable.

  • I have seen some issues with the RTT viewer, but the RTT itself has been reliable in my experience (I'm usually viewing the logs in the SES IDE). I noticed now from your logs that you are using a beta release for the J-link, maybe that's the problem. Could you try to update it? 

    Simple Blinky example with RTT logging:

    blinky_pca10056.hex

    I found this old thread I had on SWO: https://devzone.nordicsemi.com/f/nordic-q-a/31263/itm_sendchar-with-pca10056-nrf52840. As you can see, it will still require some configuration to get working plus we do not have a logger backend for it.

  • There seem to be two distinct behaviours.  I've switched to the release version of the JLink tools (6.64B) and I find that sometimes I get absolutely nothing at all from the target, no matter how many times I power it down, restart JLink, restart jlinkrttclient etc.  Other times it bursts into life and stays working for a while and in that situation I see lost characters, sometimes all of them past a certain point in execution, sometimes just a few.

    I changed main() to just do this:

    int main(void)
    {
        NRF_LOG_INIT(NULL);
        NRF_LOG_DEFAULT_BACKENDS_INIT();
    
        NRF_LOG_RAW_INFO("\nStarting up...\n");
        NRF_LOG_RAW_INFO("Printing a hex count 256 times in a loop...\n");
        for (size_t count = 0; count < 256; count++) {
            NRF_LOG_RAW_INFO("%02x", count);
        }
        NRF_LOG_RAW_INFO("\nDone.\n");
        while (1) {};
    }

    ...and sometimes it just stops in the middle, which you can see in the second case here:

    Starting up...
    Printing a hex count 256 times in a loop...
    000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF
    Done.
    
    Starting up...
    Printing a hex count 256 times in a loop...
    000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF
    Starting up...
    Printing a hex count 256 times in a loop...
    000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF
    Done.

    Other times it loses characters, which if you look carefully you can see in the output here where it loses four prints, eight characters on the 6th iteration (I've inserted spaces so that you can see the gap):

    Starting up...
    Printing a hex count 256 * 10 times in a loop...
    000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF
    000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF
    000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF
    000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF
    000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF
    000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2F3        03132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF
    000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF
    000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF
    000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF
    000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF
    Done.

    In these cases the viewer is still running, if I press the reset button on the target and it's in a "working" phase it reads the new output, it seem that the target either stopped or lost all further characters or lost some characters.  I had assumed that with NRF_LOG_DEFERRED 0 the NRF_LOG_RAW_INFO() call should act just like a printf() and block until all characters are sent, so there shouldn't be a timing/buffering issue.

    Maybe I should go try that SWO, see if it is more reliable...?  Are there any other reliability things you might suggest?  I'm using a 15 cm long USB cable and I've tried this on all the USB ports on my (Dell) laptop.

Related