5 years, 2 months ago.

Redirecting printf statements via JLink instead of the default USBTX pin?

printf statements in MBED-OS by default uses the USBTX pins, however the custom board we have doesn't use the USBTX and USBRX pins, however the board has JLink headers that we program the NRF52840. So I was wondering if there is a way to re-direct the printf o/p to use the JLink headers so this can be potentially viewed on JLinkRTTViewer application or any other means?

I am attaching the image of the schematic of the Debugger (JLink) that we have on our custom board.

/media/uploads/yogeshk/debuggerport-jlink-.png

Thanks, Yogesh

Question relating to:

The nRF52840 Development Kit is a single-board development kit for Bluetooth low energy, ANT, 802.15.4, and 2.4 GHz proprietary applications using the nRF52840 SoC.

2 Answers

5 years, 1 month ago.

Thanks Wim, for your suggestion and I had logged this issue on the mbed-os github issues and I just had to add this piece of code in main.cpp and I can view the printf statements with Seggers JLinkSWOViewer.exe.

SWO Printf debug

#include "mbed.h"
#include "platform/mbed_retarget.h"
#include "drivers/SerialWireOutput.h"

namespace mbed
{
    FileHandle *mbed_target_override_console(int)
    {
        static SerialWireOutput swo;
        return &swo;
    }
}

Thanks, Ajay

5 years, 2 months ago.

The nRF52840 is an ARM Cortex M4, so it supports the Single Wire Output (SWO) that can be used for debug messages. Try my SWO Lib and you should be able to use printf like calls. Note that I have not tested this on the nRF52840 as I dont have one available.