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

How to send log messages to RTT and stdio to UART in mesh sdk?

I am experimenting with light_switch server example from mesh SDK 2.1.1 . I want to add UART functionality to this example. 

I referred to the ble_app_uart example from sdk15.0.0 and I have successfully merged the UART part into light_switch server example. My code get compiled and I am able to flash it to my nrf52 dev board but printf() and __LOG both are send to RTT.

I want to push the debug logs to RTT and printf() to UART. I know it can be done as it is already implemented in the ble_app_uart example but I dont know what is needed to achieve this?

Parents
  • I know it can be done as it is already implemented in the ble_app_uart example but I dont know what is needed to achieve this?

    So look at how that example does it - and just do that!

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    /**@brief Function for handling the data from the Nordic UART Service.
    *
    * @details This function will process the data received from the Nordic UART BLE Service and send
    * it to the UART module.
    *
    * @param[in] p_evt Nordic UART Service event.
    */
    /**@snippet [Handling the data received over BLE] */
    static void nus_data_handler(ble_nus_evt_t * p_evt)
    {
    if (p_evt->type == BLE_NUS_EVT_RX_DATA)
    {
    uint32_t err_code;
    NRF_LOG_DEBUG("Received data from BLE NUS. Writing data on UART.");
    NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length);
    for (uint32_t i = 0; i < p_evt->params.rx_data.length; i++)
    {
    do
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • I dont require the NUS service... I am not receiving data from BLE. All I want is the printf() should be sent to UART and the NRF_LOG_INFO() should be sent to RTT.

    Fullscreen
    1
    2
    3
    4
    // Start execution.
    printf("\r\nUART started.\r\n");
    NRF_LOG_INFO("Debug logging for UART over RTT started.");
    advertising_start();
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    In mesh examples NRF_LOG_INFO is not used, instead __LOG() is used. In my case printf() and __LOG() both are appearing on RTT. Read the title of this question again, I want "stdio" to be redirected to UART. In the code that you have posted, where is printf() being used?

  • I didn't suggest that you use the NUS service!

    I said just look at how the ble_app_uart example does its output to the UART - and do the same!

  • I have gone through ble_app_uart code there are two apis that it uses to output code to UART. printf() and app_uart_put(). I have no issue with app_uart_put(), I mean using app_uart_put() I am able to send data to UART. But not with printf(). So my question is what should be done to achieve this? I am not able to figure it out looking at the code of ble_app_uart.

    It would be good if you could point me to that specific code which sends printf() to uart in ble_app_uart example.

  • What I am suggesting is to just use app_uart_put().

    That's what I would do. It seems like the simplest way forward ...

  • Yes I agree its the simplest way but then I have to write stdio functions myself for sending string and receiving string because app_uart_put() will send only one character at a time.

    So that is the reason why I had specifically mentioned "stdio" in my question title. Let me know if you have a solution for this.

  • Hi Prasad.

    If you want to use printf(), you can look at this answer.

    Use following defines in sdk_config.h:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    #define NRF_LOG_BACKEND_RTT_ENABLED 0
    #define APP_UART_ENABLED 1
    #define APP_UART_DRIVER_INSTANCE 0
    #define RETARGET_ENABLED 1
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    And set up the app_uart library, which I guess you already did.

    #define RETARGET_ENABLED 1 enables retargeting of the STDIO functions.

    - Andreas

Reply
  • Hi Prasad.

    If you want to use printf(), you can look at this answer.

    Use following defines in sdk_config.h:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    #define NRF_LOG_BACKEND_RTT_ENABLED 0
    #define APP_UART_ENABLED 1
    #define APP_UART_DRIVER_INSTANCE 0
    #define RETARGET_ENABLED 1
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    And set up the app_uart library, which I guess you already did.

    #define RETARGET_ENABLED 1 enables retargeting of the STDIO functions.

    - Andreas

Children