<?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 Unexpected RX free input parameter</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/93058/libuarte-unexpected-rx-free-input-parameter</link><description>Hi there, 
 several months ago I developed a usb to uart bridge based on the nRF52820. We&amp;#39;ve produced a hand full of those bridges for internal tests and the feedback showed some problems. 
 Right now the biggest problem is that sometimes the bridge stops</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 08 Nov 2022 10:36:12 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/93058/libuarte-unexpected-rx-free-input-parameter" /><item><title>RE: libuarte Unexpected RX free input parameter</title><link>https://devzone.nordicsemi.com/thread/394643?ContentTypeID=1</link><pubDate>Tue, 08 Nov 2022 10:36:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:67ee3003-c5d6-4846-949f-fe5b1a75632e</guid><dc:creator>JoEi</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;span&gt;H&amp;aring;kon,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I&amp;#39;ve tested a few things and the problem was&amp;nbsp;as you&amp;#39;ve said calling NRF_LIBUARTE_ASYNC_DEFINE(..) with RTC and TIMER for the timeout. After removing the TIMER instance for the timeout libuarte works perfectly.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks for your help =)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Kind regards,&lt;br /&gt;Johannes&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: libuarte Unexpected RX free input parameter</title><link>https://devzone.nordicsemi.com/thread/392325?ContentTypeID=1</link><pubDate>Tue, 25 Oct 2022 09:32:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:37f89c0d-b109-45c1-9a14-02fac135d0e5</guid><dc:creator>JoEi</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;span&gt;H&amp;aring;kon,&lt;/span&gt;&lt;/p&gt;
[quote userid="2115" url="~/f/nordic-q-a/93058/libuarte-unexpected-rx-free-input-parameter/392312"]What is the &amp;quot;libuarte&amp;quot; variable here?[/quote]
&lt;p&gt;libuarte is the variable I got from NRF_LIBUARTE_ASYNC_DEFINE.&lt;/p&gt;
[quote userid="2115" url="~/f/nordic-q-a/93058/libuarte-unexpected-rx-free-input-parameter/392312"]It looks like context is going out of scope at your end. Could you try storing uart_event_handler::context and using that instead of &amp;quot;&amp;amp;libuarte&amp;quot;?[/quote]
&lt;p&gt;I&amp;#39;ve tried that before when implementing libuarte but back then I couldn&amp;#39;t get it to run. According to my logs from back then I only got unexpected libuarte events&lt;/p&gt;
[quote userid="2115" url="~/f/nordic-q-a/93058/libuarte-unexpected-rx-free-input-parameter/392312"]Sorry, the logic was misread from my side. This is on a byte-for-byte basis, so 100 us is fine here.[/quote]
&lt;p&gt;&lt;span&gt;&lt;/span&gt;I&amp;#39;ve changed the timeout to 1ms and so far I haven&amp;#39;t seen the error again. But instead on the usb side something behaves strangely now.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Kind regards,&lt;br /&gt;Johannes&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: libuarte Unexpected RX free input parameter</title><link>https://devzone.nordicsemi.com/thread/392312?ContentTypeID=1</link><pubDate>Tue, 25 Oct 2022 08:18:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b93ea2d4-5454-4ff7-a3f2-539fec42d82a</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi Johannes,&lt;/p&gt;
[quote user="Johannes"]A1: Only if I unplug or plug in the uart connector when the bridge is already running, which normally isn&amp;#39;t the case.[/quote]
&lt;p&gt;Ok, that is to be expected. You can add a re-init routine to recover from that scenario, if wanted.&lt;/p&gt;
[quote user="Johannes"]A2: I&amp;#39;ve found an example that configured the libuarte like this and haven&amp;#39;t thought&amp;nbsp;much about it.[/quote]
&lt;p&gt;You should select either RTC based timing, or high speed TIMER.&lt;/p&gt;
[quote user="Johannes"]A3: Well I used the same timeout that is used in the libuarte example in the SDK. Is there a rule of thumb how to choose the right timeout?[/quote]
&lt;p&gt;Sorry, the logic was misread from my side. This is on a byte-for-byte basis, so 100 us is fine here.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The usual scenario when receiving &amp;quot;Unexpected RX free input parameter&amp;quot; is that there is a timing issue in the firmware, wrong input parameter, etc.&lt;/p&gt;
&lt;p&gt;Looking at your code here:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void uart_event_sched_handler(void* p_event_data, uint16_t event_size)
{
  nrf_libuarte_async_evt_t* p_evt = (nrf_libuarte_async_evt_t*) p_event_data;

  switch(p_evt-&amp;gt;type)
  {
    case NRF_LIBUARTE_ASYNC_EVT_RX_DATA:
    {
      u8* pu8Data;
      u32 i;
      for(i = 0, pu8Data = p_evt-&amp;gt;data.rxtx.p_data; i &amp;lt; p_evt-&amp;gt;data.rxtx.length; i++, pu8Data++)
      {
        UART_RxProcess(*pu8Data);
      }
      nrf_libuarte_async_rx_free(&amp;amp;libuarte, p_evt-&amp;gt;data.rxtx.p_data, p_evt-&amp;gt;data.rxtx.length);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What is the &amp;quot;libuarte&amp;quot; variable here? normally, you want to&amp;nbsp;pass both the&amp;nbsp;void pointer and the p_evt coming from the libuarte evt handler:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void my_libuarte_handler(void * context, nrf_libuarte_async_evt_t * p_evt)
{
    nrf_libuarte_async_t * p_libuarte = (nrf_libuarte_async_t *)context;
    switch (p_evt-&amp;gt;type)
    {
    case NRF_LIBUARTE_ASYNC_EVT_RX_DATA:
        nrf_libuarte_async_rx_free(p_libuarte, p_evt-&amp;gt;data.rxtx.p_data, p_evt-&amp;gt;data.rxtx.length);
        ...
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It looks like context is going out of scope at your end. Could you try storing uart_event_handler::context and using that instead of &amp;quot;&amp;amp;libuarte&amp;quot;?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: libuarte Unexpected RX free input parameter</title><link>https://devzone.nordicsemi.com/thread/392171?ContentTypeID=1</link><pubDate>Mon, 24 Oct 2022 13:09:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:72b4e41d-6099-4f7e-8709-b1a7ba1def88</guid><dc:creator>JoEi</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;span&gt;H&amp;aring;kon,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;A1: Only if I unplug or plug in the uart connector when the bridge is already running, which normally isn&amp;#39;t the case.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;A2: I&amp;#39;ve found an example that configured the libuarte like this and haven&amp;#39;t thought&amp;nbsp;much about it. &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f605.svg" title="Sweat smile"&gt;&amp;#x1f605;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;A3: Well I used the same timeout that is used in the libuarte example in the SDK. Is there a rule of thumb how to choose the right timeout?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Kind regards,&lt;br /&gt;Johannes&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: libuarte Unexpected RX free input parameter</title><link>https://devzone.nordicsemi.com/thread/392159?ContentTypeID=1</link><pubDate>Mon, 24 Oct 2022 12:33:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1d3e3f48-a3c3-4b6b-9c2e-9f1ed7c5b8f6</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Q1: Does the event &amp;quot;NRF_LIBUARTE_ASYNC_EVT_ERROR&amp;quot; occur at some point?&lt;/p&gt;
&lt;p&gt;Q2: You seem to configure&amp;nbsp;NRF_LIBUARTE_ASYNC_DEFINE(..) to use both RTC and high speed TIMER for timeout generation, is this intended?&lt;/p&gt;
&lt;p&gt;Q3: The timeout is set to 100 us. This sounds a bit low for receiving up to 256 bytes payload. Have you tried adjusting this a bit higher?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: libuarte Unexpected RX free input parameter</title><link>https://devzone.nordicsemi.com/thread/391669?ContentTypeID=1</link><pubDate>Thu, 20 Oct 2022 12:47:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:27fabf99-e22d-4cdd-aa9c-4af9d82c0887</guid><dc:creator>JoEi</dc:creator><description>&lt;p&gt;Ok somehow Ozone showed me complete nonsense.&lt;/p&gt;
&lt;p&gt;Sometimes I reach the point where&amp;nbsp;&lt;span&gt;rx_free_cnt&amp;nbsp;is 250 and&amp;nbsp;nrf_libuarte_async_rx_free&amp;nbsp;is called with a length greater than 6 (e.g. 20) which results in&amp;nbsp;rx_free_cnt&amp;nbsp;exceeding the buffer size 256.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>