<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How to send log messages to RTT and stdio to UART in mesh sdk?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/39154/how-to-send-log-messages-to-rtt-and-stdio-to-uart-in-mesh-sdk</link><description>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</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 04 Oct 2018 06:38:06 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/39154/how-to-send-log-messages-to-rtt-and-stdio-to-uart-in-mesh-sdk" /><item><title>RE: How to send log messages to RTT and stdio to UART in mesh sdk?</title><link>https://devzone.nordicsemi.com/thread/151570?ContentTypeID=1</link><pubDate>Thu, 04 Oct 2018 06:38:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9d1f0990-ee54-4aaa-8f48-6a9979c2c7e6</guid><dc:creator>Prasad</dc:creator><description>&lt;p&gt;Thanks &lt;a href="https://devzone.nordicsemi.com/members/andreasf"&gt;AndreasF&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;I am able to get it to work, I have already replied to this question. Thanks for elaborating the answer.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send log messages to RTT and stdio to UART in mesh sdk?</title><link>https://devzone.nordicsemi.com/thread/151569?ContentTypeID=1</link><pubDate>Thu, 04 Oct 2018 06:29:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:92338416-ff50-46fe-8d0f-a17496e23155</guid><dc:creator>AndreasF</dc:creator><description>&lt;p&gt;Hi Prasad.&lt;/p&gt;
&lt;p&gt;If you want to use &lt;strong&gt;printf()&lt;/strong&gt;, you can look at this &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/29921/printf-output-via-uart"&gt;answer&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Use following defines in &lt;strong&gt;sdk_config.h&lt;/strong&gt;:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define NRF_LOG_BACKEND_RTT_ENABLED 0

#define APP_UART_ENABLED 1

#define APP_UART_DRIVER_INSTANCE 0

#define RETARGET_ENABLED 1&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And set up the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.0.0/group__app__uart.html?cp=4_0_1_6_11_57"&gt;app_uart library,&lt;/a&gt; which I guess you already did.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;#define RETARGET_ENABLED 1&lt;/strong&gt; enables &lt;a href="http://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v15.0.0%2Fgroup__retarget__config.html&amp;amp;cp=4_0_1_6_11_66_0"&gt;retargeting of the STDIO functions&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;- Andreas&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send log messages to RTT and stdio to UART in mesh sdk?</title><link>https://devzone.nordicsemi.com/thread/151565?ContentTypeID=1</link><pubDate>Thu, 04 Oct 2018 05:59:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3f7d9698-c846-4630-a68d-8165a0c460fe</guid><dc:creator>Prasad</dc:creator><description>&lt;p&gt;Finally I got it to work the way I wanted!!&lt;/p&gt;
&lt;p&gt;You have to include ../components/libraries/uart/retarget.c in your project and define the macro&amp;nbsp;RETARGET_ENABLED = 1(I defined it project settings)&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/29921/printf-output-via-uart"&gt;This devzone question &lt;/a&gt;was helpful.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send log messages to RTT and stdio to UART in mesh sdk?</title><link>https://devzone.nordicsemi.com/thread/151528?ContentTypeID=1</link><pubDate>Wed, 03 Oct 2018 15:32:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5e72dc20-1c4c-4f40-9de9-f9196eb8f7b4</guid><dc:creator>Prasad</dc:creator><description>&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;So that is the reason why I had specifically mentioned &amp;quot;stdio&amp;quot; in my question title. Let me know if you have a solution for this.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send log messages to RTT and stdio to UART in mesh sdk?</title><link>https://devzone.nordicsemi.com/thread/151526?ContentTypeID=1</link><pubDate>Wed, 03 Oct 2018 15:23:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5bc64833-bb72-4600-b152-1e13c3269757</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;What I am suggesting is to just use&amp;nbsp;&lt;span&gt;app_uart_put().&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;That&amp;#39;s what I would do. It seems like the simplest way forward ...&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send log messages to RTT and stdio to UART in mesh sdk?</title><link>https://devzone.nordicsemi.com/thread/151524?ContentTypeID=1</link><pubDate>Wed, 03 Oct 2018 15:21:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e5d7678b-c217-4d87-a2d2-6b59b435e2fe</guid><dc:creator>Prasad</dc:creator><description>&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;It would be good if you could point me to that specific code which sends printf() to uart in ble_app_uart example.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send log messages to RTT and stdio to UART in mesh sdk?</title><link>https://devzone.nordicsemi.com/thread/151522?ContentTypeID=1</link><pubDate>Wed, 03 Oct 2018 15:12:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:783195f3-71e8-446b-b443-0d939188672d</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;I didn&amp;#39;t suggest that you use the NUS service!&lt;/p&gt;
&lt;p&gt;I said just look at how the&amp;nbsp;&lt;span&gt;ble_app_uart example does its output to the UART - and do the same!&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send log messages to RTT and stdio to UART in mesh sdk?</title><link>https://devzone.nordicsemi.com/thread/151516?ContentTypeID=1</link><pubDate>Wed, 03 Oct 2018 14:56:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0b5fb7a4-60e4-411a-8dca-37c2b9e21945</guid><dc:creator>Prasad</dc:creator><description>&lt;p&gt;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&amp;nbsp;NRF_LOG_INFO() should be sent to RTT.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;
    // Start execution.
    printf(&amp;quot;\r\nUART started.\r\n&amp;quot;);
    NRF_LOG_INFO(&amp;quot;Debug logging for UART over RTT started.&amp;quot;);
    advertising_start();

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;In mesh examples NRF_LOG_INFO is not used, instead __LOG() is used.&amp;nbsp;In my case printf() and&amp;nbsp;__LOG() both are appearing on RTT. Read the title of this question&amp;nbsp;again, I want &amp;quot;stdio&amp;quot; to be redirected to UART. In the code that you have posted,&amp;nbsp;where is printf() being used?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to send log messages to RTT and stdio to UART in mesh sdk?</title><link>https://devzone.nordicsemi.com/thread/151503?ContentTypeID=1</link><pubDate>Wed, 03 Oct 2018 14:17:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a305ea59-727b-4f58-a4b1-a7f20a827369</guid><dc:creator>awneil</dc:creator><description>[quote userid="18390" url="~/f/nordic-q-a/39154/how-to-send-log-messages-to-rtt-and-stdio-to-uart-in-mesh-sdk"] 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?[/quote]
&lt;p&gt;So look at how that example does it - and just do that!&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**@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-&amp;gt;type == BLE_NUS_EVT_RX_DATA)
    {
        uint32_t err_code;

        NRF_LOG_DEBUG(&amp;quot;Received data from BLE NUS. Writing data on UART.&amp;quot;);
        NRF_LOG_HEXDUMP_DEBUG(p_evt-&amp;gt;params.rx_data.p_data, p_evt-&amp;gt;params.rx_data.length);

        for (uint32_t i = 0; i &amp;lt; p_evt-&amp;gt;params.rx_data.length; i++)
        {
            do
            {
                err_code = app_uart_put(p_evt-&amp;gt;params.rx_data.p_data[i]);
                if ((err_code != NRF_SUCCESS) &amp;amp;&amp;amp; (err_code != NRF_ERROR_BUSY))
                {
                    NRF_LOG_ERROR(&amp;quot;Failed receiving NUS message. Error 0x%x. &amp;quot;, err_code);
                    APP_ERROR_CHECK(err_code);
                }
            } while (err_code == NRF_ERROR_BUSY);
        }
        if (p_evt-&amp;gt;params.rx_data.p_data[p_evt-&amp;gt;params.rx_data.length - 1] == &amp;#39;\r&amp;#39;)
        {
            while (app_uart_put(&amp;#39;\n&amp;#39;) == NRF_ERROR_BUSY);
        }
    }

}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>