<?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 RX Buffer Full event</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/83837/libuarte-rx-buffer-full-event</link><description>Hello, 
 
 I am having an issue with the nrf_libuarte_async librairie. 
 
 I am sending data via nrf_libuarte_async_tx and receiving the data properly via the IRQ handler (user implemented). I copy the data received into a buffer and then send a notification</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 23 Feb 2022 13:45:46 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/83837/libuarte-rx-buffer-full-event" /><item><title>RE: LIBUARTE RX Buffer Full event</title><link>https://devzone.nordicsemi.com/thread/354603?ContentTypeID=1</link><pubDate>Wed, 23 Feb 2022 13:45:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:24b787fd-8293-497f-aefb-25c303d7248f</guid><dc:creator>ogulcan</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I was having a similar problem with the LIBUARTE library. In the end I realised that there is a way to understand if the event is because of a full buffer or timeout. The variable p_libuarte-&amp;gt;p_ctrl_blk-&amp;gt;sub_rx_count is always 0 if the event is coming from a full buffer.&lt;/p&gt;
&lt;p&gt;Here is my uartEventHandle if anyone else needs it:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**@brief Function for handling UARTE callback events.
 *
 * @param[in]   context   Pointer to UARTE library asynhronous instance.
 * @param[in]   p_evt     Pointer to UARTE library asynhronous event.
 */
static void uartEventHandle(void * context, nrf_libuarte_async_evt_t * p_evt)
{
    /* Holds pointer to UARTE library instance. */
    nrf_libuarte_async_t * p_libuarte = (nrf_libuarte_async_t *)context;
    /* Holds yield request. */
    BaseType_t yieldReq = pdFALSE;
    /* Decide according to event type. */
    switch(p_evt-&amp;gt;type)
    {
        case NRF_LIBUARTE_ASYNC_EVT_RX_DATA:
            /* Check if buffer full event. */
            if(0 == p_libuarte-&amp;gt;p_ctrl_blk-&amp;gt;sub_rx_count)
            {
                /* Copy new data to buffer but wait for the second event. */
            }
            else
            {
                /* Copy rest of data to your buffer and notify the task to process it. */   
                vTaskNotifyGiveFromISR(taskHandle, &amp;amp;yieldReq);
                portYIELD_FROM_ISR(yieldReq);
            }
            /* Free UARTE memory. */
            nrf_libuarte_async_rx_free(p_libuarte, p_evt-&amp;gt;data.rxtx.p_data, \
                                       p_evt-&amp;gt;data.rxtx.length);
            break;
        case NRF_LIBUARTE_ASYNC_EVT_ERROR:
            break;
        case NRF_LIBUARTE_ASYNC_EVT_TX_DONE:
            break;
        default:
            break;
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;So there is no need to change the files from the SDK.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: LIBUARTE RX Buffer Full event</title><link>https://devzone.nordicsemi.com/thread/349008?ContentTypeID=1</link><pubDate>Fri, 21 Jan 2022 16:15:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c4d9d93c-e2c2-4752-8fa7-61fb44545f69</guid><dc:creator>vlockhead</dc:creator><description>&lt;p&gt;Thank you for your answer Edvin! I will look into implementing the buffer full event.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: LIBUARTE RX Buffer Full event</title><link>https://devzone.nordicsemi.com/thread/348740?ContentTypeID=1</link><pubDate>Thu, 20 Jan 2022 14:13:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d0829014-9057-4896-875c-64b6a0cf047b</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;1:&lt;/p&gt;
&lt;p&gt;There is no way to tell from the&amp;nbsp;uart_event_handler() in main.c (looking at the SDK\examples\peripheral\libuarte example) to tell what generated the&amp;nbsp;NRF_LIBUARTE_ASYNC_EVT_RX_DATA event. If you want to separate on the two cases where the buffer is full and the timeout, I guess I would&amp;#39;ve tried adding a parameter saying what generated the event in nrf_libuarte_async.c.&lt;/p&gt;
&lt;p&gt;As you can tell, it is either line 243 or 321 that generate the NRF_LIBUARTE_ASYNC_EVT_RX_DATA event. Try adding this to the&amp;nbsp;nrf_libuarte_async_evt_t:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;typedef struct
{
    nrf_libuarte_async_evt_type_t type; ///&amp;lt; Event type.
    union {
        nrf_libuarte_async_data_t rxtx;                   ///&amp;lt; RXD/TXD data.
        uint8_t                   errorsrc;               ///&amp;lt; Error source.
        nrf_libuarte_async_overrun_err_evt_t overrun_err; ///&amp;lt; Overrun error data.
        uint8_t                   src;                    ///&amp;lt; what triggered the event  &amp;lt;- add this line
    } data;                                 ///&amp;lt; Union with data.
} nrf_libuarte_async_evt_t;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And then in the nrf_libuarte_async.c use this parameter to say whether the event was triggered by a timeout or a buffer that is full. E.g by setting it to 0 when the buffer was full or 1 when the timeout occured:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    case NRF_LIBUARTE_DRV_EVT_RX_DATA:
    {

        uint32_t rx_amount = p_evt-&amp;gt;data.rxtx.length - p_libuarte-&amp;gt;p_ctrl_blk-&amp;gt;sub_rx_count;
        if (rx_amount)
        {
            p_libuarte-&amp;gt;p_ctrl_blk-&amp;gt;rx_count += rx_amount;
            nrf_libuarte_async_evt_t evt = {
                .type = NRF_LIBUARTE_ASYNC_EVT_RX_DATA,
                .data = {
                    .rxtx = {
                        .p_data = &amp;amp;p_evt-&amp;gt;data.rxtx.p_data[p_libuarte-&amp;gt;p_ctrl_blk-&amp;gt;sub_rx_count],
                        .length = rx_amount,
                        .src = 0
                    }
                }
            };
            
            
...
void nrf_libuarte_async_timeout_handler(const nrf_libuarte_async_t * p_libuarte)
{
    NRFX_IRQ_DISABLE((IRQn_Type)NRFX_IRQ_NUMBER_GET(p_libuarte-&amp;gt;p_libuarte-&amp;gt;uarte));

    uint32_t capt_rx_count = p_libuarte-&amp;gt;p_libuarte-&amp;gt;timer.p_reg-&amp;gt;CC[3];

    if (capt_rx_count &amp;gt; p_libuarte-&amp;gt;p_ctrl_blk-&amp;gt;rx_count)
    {
        uint32_t rx_amount = capt_rx_count - p_libuarte-&amp;gt;p_ctrl_blk-&amp;gt;rx_count;
        nrf_libuarte_async_evt_t evt = {
            .type = NRF_LIBUARTE_ASYNC_EVT_RX_DATA,
            .data = {
                .rxtx = {
                    .p_data = &amp;amp;p_libuarte-&amp;gt;p_ctrl_blk-&amp;gt;p_curr_rx_buf[p_libuarte-&amp;gt;p_ctrl_blk-&amp;gt;sub_rx_count],
                    .length = rx_amount,
                    .src = 1,
                }
            }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This way you can tell from main.c where the event is coming from:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;...

case NRF_LIBUARTE_ASYNC_EVT_RX_DATA:
            if (p_evt-&amp;gt;data.src == 0)
            {
                NRF_LOG_INFO(&amp;quot;triggered by full buffer&amp;quot;);
            }
            else if (p_evt-&amp;gt;data.src == 1)
            {
                NRF_LOG_INFO(&amp;quot;Triggered by timeout&amp;quot;);
            }
            ret = nrf_libuarte_async_tx(p_libuarte,p_evt-&amp;gt;data.rxtx.p_data, p_evt-&amp;gt;data.rxtx.length);
            if (ret == NRF_ERROR_BUSY)
            {
                buffer_t buf = {
                    .p_data = p_evt-&amp;gt;data.rxtx.p_data,
                    .length = p_evt-&amp;gt;data.rxtx.length,
                };

                ret = nrf_queue_push(&amp;amp;m_buf_queue, &amp;amp;buf);
                APP_ERROR_CHECK(ret);
            }

...&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;And if you want it to be fancy, you can create an enum instead of using the &amp;quot;0&amp;quot; and &amp;quot;1&amp;quot;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;2:&lt;/p&gt;
&lt;p&gt;That is correct.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;3:&lt;/p&gt;
&lt;p&gt;That is not the way it is done in the libuarte library. You can use the above workaround to just copy the data if the event was caused by a full buffer, and attach the last part of the message from the timeout later before you process the data, or you can look into implementing a ring buffer. There is no simple way to make libuarte use a ring buffer out of the box, unfortunately.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: LIBUARTE RX Buffer Full event</title><link>https://devzone.nordicsemi.com/thread/348585?ContentTypeID=1</link><pubDate>Wed, 19 Jan 2022 19:23:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a916eb84-51a3-42b4-ad51-128c1bfb7015</guid><dc:creator>vlockhead</dc:creator><description>&lt;p&gt;There is the same question here:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/81200/libuarte-packet-fragmentation/337220#337220"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/81200/libuarte-packet-fragmentation/337220#337220&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;But no obvious fix&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>