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

nRF52832 custom boad logging

Hi!

we're just finishing the layout for a custom nRF52832 board. On the custom board we have a connector for SWDIO and SWCLK to flash the firmware. Can we use theese 2 pins also for logging, or do i also need PIN 6 for UART logging? What pins are needed for RTT logging?

Kind regards

Parents
  • Hi hannes,

    yes, using only SWDIO and SWCLK will work just fine. If you have programmed the custom board already your circuitry should be already set up.

    In software, all you need is enable the RTT logging backend in the SDK like follows. In the app_config.h or local sdk_config.h:

    #define NRF_LOG_ENABLED 1
    #define NRF_LOG_BACKEND_RTT_ENABLED 1
    #define NRF_LOG_USES_RTT 1

    In the Makefile make sure RTT library is included:

    SRC_FILES+=    $(SDK_ROOT)/components/libraries/log/src/nrf_log_backend_rtt.c
    SRC_FILES+=    $(SDK_ROOT)/external/segger_rtt/SEGGER_RTT.c
    SRC_FILES+=    $(SDK_ROOT)/external/segger_rtt/SEGGER_RTT_printf.c
    INC_FOLDERS+=  $(SDK_ROOT)/external/segger_rtt

    From now on, NRF_LOG_INFO() and other log macros will output to the RTT buffers from where it will be possible to read using an RTT viewer.

    For example, to use the nRF52 DK as debugger, it will be required to download the J-Link software bundle (may also be available with nRF command line tools) and which is very likely installed if you have programmed the custom board already. Among the J-Link library the bundle contains the JLinkExe and the JLinkRTTClient utilities. In one terminal window, please connect the JLink Commander to the debugger with the command like this:

    $ JLinkExe -device NRF52 -speed 4000 -if SWD -AutoConnect 1

    In another terminal window, connect RTT Client to the JLink Commander like this:

    $ JLinkRTTClient

    Now, the logs should appear in the RTT Client.

    Please also note, if the code use printf() it may be required to tell compiler explicitly that the RTT version should be used. For example, it might be defined like this:

    #include <SEGGER_RTT.h>
    #define printf(...) SEGGER_RTT_printf(0, __VA_ARGS__)

    For more insight on how the RTT works is please refer to the Real-Time Transfer page on the Segger website.

    Best regards,
    Mishka

    P.S. I'd leave a couple of GPIO test points on the PCB anyway - they could be very handy if something will occasionally go wrong and it might be needed to connect a LED, another I2C bus, or use them for RX/TX.

  • Thanks Mishka for your detailed reply. Can you also tell me which pins are needed for UART logging on the custom board? Just TX (Pin 6) and GND?

Reply Children
  • Yep, it should also work. The UART backend uses the same UART driver with RX, CTS, RTS pins explicitly disabled. In the sdk_config.h / app_config.h you have to have something like that:

    #define NRF_LOG_ENABLED 1
    #define NRF_LOG_BACKEND_UART_ENABLED 1
    #define NRF_LOG_BACKEND_UART_TX_PIN 6

    But for printf() to work you might need to add components/libraries/uart/retarget.c to your firmware, so system calls like putchar(), getchar(), read(), and write() will be redirected to UART. Again, per your SDK config:

    #define APP_UART_ENABLED 1
    #define RETARGET_ENABLED 1

    Mishka

  • Thanks - so I only need to connect Pin 6 and GND of the custom board with an "USB serial TTL cable" to the PC?

  • Seems as simple as that. Moreover, you may use any free GPIO pin closest to the UART connector on your PCB, not limiting to the pin 6 only. It's a good practice to create your own board definitions file and declare the TX_PIN_NUMBER and other stuff (like LEDs and buttons) there. For examples please see sdk/components/boards/ header files.

    But please also note, despite it may be not so critical for TX + GND only, some cables have 5V logic level which is way above allowed 3.6V for the nRF52832. It might be good idea to check that before connecting the cable. Another thing to outline is that this configuration suggest no hardware, no software flow control. Indeed, there is no CTS/RTS, as well as no ability to send XON/XOFF. In some cases this may screw up the terminal.

    Finally, the nRF52 DK offers full UART pinout on pins P0.5 through P0.8. The UART example may be used to test the cable connection. After setting it up with the DK, the code may be used to test the custom board.

  • Thanks - Just tested both ways.
    RTT Logging via SWDIO/SWCLK/GND and UART Logging via TX_PIN (6 in my case) and GND.
    Everything works fine as expected. Thanks for your support!

Related