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

Rerouting printf() to UART

Hi,

Currently our system is using printf() to print some debug messages to the Segger debug terminal.
Now we would like to reroute these messages to a UART port.

We are already using 1 UART for communication with chip on the board. We would like to use the other UART for the debug messages.

In our sdk_config.h we changed NRF_LOG_BACKEND_RTT_ENABLED from 1 to 0, and NRF_LOG_BACKEND_UART_ENABLED from 0 to 1.
Furthermore, we set NRF_LOG_BACKEND_UART_TX_PIN. For now, we left NRF_LOG_BACKEND_UART_BAUDRATE at 30801920

Unfortunately, after these changes the UART that we were previously already using successfully is no longer working.
This is coming into a conditional breakpoint:

    app_uart_comm_params_t const uart1_settings =
    {
        .rx_pin_no    = UART1_TX_PIN,
        .tx_pin_no    = UART1_RX_PIN,
        .rts_pin_no   = RTS_PIN_NUMBER,
        .cts_pin_no   = CTS_PIN_NUMBER,
        .flow_control = APP_UART_FLOW_CONTROL_DISABLED,
        .use_parity   = false,
        .baud_rate    = UART_BAUDRATE_BAUDRATE_Baud115200
    };
    APP_UART_FIFO_INIT(&uart1_settings,
                       UART_RX_BUF_SIZE,
                       UART_TX_BUF_SIZE,
                       uart1_event_handle,
                       APP_IRQ_PRIORITY_LOWEST,
                       err_code);
    APP_ERROR_CHECK(err_code);       // check if UART is setup without errors

What are we missing?

Parents Reply
  • The instance is 0. Instance 1 is used by our communication chip, after the suggested changes, so indeed we need retarget on 0.

    In retarget.c I see that app_uart_put is used, but that function is used to send data to our modem. 
    We have also tried replacing app_uart_put with app_uart_put2, which is our function to transmit to the other uart fifo, but this suddenly yields garbage data (we are using the baudrate from the SDK config: 115200). Furthermore, how is this instance then initialized?

    If we disable retarget, we see printf() in the debug terminal and NRF log in the debug UART. 
    When enabling retarget so that printf also goes to the debug UART, we get the garbage data (also NRF LOG is no longer showing)

Children
Related