Logging via SWO

Hi,

I am trying to configure SWO logging in a sample project based on zephyr/samples/hello_world (source and config at the end).

I run this application on two targets: nRF54L15-DK and nRF52-DK.

On nRF54L15-DK: I cannot see any logs when using SEGGER J-Link SWO Viewer but I can see the logs via cortex-debug extension for vscode.

On nRF52-DK: I can see logs when using SEGGER J-Link SWO Viewer but I cannot see any logs via cortex-debug extension for vscode.

Do you know why it works that way?

Another question is about the SWO frequency. In case of nRF54L15-DK and vscode I need to configure the SWO receiver to half of the frequency configured in the application. In case of nRF52-DK and SEGGER J-Link SWO Viewer I can choose whatever frequency I want.

How to properly set the SWO frequency for nRF54L15?

Application code:

 

#include <zephyr/kernel.h>
#include <zephyr/sys/printk.h>

int main(void)
{
	while (1) {
		printk("Hello World! %s\n", CONFIG_BOARD_TARGET);
		k_msleep(1000);
	}

	return 0;
}

prj.conf file:

CONFIG_LOG=y
CONFIG_LOG_MODE_MINIMAL=n
CONFIG_LOG_MODE_IMMEDIATE=y
CONFIG_LOG_BACKEND_SWO=y
CONFIG_LOG_BACKEND_SWO_FREQ_HZ=2000000

launch.json file for vscode:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "hello nrf54",
            "cwd": "${workspaceFolder}",
            "executable": "${workspaceFolder}/build/merged.hex",
            "symbolFiles": [
                "${workspaceFolder}/build/hello_world/zephyr/zephyr.elf",
            ],
            "request": "launch",
            "type": "cortex-debug",
            "runToEntryPoint": "main",
            "servertype": "jlink",
            "device": "NRF54L15_M33",
            "interface": "swd",
            "showDevDebugOutput": "raw",
            "swoConfig": {
                "enabled": true,
                "source": "probe",
                "swoFrequency": 1000000,
                "cpuFrequency": 128000000,
                "decoders": [
                    {
                        "port": 0,
                        "type": "console",
                        "label": "hello",
                        "encoding":"ascii"
                    }
                ]
            },
            "ipAddress": "192.168.100.20:19020",
        },
        {
            "name": "hello nrf52",
            "cwd": "${workspaceFolder}",
            "executable": "${workspaceFolder}/build/merged.hex",
            "symbolFiles": [
                "${workspaceFolder}/build/hello_world/zephyr/zephyr.elf",
            ],
            "request": "launch",
            "type": "cortex-debug",
            "runToEntryPoint": "main",
            "servertype": "jlink",
            "device": "NRF52832_xxAA",
            "interface": "swd",
            "showDevDebugOutput": "raw",
            "swoConfig": {
                "enabled": true,
                "source": "probe",
                "swoFrequency": 1000000,
                "cpuFrequency": 64000000,
                "decoders": [
                    {
                        "port": 0,
                        "type": "console",
                        "label": "hello",
                        "encoding":"ascii"
                    }
                ]
            },
            "ipAddress": "192.168.100.20:19020",
        },
    ]
}

Cheers,
Damian

  • Hi Damian,

    You need to enable SWO control in the board configurator:

    Please note that this is only supported on nRF54L15 DK v1.0.0 and newer.

    Best regards,
    Marte

  • Hi Marte,

    Unfortunately, the version of my DK is 0.9.1.

    Do you know how to enable SWO on a custom board with nRF54L10 SoC? I am asking about nRF54L10 since in our project we use our custom board with this SoC and we have exactly the same issue with SWO as described above for nRF54L15-DK.

    Best Regards,

    Damian

  • Hi Damian,

    The board configurator tool configures the board controller (interface MCU) on the DK itself, it does not configure the nRF54L chip. This means what you want to replicate in firmware is the trace port enablement on the nRF54L chip itself, not the DK board controller configuration.

    For the nRF54L, the following sequence is required to enable SWO support:

    /* Trace configuration */
    #define TRACE_PORT                  NRF_P2_S
    #define TRACE_TRACECLK_PIN          (6ul)
    #define TRACE_TRACEDATA0_PIN        (7ul)
    #define TRACE_TRACEDATA1_PIN        (8ul)
    #define TRACE_TRACEDATA2_PIN        (9ul)
    #define TRACE_TRACEDATA3_PIN        (10ul)
    #define TRACE_PIN_CONFIG            ((GPIO_PIN_CNF_DRIVE0_E0 << GPIO_PIN_CNF_DRIVE0_Pos) \
    | (GPIO_PIN_CNF_DRIVE1_E1 << GPIO_PIN_CNF_DRIVE1_Pos) \
    | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos))
    
    #define TRACE_PIN_CLEAR             (~(GPIO_PIN_CNF_CTRLSEL_Msk | GPIO_PIN_CNF_DRIVE0_Msk | GPIO_PIN_CNF_DRIVE1_Msk | GPIO_PIN_CNF_DIR_Msk))
    /* End Trace configuration */
    
    
    // Enable trace and debug
    NRF_TAD_S->ENABLE = TAD_ENABLE_ENABLE_Msk;
    
    // Configure trace port pads
    TRACE_PORT->PIN_CNF[TRACE_TRACECLK_PIN] &= TRACE_PIN_CLEAR;
    TRACE_PORT->PIN_CNF[TRACE_TRACEDATA0_PIN] &= TRACE_PIN_CLEAR;
    
    TRACE_PORT->PIN_CNF[TRACE_TRACECLK_PIN] |= TRACE_PIN_CONFIG;
    TRACE_PORT->PIN_CNF[TRACE_TRACEDATA0_PIN] |= TRACE_PIN_CONFIG;
    
    // Configure trace port speed
    NRF_TAD_S->TRACEPORTSPEED = TAD_TRACEPORTSPEED_TRACEPORTSPEED_DIV2;

    However, this should automatically be set when you have SWO enabled with CONFIG_LOG=y and CONFIG_LOG_BACKEND_SWO=y as you can see from these files:

    https://github.com/nrfconnect/sdk-zephyr/blob/main/modules/hal_nordic/nrfx/CMakeLists.txt#L116

    https://github.com/nordicsemi/nrfx/blob/master/bsp/stable/mdk/system_nrf54l.c#L260-L278

    Since this is not working in your case, can you try manually enabling SWO using the code above? If this does not work, please let me know.

    Best regards,
    Marte

  • Hi Marte,

    Thanks for clarifying how the board configurator works and what it does.

    I have added the above code snippet but it did not help. I still cannot see the logs in SEGGER J-Link SWO Viewer.

    Best Regards,

    Damian

  • Hi Damian,

    What debugger are you using? The debugger must be SWO capable to work.

    Is there a specific reason for using SWO instead of RTT?

    Best regards,
    Marte

Related