<?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>UART RX missing bytes -event buffer  length and offset mismatch-NRF Connect SDK</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/93556/uart-rx-missing-bytes--event-buffer-length-and-offset-mismatch-nrf-connect-sdk</link><description>Hi, greetings all !! 
 I am developing an application based on ble_uart_peripheral example on nrf52dk_nrf52832 using NRF Connect SDK2.1. In my application, I have to receive bytes from an external client via UART. The problem is, at high baud rate, some</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 11 Nov 2022 14:39:11 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/93556/uart-rx-missing-bytes--event-buffer-length-and-offset-mismatch-nrf-connect-sdk" /><item><title>RE: UART RX missing bytes -event buffer  length and offset mismatch-NRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/395351?ContentTypeID=1</link><pubDate>Fri, 11 Nov 2022 14:39:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:95a94227-92ff-4f81-84af-989f5df78a93</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>[quote user="Midhunjac"]That was what i tried to do initially, but without knowing the exact length and offset, that would be difficult.&amp;nbsp; Can you guide me with a code snippet ?[/quote]
&lt;p&gt;The offset and length are given in the event. Based on your code, you can process it directly like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;case UART_RX_RDY:
	LOG_DBG(&amp;quot;UART_RX_RDY&amp;quot;);
	buf = CONTAINER_OF(evt-&amp;gt;data.rx.buf, struct uart_data_t, data);
	buf-&amp;gt;len += evt-&amp;gt;data.rx.len;
	if (disable_req) {
		return;
	}
	uint8_t data_t;
	for (uint8_t i; i &amp;lt; evt-&amp;gt;data.rx.len; i++)
	{
	    data_t = *(buf-&amp;gt;data+evt-&amp;gt;data.rx.offset+i);
        packetDecode(data_t,eSrc_UART);
	}
    if ((evt-&amp;gt;data.rx.buf[buf-&amp;gt;len - 1] == &amp;#39;\n&amp;#39;) ||
        (evt-&amp;gt;data.rx.buf[buf-&amp;gt;len - 1] == &amp;#39;\r&amp;#39;)) 
    {
    	disable_req = true;
    	uart_rx_disable(uart);
    }
	
	break;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;You can also define a &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.1.2/zephyr/kernel/services/data_passing/queues.html"&gt;Queue&lt;/a&gt; or a&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.1.2/zephyr/kernel/services/data_passing/fifos.html"&gt;FIFO &lt;/a&gt;where you push each received byte, to be processed later.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART RX missing bytes -event buffer  length and offset mismatch-NRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/395127?ContentTypeID=1</link><pubDate>Thu, 10 Nov 2022 13:31:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:26ff55f1-5857-49b7-8e17-a7efc3a75dcc</guid><dc:creator>Midhunjac</dc:creator><description>&lt;p&gt;Yes. The issue was caused due to the shared buffer. So, i tried using seperate buffers. But buffer size of 1 wont be enough as I observed it caused kernel panic. I believe the first 2 locations are used for some OS level purposes. Anyway, I got it working with size 3. But as you mentioned, this might not be a good solution.&lt;/p&gt;
[quote userid="14926" url="~/f/nordic-q-a/93556/uart-rx-missing-bytes--event-buffer-length-and-offset-mismatch-nrf-connect-sdk/395119"]Processing the received bytes according to the offset and len parameters and/or pushing the received data into a queue for later processing would be a much safer approach.[/quote]
&lt;p&gt;That was what i tried to do initially, but without knowing the exact length and offset, that would be difficult.&amp;nbsp; Can you guide me with a code snippet ?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART RX missing bytes -event buffer  length and offset mismatch-NRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/395119?ContentTypeID=1</link><pubDate>Thu, 10 Nov 2022 13:14:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6ae1dc32-4df1-42bb-b4cc-29f496a5eda7</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Ah, I see. The config is used for both the RX and TX buffers, and the buffer will be too small for the TX strings used in the example, causing an error.&lt;/p&gt;
&lt;p&gt;You can modify the example to use separate TX and RX buffer sizes, as shown in this patch:&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/main_5F00_changes.diff"&gt;devzone.nordicsemi.com/.../main_5F00_changes.diff&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Note that the peripheral_uart application gave lots of warnings about not being able to allocate UART receive buffer when receiving much data, so this approach may lead to data loss if you are not careful about the baudrate and frequency of incoming data. I would advise against using this approach. Processing the received bytes according to the offset and len parameters and/or pushing the received data into a queue for later processing would be a much safer approach.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART RX missing bytes -event buffer  length and offset mismatch-NRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/395000?ContentTypeID=1</link><pubDate>Wed, 09 Nov 2022 19:53:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c6f8cf81-4da1-4ce3-8e4a-6e309c3f0e19</guid><dc:creator>Midhunjac</dc:creator><description>&lt;p&gt;I am sorry I did not mention about that. Yes, I tried but that didnt work. When I added that in the config environment, the device stopped receiving at all. No callbacks at all for receiving.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART RX missing bytes -event buffer  length and offset mismatch-NRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/394876?ContentTypeID=1</link><pubDate>Wed, 09 Nov 2022 10:23:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:66a79389-3be3-47db-bbec-85c9441202fb</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Did you try&amp;nbsp;setting the config I suggested in my last post?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART RX missing bytes -event buffer  length and offset mismatch-NRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/394783?ContentTypeID=1</link><pubDate>Tue, 08 Nov 2022 16:52:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0e777d30-b58e-4465-a6b4-b08fcceb1d83</guid><dc:creator>Midhunjac</dc:creator><description>&lt;p&gt;I want to get data byte by byte for my purpose. what would be a better method to do that ? please excuse my ignorance.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART RX missing bytes -event buffer  length and offset mismatch-NRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/394518?ContentTypeID=1</link><pubDate>Mon, 07 Nov 2022 16:36:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:135cc906-4458-4e8d-b05a-fb32614af705</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;This is not the expected way that the async UART should work, but you can try to set &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v2.1.0/samples/bluetooth/peripheral_uart/Kconfig#L17-L21"&gt;CONFIG_&lt;/a&gt;&lt;span&gt;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v2.1.0/samples/bluetooth/peripheral_uart/Kconfig#L17-L21"&gt;BT_NUS_UART_BUFFER_SIZE&lt;/a&gt;=1, as this is what determines the &lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/v2.1.0/samples/bluetooth/peripheral_uart/src/main.c#L53"&gt;buffer size used in the sample&lt;/a&gt;. Note that this may cause overrun errors if the CPU is blocked from providing a new buffer to the UARTE peripheral before ~4 bytes are received. I would be much more safe to have a larger buffer size and iterate through the received data when you get the events.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART RX missing bytes -event buffer  length and offset mismatch-NRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/394458?ContentTypeID=1</link><pubDate>Mon, 07 Nov 2022 14:02:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6cec6ac3-98fd-440f-b06f-31ccd3945202</guid><dc:creator>Midhunjac</dc:creator><description>&lt;p&gt;yes. my requirement is to receive and process byte by byte. If my UART thread is given highest priority, do you think maybe this event will work as expected ? with one byte each ? how can I give my UART RX the highest priority ? I am not doing much other than collecting the data and a little bit of work on it. So, i dont mind it blocking some other communication, i think.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART RX missing bytes -event buffer  length and offset mismatch-NRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/394442?ContentTypeID=1</link><pubDate>Mon, 07 Nov 2022 13:29:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ecc35c25-6892-4ca0-9a38-dcd8b90296c6</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Do I read your code correctly that you will only assign one byte to&amp;nbsp;data_t? If the CPU is blocked by other higher priority tasks to provide the UART RX event immediately when the data is received, the event can contain multiple bytes (given by the len struct member variable). You need to loop through the buffer from offset to offset+len to make sure you get all received bytes.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART RX missing bytes -event buffer  length and offset mismatch-NRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/394216?ContentTypeID=1</link><pubDate>Fri, 04 Nov 2022 15:03:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:daf95559-f451-479b-977e-1f43444a5fd8</guid><dc:creator>Midhunjac</dc:creator><description>&lt;p&gt;Hi Jorgen,&lt;/p&gt;
&lt;p&gt;maybe i am not making myself clear here. This is my code.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;case UART_RX_RDY:
		LOG_DBG(&amp;quot;UART_RX_RDY&amp;quot;);
		buf = CONTAINER_OF(evt-&amp;gt;data.rx.buf, struct uart_data_t, data);
		buf-&amp;gt;len += evt-&amp;gt;data.rx.len;
		if (disable_req) {
			return;
		}
		uint8_t data_t = *(buf-&amp;gt;data+evt-&amp;gt;data.rx.offset);
		packetDecode(data_t,eSrc_UART);

		if ((evt-&amp;gt;data.rx.buf[buf-&amp;gt;len - 1] == &amp;#39;\n&amp;#39;) ||
		    (evt-&amp;gt;data.rx.buf[buf-&amp;gt;len - 1] == &amp;#39;\r&amp;#39;)) {
			disable_req = true;
			uart_rx_disable(uart);
		}
		
		break;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;This is part of the default uart_cb() that was part of the peripheral uart example. I am expecting that when each byte is received, I will get this interrupt and i will get that in data_t variable. Please correct me if my understanding is wrong or if there is a better implementation.&lt;br /&gt;I dont feel that the logic is wrong though. Since, when there is a 1s gap between each byte transmitted from my client, I get all the bytes with no hassle in the data_t variable.&lt;/p&gt;
&lt;p&gt;Please advise. Thanks for your time.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: UART RX missing bytes -event buffer  length and offset mismatch-NRF Connect SDK</title><link>https://devzone.nordicsemi.com/thread/394150?ContentTypeID=1</link><pubDate>Fri, 04 Nov 2022 12:57:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9bd1750a-b4f1-47b6-a22d-2d50234adde5</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Do you expect offset and len to always be the same? As described in&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.1.0/zephyr/hardware/peripherals/uart.html#c.uart_event_rx"&gt;&lt;span&gt;uart_event&lt;/span&gt;&lt;/a&gt;&lt;span&gt;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.1.0/zephyr/hardware/peripherals/uart.html#c.uart_event_rx"&gt;_rx struct documentation&lt;/a&gt;: &amp;quot;The data represented by the event is stored in rx.buf[rx.offset] to rx.buf[rx.offset+rx.len]. That is, the length is relative to the offset.&amp;quot; Is this how you read out data from the buffer in the event?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;br /&gt;Jørgen&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>