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

SDK14 nrf_log vs UART vs printf

Hello

I wanted to ask what is the correct way to use NRF_LOG_* functions along with printf (with RETARGET_ENABLED 1) and normal UART initialized with standard:

const app_uart_comm_params_t comm_params =
{
    RX_PIN_NUMBER,
    TX_PIN_NUMBER,
    RTS_PIN_NUMBER,
    CTS_PIN_NUMBER,
    APP_UART_FLOW_CONTROL_ENABLED,
    false,
    UART_BAUDRATE_BAUDRATE_Baud115200
};

  APP_UART_FIFO_INIT(&comm_params,
                   UART_RX_BUF_SIZE,
                   UART_TX_BUF_SIZE,
                   uart_event_handle,
                   APP_IRQ_PRIORITY_LOWEST,
                   err_code);

  APP_ERROR_CHECK(err_code);

When I enable UART loger backend the application fails on UART init with an error <error> uart: Init failed. id:2 in wrong state which makes sense as NRF_LOG_INIT already takes over due to #define NRF_LOG_BACKEND_UART_ENABLED 1 setting.

When I disable NRF_LOG_BACKEND_UART_ENABLED RX on UART works but nothing is printed from printf even though RETARGET_ENABLED is enabled.

My questions to the situation encotered are:

  1. I couldn't find a resource on using and properly configuring all the backends, maybe I've missed some chapter in the infocenter?

  2. Can the application and NRF_LOG use different instances of UART but still share the same pins? This would come with the assumption that NRF_LOG only transmits and doesn't receive.

Related