<?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>libuarte sometimes print garbled</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/68745/libuarte-sometimes-print-garbled</link><description>Hello, 
 I&amp;#39;m implementing libuarte with ble_app_multilink. But receiver side receive gibberish like below. 
 
 
 It looks like RTT message is printed to serial port. But I have already disabled NRF_LOG_BACKEND_UART_ENABLED. 
 Here is my sdk_config file</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 26 Jan 2021 06:36:59 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/68745/libuarte-sometimes-print-garbled" /><item><title>RE: libuarte sometimes print garbled</title><link>https://devzone.nordicsemi.com/thread/291169?ContentTypeID=1</link><pubDate>Tue, 26 Jan 2021 06:36:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:db15cb09-b4ad-4bc0-ac39-9a131a9f837e</guid><dc:creator>leo.lau</dc:creator><description>&lt;p&gt;Thank you for your suggestion.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: libuarte sometimes print garbled</title><link>https://devzone.nordicsemi.com/thread/285417?ContentTypeID=1</link><pubDate>Wed, 16 Dec 2020 15:53:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:090248fa-024e-4b0f-98d7-b4a5736294ad</guid><dc:creator>Krzysztof Chruscinski</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;unfortunately, libuarte is currently not thread safe. It is returning NRF_ERROR_BUSY when transfer is in progress but setting busy state is done without protection so there is a chance for race. It can be easily fixed in `nrf_libuarte_drv.c`&lt;/p&gt;
&lt;p&gt;In the beginning of nrf_libuarte_drv_tx() function there is&lt;/p&gt;
&lt;p&gt;&lt;br /&gt; &lt;pre class="ui-code" data-mode="c_cpp"&gt;
    if (p_libuarte-&amp;gt;ctrl_blk-&amp;gt;p_tx)
    {
        return NRF_ERROR_BUSY;
    }
    p_libuarte-&amp;gt;ctrl_blk-&amp;gt;p_tx = p_data;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;That can be replaced with:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;if (!nrf_atomic_u32_cmp_exch(&amp;amp;p_libuarte-&amp;gt;ctrl_blk-&amp;gt;p_tx, NULL, p_data)) {
  return NRF_ERROR_BUSY;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Code above is using exclusive access to safely set p_tx which is used for determining if driver is busy. That will make it thread safe.&lt;/p&gt;
&lt;p&gt;Regarding nrf_queue, it is thread safe.&lt;/p&gt;
&lt;p&gt;If you don&amp;#39;t want to modify libuarte code you would need to wrap tx call with critical region.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Krzysztof&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: libuarte sometimes print garbled</title><link>https://devzone.nordicsemi.com/thread/281947?ContentTypeID=1</link><pubDate>Thu, 26 Nov 2020 08:12:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e2b03dc3-0ac5-4796-bcf0-980928775243</guid><dc:creator>leo.lau</dc:creator><description>&lt;p&gt;Thank you for your response.&amp;nbsp;I have&amp;nbsp;solved the problem that there is a bug in my code.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m sorry to bother you.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;On the other hand, I&lt;span&gt;&amp;nbsp;have few questions about libuarte and ble_app_multilink.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;1. Is libuarte thread-safe? What happens if two peripheral&amp;#39;s events&amp;nbsp;calling nrf_libuarte_async_tx.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;2. Is nrf_queue&amp;nbsp;thread-safe? I know&amp;nbsp;nrf_queue is interrupt secure. Is that&amp;nbsp;equals to thread-safe?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;3. Is&amp;nbsp;the following code looks good for&amp;nbsp;two peripherals?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;buffer_t buf;
buf.p_data = p_lbs_c_evt-&amp;gt;params.button.p_data;
buf.length = (uint8_t)p_lbs_c_evt-&amp;gt;params.button.data_len;

ret_code_t err_code = nrf_libuarte_async_tx(&amp;amp;libuarte, buf.p_data, buf.length);
if (err_code == NRF_ERROR_BUSY){
    if (!nrf_queue_is_full(&amp;amp;m_buf_queue)){
        ret_code_t err_code = nrf_queue_push(&amp;amp;m_buf_queue, &amp;amp;buf);
        APP_ERROR_CHECK(err_code);
    }
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;4. If &lt;span&gt;libuarte/nrf_queue not thread-safe, should I need to implement something like&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;CRITICAL_REGION_ENTER();&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;CRITICAL_REGION_EXIT();&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;Best Regards&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;span&gt;Leo&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: libuarte sometimes print garbled</title><link>https://devzone.nordicsemi.com/thread/281820?ContentTypeID=1</link><pubDate>Wed, 25 Nov 2020 13:27:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b6f9e324-cf48-4b22-9454-99237507a1ff</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;RTT works over SWD, and should not interfere with the UART interface. Could it be some issue with the buffer scopes, causing the libUARTE buffers to be overwritten before being processed/transmitted?&lt;/p&gt;
&lt;p&gt;Have you tested with different UART pins, just to make sure there is nothing else in the application trying to write to these pins?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>