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

C++ cout with ble_app_uart example

Hi,

I'm integrating some c++ code using ble_app_uart example as base. The code has some cout << "text"; kind of outputs that seem to go to uart by default configuration. What would I need to change to get the output to RTT or if not possible, ignored altogether?

Edit: 

Ok, I removed the retarget.c from Makefile sources and it no longer inputs to uart. Still no luck getting it to RTT.

  • Have you enabled RTT logging correctly? See this link: https://devzone.nordicsemi.com/f/nordic-q-a/47730/getting-rtt-logging-to-work-in-ses. Remember to set NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED to 0

    If you have done that, I think you can include these files:

    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"

    Then initialize logging and use the function NRF_LOG_INFO() from "nrf_log.h" (which has extern "C" added at the top and makes its functions callable from C++ code) to print the RTT logs. 

    Check out the ble_app_uart example, where RTT logging should work out of the box, or almost, you have to set NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED to 0.

    I have not worked much with C++, and have not tested this myself, so it may be that I have misunderstood something or missed some steps, but hopefully, this works.

    Best regards,

    Simon

Related