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

Configuring SWO on nrf52

I'm trying to configure SWO properly, specifically to get the output in Eclipse. The following code is used to initialise the SWO.

const uint32_t current_config = static_cast<uint32_t>(NRF_CLOCK->TRACECONFIG
    & ~CLOCK_TRACECONFIG_TRACEPORTSPEED_Msk);
const uint32_t speed_config =
    static_cast<uint32_t>(CLOCK_TRACECONFIG_TRACEPORTSPEED_4MHz);
NRF_CLOCK->TRACECONFIG = current_config | speed_config;
ITM->TCR |= 1U;


I have a snippet that outputs a string to the SWO and I can read this correctly using this command

JLinkExe -if swd -device nrf52 -speed auto
connect
swoview 4000000

However, when I start the debug session in Eclipse, I'm not able to get the SWO output in the console. I can set breakpoints, step through code, etc. I'm attaching some screenshots from my configuration as well as the GDB Server output. Any help would be much appreciated!

macOS High Sierra (10.13.3)
Eclipse Neon.3 Release (4.6.3)

SEGGER J-Link GDB Server V6.22e Command Line Version

JLinkARM.dll V6.22e (DLL compiled Jan  8 2018 11:45:44)

Command line: -if swd -device nRF52832_xxAA -endian little -speed auto -port 2331 -swoport 2332 -telnetport 2333 -vd -ir -localhostonly 1 -singlerun -strict -timeout 0
-----GDB Server start settings-----
GDBInit file:                  none
GDB Server Listening port:     2331
SWO raw output listening port: 2332
Terminal I/O port:             2333
Accept remote connection:      localhost only
Generate logfile:              off
Verify download:               on
Init regs on start:            on
Silent mode:                   off
Single run mode:               on
Target connection timeout:     0 ms
------J-Link related settings------
J-Link Host interface:         USB
J-Link script:                 none
J-Link settings file:          none
------Target related settings------
Target device:                 nRF52832_xxAA
Target interface:              SWD
Target interface speed:        auto
Target endian:                 little

Connecting to J-Link...
J-Link is connected.
Firmware: J-Link OB-SAM3U128 V3 compiled Sep 21 2017 14:14:50
Hardware: V3.00
S/N: 483020034
Checking target voltage...
Target voltage: 3.30 V
Listening on TCP/IP port 2331
Connecting to target...Connected to target
Waiting for GDB connection...Connected to 127.0.0.1
Reading all registers
Read 4 bytes @ address 0x00000000 (Data = 0x20000400)
Read 2 bytes @ address 0x00000000 (Data = 0x0400)
Read 2 bytes @ address 0x00021128 (Data = 0xB508)
Reading all registers
Read 4 bytes @ address 0x00000000 (Data = 0x20000400)
Read 2 bytes @ address 0x00000000 (Data = 0x0400)
Received monitor command: reset
Resetting target
GDB closed TCP/IP connection
Connected to 127.0.0.1
Reading all registers
Read 2 bytes @ address 0x00021128 (Data = 0xB508)
Read 4 bytes @ address 0x000008E4 (Data = 0x47184B06)
Read 2 bytes @ address 0x000008E4 (Data = 0x4B06)
Received monitor command: speed 1000
Target interface speed set to 1000 kHz
Received monitor command: clrbp
Received monitor command: reset
Resetting target
Received monitor command: halt
Halting target CPU...
...Target halted (PC = 0x000008E4)
Received monitor command: regs
R0 = 00000000, R1 = 00000000, R2 = 00000000, R3 = 00000000
R4 = 00000000, R5 = 00000000, R6 = 00000000, R7 = 00000000
R8 = 00000000, R9 = 00000000, R10= 00000000, R11= 00000000
R12= 00000000, R13= 20000400, MSP= 20000400, PSP= 00000000
R14(LR) = FFFFFFFF, R15(PC) = 000008E4
XPSR 01000000, APSR 00000000, EPSR 01000000, IPSR 00000000
CFBP 00000000, CONTROL 00, FAULTMASK 00, BASEPRI 00, PRIMASK 00
Reading all registers
Read 4 bytes @ address 0x000008E4 (Data = 0x47184B06)
Read 2 bytes @ address 0x000008E4 (Data = 0x4B06)
Received monitor command: speed auto
Select auto target interface speed (2000 kHz)
Received monitor command: flash breakpoints 1
Flash breakpoints enabled
Received monitor command: semihosting enable
Semi-hosting enabled (Handle on BKPT)
Received monitor command: semihosting IOClient 3
Semihosting I/O set to TELNET and GDB Client
Received monitor command: SWO DisableTarget 0xFFFFFFFF
SWO disabled successfully.
Received monitor command: SWO EnableTarget 0 0 0xFF 0
SWO enabled successfully.
Read 2 bytes @ address 0x00021128 (Data = 0xB508)
Read 4 bytes @ address 0x000008E4 (Data = 0x47184B06)
Read 2 bytes @ address 0x000008E4 (Data = 0x4B06)
Downloading 9780 bytes @ address 0x0001F000 - Verified OK
Downloading 8 bytes @ address 0x00021634 - Verified OK
Downloading 128 bytes @ address 0x20002C38 - Verified OK
Writing register (PC = 0x0001F46C)
Read 2 bytes @ address 0x00021128 (Data = 0xB508)
Read 4 bytes @ address 0x0001F46C (Data = 0x2B004B15)
Read 2 bytes @ address 0x0001F46C (Data = 0x4B15)
Read 2 bytes @ address 0x00020878 (Data = 0xF7FF)
Read 2 bytes @ address 0x00020878 (Data = 0xF7FF)
Read 2 bytes @ address 0x00020878 (Data = 0xF7FF)
Read 2 bytes @ address 0x00020878 (Data = 0xF7FF)
Read 2 bytes @ address 0x00020878 (Data = 0xF7FF)
Read 2 bytes @ address 0x00020878 (Data = 0xF7FF)
Read 2 bytes @ address 0x00020878 (Data = 0xF7FF)
Received monitor command: clrbp
Received monitor command: reset
Resetting target
Received monitor command: halt
Halting target CPU...
...Target halted (PC = 0x000008E4)
Read 2 bytes @ address 0x00020878 (Data = 0xF7FF)
Read 2 bytes @ address 0x00020878 (Data = 0xF7FF)
Read 2 bytes @ address 0x00020878 (Data = 0xF7FF)
Received monitor command: regs
R0 = 00000000, R1 = 00000000, R2 = 00000000, R3 = 00000000
R4 = 00000000, R5 = 00000000, R6 = 00000000, R7 = 00000000
R8 = 00000000, R9 = 00000000, R10= 00000000, R11= 00000000
R12= 00000000, R13= 20000400, MSP= 20000400, PSP= 00000000
R14(LR) = FFFFFFFF, R15(PC) = 000008E4
XPSR 01000000, APSR 00000000, EPSR 01000000, IPSR 00000000
CFBP 00000000, CONTROL 00, FAULTMASK 00, BASEPRI 00, PRIMASK 00
Reading all registers
Read 4 bytes @ address 0x000008E4 (Data = 0x47184B06)
Read 2 bytes @ address 0x000008E4 (Data = 0x4B06)
Setting breakpoint @ address 0x00020878, Size = 2, BPHandle = 0x0001
Starting target CPU...
...Breakpoint reached @ address 0x00020878
Reading all registers
Read 4 bytes @ address 0x00020878 (Data = 0xFF5CF7FF)
Removing breakpoint @ address 0x00020878, Size = 2
Reading 64 bytes @ address 0x00020840
Reading 64 bytes @ address 0x00020880
Reading 64 bytes @ address 0x000208C0
Reading 64 bytes @ address 0x00020900
Reading 64 bytes @ address 0x00020940
Reading 64 bytes @ address 0x00020980
Reading 64 bytes @ address 0x000209C0
Reading 64 bytes @ address 0x2000FFC0
Read 4 bytes @ address 0x0001F4BA (Data = 0xFE4FF001)
Read 2 bytes @ address 0x0001F46C (Data = 0x4B15)
Read 4 bytes @ address 0x0001F4C4 (Data = 0x20010000)
Read 2 bytes @ address 0x0001F46E (Data = 0x2B00)
Read 2 bytes @ address 0x0001F470 (Data = 0xBF08)
Read 2 bytes @ address 0x0001F472 (Data = 0x4B13)
Read 4 bytes @ address 0x0001F4C2 (Data = 0x00000008)
Read 2 bytes @ address 0x0001F474 (Data = 0x469D)
Read 2 bytes @ address 0x0001F476 (Data = 0xF5A3)
Read 2 bytes @ address 0x0001F478 (Data = 0x3A80)
Read 2 bytes @ address 0x0001F47A (Data = 0x2100)
Read 2 bytes @ address 0x0001F47C (Data = 0x468B)
Read 2 bytes @ address 0x0001F47E (Data = 0x460F)
Read 2 bytes @ address 0x0001F480 (Data = 0x4813)
Read 4 bytes @ address 0x0001F4D0 (Data = 0x00018000)
Read 2 bytes @ address 0x0001F482 (Data = 0x4A14)
Read 4 bytes @ address 0x0001F4D6 (Data = 0x00000001)
Read 2 bytes @ address 0x0001F484 (Data = 0x1A12)
Read 2 bytes @ address 0x0001F486 (Data = 0xF001)
Read 2 bytes @ address 0x0001F488 (Data = 0xFEA9)
Reading 64 bytes @ address 0x2000FF00
Reading 64 bytes @ address 0x2000FF40
Reading 64 bytes @ address 0x2000FF80
Read 4 bytes @ address 0x2000FF20 (Data = 0x00021500)
Read 4 bytes @ address 0x000214F8 (Data = 0x00000000)
Read 4 bytes @ address 0x2000FF3C (Data = 0x00021500)
Read 4 bytes @ address 0x000214F8 (Data = 0x00000000)
Read 4 bytes @ address 0x2000FF58 (Data = 0x00021500)
Read 4 bytes @ address 0x000214F8 (Data = 0x00000000)
Read 4 bytes @ address 0x2000FF74 (Data = 0x00021424)
Read 4 bytes @ address 0x0002141C (Data = 0x00000000)
Read 4 bytes @ address 0x2000FF84 (Data = 0x000213D4)
Read 4 bytes @ address 0x000213CC (Data = 0x00000000)
Read 4 bytes @ address 0x2000FF90 (Data = 0x000215D0)
Read 4 bytes @ address 0x000215C8 (Data = 0x00000000)
Read 4 bytes @ address 0x2000FFD8 (Data = 0x0000FFFF)
Read 4 bytes @ address 0x2000FFE4 (Data = 0x0002080F)
Read 4 bytes @ address 0x2000FF0C (Data = 0x000214CC)
Read 4 bytes @ address 0x000214C4 (Data = 0x00000000)

SEGGER J-Link GDB Server V6.22e - Terminal output channel

  • Hello,

    I have not tested this on eclipse, so I don't know how this startup GUI is set up. Maybe the "enable SWO" checkbox does this, but I am not sure. Could you try to add "ENABLE_SWO" to your preprocessor defines?

    I have not done much c++, but this code in C (thanks to from this case) should print data on the SWO line after defining ENABLE_SWO.

    #include <stdbool.h>
    #include <stdint.h>
    
    #include "nrf.h"
    #include "nordic_common.h"
    #include "boards.h"
    #include "nrf_delay.h"
    
    /**
     * @brief Function for application main entry.
     */
    int main(void)
    {
        // step 2
        NRF_CLOCK->TRACECONFIG = (NRF_CLOCK->TRACECONFIG & ~CLOCK_TRACECONFIG_TRACEPORTSPEED_Msk) |
        (CLOCK_TRACECONFIG_TRACEPORTSPEED_4MHz << CLOCK_TRACECONFIG_TRACEPORTSPEED_Pos);
        
        // step 3
        ITM->TCR |= 1;
        ITM->TER |= 1;
        uint8_t c = 65;
        
        while (true)
        {
            nrf_delay_ms(100);
            // step 4   
            ITM_SendChar(c);
            if( c >= 90){
                c = 65;
            }else{
                c++;
            }
        }
    }

    Can you test it and see if you get any output? I tested it using the same JLink command that you used: 

    JLinkExe -if swd -device nrf52 -speed auto
    connect
    swoview 4000000

    Do you use a DK, or is it a custom device?

    Best regards,

    Edvin

  • Hi Edvin,

    Thanks for your reply! The code I'm using is a C++ adaption from the excellent post by . And it works properly, if I run the command I get SWO output, but only though JLinkExe. I want it to launch as part of the Eclipse debuggning session, which (I believe) doesn't use JLinkExe, but a telnet client to GDB server.

    I can of course run this in a terminal, but I get the same output there as in Eclipse. (Last code snippet in the original post) I'm pasting what I believe to be the equivalent terminal commands below. Its three separate processes - a GDB server, a GDB client (to issue SWO command) and a telnet client that should receive the SWO output from the GDB server.

    JLinkGDBServer -if swd -device nrf52832_XXAA
    
    arm-none-eabi-gdb
    (gbd) mon swo start 0 0
    
    telnet localhost 2333

    I'm using both a development kit from Laird (DVK-BL652_1.0) and a stand-alone BL652 module (also from Laird) with a Segger JLink.

  • Oh! Sorry. I seem to misunderstand your question. So you do get the swo output with your project if you use "JLink.exe" and "swoview 4000000", is that correct?

  • In the screenshots above, you have left the CPU freq and SWO freq fields empty, can you fill those values and see if it works?

    SWO freq is the 4MHz (which is what is passed in to the swoview as well - swoview 4000000)

    CPU freq - what ever is the freq you are running your cpu at.

Related