<?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>nrf52810 with nrf52SDK 17.1 S113,can&amp;#39;t receive a whole packet at a time with LIBUARTE</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/124028/nrf52810-with-nrf52sdk-17-1-s113-can-t-receive-a-whole-packet-at-a-time-with-libuarte</link><description>Now I can use LIBUARTE to receive data from MCU, but have a trouble: it can&amp;#39;t receive a whole packet sometime,and return it with 2 parts. 
 UARTE : 115200/8/1 
 receive buffer : 104 bytes * 3 
 MCU send : 28 bytes a time every 5 seconds; 
 nrf52810 receive</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 09 Sep 2025 04:29:15 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/124028/nrf52810-with-nrf52sdk-17-1-s113-can-t-receive-a-whole-packet-at-a-time-with-libuarte" /><item><title>RE: nrf52810 with nrf52SDK 17.1 S113,can't receive a whole packet at a time with LIBUARTE</title><link>https://devzone.nordicsemi.com/thread/548128?ContentTypeID=1</link><pubDate>Tue, 09 Sep 2025 04:29:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:74d5c518-23c3-4aec-afef-680686833ab7</guid><dc:creator>OldXiao</dc:creator><description>&lt;p&gt;Yes,Walk around it.&lt;/p&gt;
&lt;p&gt;I don&amp;#39;t study the code of&amp;nbsp;LIBUARTE, don&amp;#39;t know it is desired way or interrupted by SoftDevice tasks.&lt;/p&gt;
&lt;p&gt;Any way, it works now,we can close this ticket.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52810 with nrf52SDK 17.1 S113,can't receive a whole packet at a time with LIBUARTE</title><link>https://devzone.nordicsemi.com/thread/548046?ContentTypeID=1</link><pubDate>Mon, 08 Sep 2025 10:57:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:91fc9e00-f970-4cd8-bc89-872a7a40d991</guid><dc:creator>Edvin</dc:creator><description>[quote user="OldXiao"]Now I have added the function to re-compose the packets at UART.Rx side[/quote]
&lt;p&gt;Does this mean that it is working now?&lt;/p&gt;
&lt;p&gt;BR,&lt;br /&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52810 with nrf52SDK 17.1 S113,can't receive a whole packet at a time with LIBUARTE</title><link>https://devzone.nordicsemi.com/thread/547979?ContentTypeID=1</link><pubDate>Sat, 06 Sep 2025 04:35:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:500dd8fc-0e06-4c7d-8043-63a543f886d6</guid><dc:creator>OldXiao</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I did not get your meaning,this is my code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;quot;nrf_libuarte_async.h&amp;quot;
#include &amp;quot;app_uarte.h&amp;quot;
#include &amp;quot;nrf_queue.h&amp;quot;
#include &amp;quot;nrfx_log.h&amp;quot;
#include &amp;quot;nrf_assert.h&amp;quot;
#include &amp;quot;sdk_config.h&amp;quot;

//create uarte instance
/*#define NRF_LIBUARTE_ASYNC_DEFINE(_name, _uarte_idx, _timer0_idx,\
                                  _rtc1_idx, _timer1_idx,\
                                  _rx_buf_size, _rx_buf_cnt) 
								  */
NRF_LIBUARTE_ASYNC_DEFINE(	m_libuarte, 0, 1,    
							NRF_LIBUARTE_PERIPHERAL_NOT_USED, 2,  
							NRF_SDH_BLE_GATT_MAX_MTU_SIZE * 2, 3);


//use queue as TX buffer
// BLE -&amp;gt; TX buffer -&amp;gt; UART -&amp;gt; MCU
NRF_QUEUE_DEF(buffer_to_uart_struct_t, m_uart_tx_queue,  BUFFER_UP_QUEUE_SIZE, BUFFER_UP_QUEUE_MODE );


static app_uarte_rx_handler_t m_rx_handler = NULL;

static volatile bool m_tx_in_progress = false;

static void process_tx_fifo(void);

void libuarte_event_handler(void * context, nrf_libuarte_async_evt_t * p_event){
    nrf_libuarte_async_t * p_libuarte = (nrf_libuarte_async_t *)context;
   
    switch (p_event-&amp;gt;type)
    {
        case NRF_LIBUARTE_ASYNC_EVT_RX_DATA:
            if (m_rx_handler) {
                m_rx_handler(p_event-&amp;gt;data.rxtx.p_data, p_event-&amp;gt;data.rxtx.length);
				//must release rx buffer
                nrf_libuarte_async_rx_free(p_libuarte, p_event-&amp;gt;data.rxtx.p_data, p_event-&amp;gt;data.rxtx.length);
            }
            break;
        case NRF_LIBUARTE_ASYNC_EVT_TX_DONE:
            if (m_tx_in_progress){
				//pop record has been sent
				nrf_queue_generic_pop_with_no_data_return(&amp;amp;m_uart_tx_queue);
                m_tx_in_progress = false;
            }
			//try to send next record from buffer
            process_tx_fifo();
            break;
        case NRF_LIBUARTE_ASYNC_EVT_ERROR:
            NRF_LOG_ERROR(&amp;quot;UARTE error occurred,error source:%d&amp;quot;,p_event-&amp;gt;data.errorsrc);
            break;
        case NRF_LIBUARTE_ASYNC_EVT_OVERRUN_ERROR:
            NRF_LOG_ERROR(&amp;quot;UARTE overrun error occurred,lost:%d bytes.&amp;quot;,p_event-&amp;gt;data.overrun_err.overrun_length);
            break;
        default:
            break;
    }
}


static void process_tx_fifo(void) {
    if (m_tx_in_progress) {
        return; 
    }
	if(nrf_queue_is_empty(&amp;amp;m_uart_tx_queue)){
		return;
	}
	
	ret_code_t err_code;
    buffer_to_uart_struct_t* p;
	
  get_head_element:
	p = nrf_queue_generic_get_head_element(&amp;amp;m_uart_tx_queue);
	if(NULL == p){
		NRF_LOG_DEBUG(&amp;quot;No data to send.&amp;quot;);
		return;
	}
	
	if(0 == p-&amp;gt;actual_data_len){
		nrf_queue_generic_pop_with_no_data_return(&amp;amp;m_uart_tx_queue);
		NRF_LOG_DEBUG(&amp;quot;record&amp;#39;s actual_data_len = 0,delete it&amp;quot;);
		goto get_head_element;
	}

	//try to send 1st record
	err_code = nrf_libuarte_async_tx(&amp;amp;m_libuarte, p-&amp;gt;data, p-&amp;gt;actual_data_len);
    if (err_code == NRFX_SUCCESS) {
		m_tx_in_progress = true;
	} else {
		NRF_LOG_ERROR(&amp;quot;Failed to start LIBUARTE TX, error code: %d(%s)&amp;quot;, err_code,NRFX_LOG_ERROR_STRING_GET(err_code));
	}
}


void app_uarte_init(uint32_t tx_pin, uint32_t rx_pin, nrf_uarte_baudrate_t baudrate, app_uarte_rx_handler_t rx_handler) {
    ASSERT(rx_handler);
	
    m_rx_handler = rx_handler;
    ret_code_t err_code;

	nrf_libuarte_async_config_t nrf_libuarte_async_config = {
            .tx_pin     = tx_pin,
            .rx_pin     = rx_pin,
            .baudrate   = baudrate,
            .parity     = NRF_UARTE_PARITY_EXCLUDED,
            .hwfc       = NRF_UARTE_HWFC_DISABLED,
            .timeout_us = 500,
            .int_prio   = APP_IRQ_PRIORITY_LOW
    };
	
	err_code = nrf_libuarte_async_init(&amp;amp;m_libuarte, &amp;amp;nrf_libuarte_async_config, libuarte_event_handler, (void *)&amp;amp;m_libuarte);
    APP_ERROR_CHECK(err_code);

    nrf_libuarte_async_enable(&amp;amp;m_libuarte);

}

// called while BLE received data
// server data -&amp;gt; BLE -&amp;gt; uart queue -&amp;gt; UART.TxD -&amp;gt; MCU
bool app_uarte_send_buffer_push(const uint8_t *data, size_t length) {
	if((NULL == data) || (length == 0) )
			return false;
    
	//push into queue 
	buffer_to_uart_struct_t bu;
	bu.actual_data_len = length;
	memcpy(bu.data,data,length);
	
	ret_code_t ret;
	ret = nrf_queue_push_bytes(&amp;amp;m_uart_tx_queue,(const void*)&amp;amp;bu, 
					bu.actual_data_len + sizeof(bu.actual_data_len)); 
	if (NRF_SUCCESS != ret){
		NRF_LOG_DEBUG(&amp;quot;push into UART TxD buffer failed,ret = %d&amp;quot;,ret);
	}else{
		NRF_LOG_DEBUG(&amp;quot;push into UART TxD buffer success.&amp;quot;);
	}
	
    //try to send
    process_tx_fifo();
    
    return true;
}

&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Now I have added the function to re-compose the packets at UART.Rx side.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf52810 with nrf52SDK 17.1 S113,can't receive a whole packet at a time with LIBUARTE</title><link>https://devzone.nordicsemi.com/thread/547476?ContentTypeID=1</link><pubDate>Tue, 02 Sep 2025 12:37:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fc4a24f1-3cb5-4a43-bd21-5dba63e2568b</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
[quote user=""]&lt;p&gt;receive buffer : 104 bytes * 3&lt;/p&gt;
&lt;p&gt;MCU send : 28 bytes a time every 5 seconds;&lt;/p&gt;[/quote]
&lt;p&gt;This sounds a bit overkill. If the MCU always sends 28 bytes every 5 seconds, I would recommend that you are looking into the UART implementation from SDK\examples\ble_peripheral\ble_app_uart. That should be more than enough to handle this amount of data.&lt;/p&gt;
&lt;p&gt;Note that the libuarte library is very resource heavy. Requiring a lot of peripherals running for it&amp;#39;s functionality.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;If you do, however, insist in using libuarte, can you check, the times where your packet is split up, is it coming from the&amp;nbsp;nrf_libuarte_async_timeout_handler(), or&amp;nbsp;uart_evt_handler() -&amp;gt; case NRF_LIBUARTE_DRV_EVT_RX_DATA ?&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></channel></rss>