<?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>Asynchronous UART and circular buffer?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/118516/asynchronous-uart-and-circular-buffer</link><description>Hi, 
 I am making an application based on the peripheral-nus example. The checking for CR is removed and all characters are just sent further when available. The problem is that even short messages might be split in parts when close to buffer ends. For</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 05 Feb 2025 17:45:21 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/118516/asynchronous-uart-and-circular-buffer" /><item><title>RE: Asynchronous UART and circular buffer?</title><link>https://devzone.nordicsemi.com/thread/521614?ContentTypeID=1</link><pubDate>Wed, 05 Feb 2025 17:45:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f7002415-58b6-4d43-8689-b37a33f08b99</guid><dc:creator>Mikael_2</dc:creator><description>&lt;p&gt;Thank you! That looks like what I need :-)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Asynchronous UART and circular buffer?</title><link>https://devzone.nordicsemi.com/thread/521537?ContentTypeID=1</link><pubDate>Wed, 05 Feb 2025 12:10:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:78cf4fae-78a9-456e-a97c-3ef8f76d793a</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;&lt;span&gt;It looks like we may have what you need. This commit &lt;a href="https://github.com/zephyrproject-rtos/zephyr/commit/399a235653518bc9b65c083f2e70cefa943aa4d9"&gt;https://github.com/zephyrproject-rtos/zephyr/commit/399a235653518bc9b65c083f2e70cefa943aa4d9&lt;/a&gt;&amp;nbsp;introduced a new receive mode (CONFIG_UART_NRFX_UARTE_ENHANCED_RX) that always releases the buffer after UART_RX_RDY. This means the buffer offset will always be 0. It is the default mode in SDK v2.9.0.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Asynchronous UART and circular buffer?</title><link>https://devzone.nordicsemi.com/thread/521481?ContentTypeID=1</link><pubDate>Wed, 05 Feb 2025 09:09:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8efe22f3-c7d3-4bd0-89a7-a8d6b1b3c4ed</guid><dc:creator>Mikael_2</dc:creator><description>&lt;p&gt;The application have not possibility do this as good as the driver could because the application &lt;br /&gt;has not access to the same information. The application can not know if data is still arriving.&lt;br /&gt;&lt;br /&gt;I transfer random binary data that I do not control so CR/STX/ETX will not solve the problem.&lt;br /&gt;Of course if the data do not fill the buffer I have to wait for a timeout. That is all fine.&lt;br /&gt;&lt;br /&gt;I want to avoid short messages being delivered to the application in two parts.&lt;br /&gt;The application could handle this by checking if last message filled the buffer and &lt;br /&gt;if so wait a delay time and if a second part comes join the two parts.&lt;br /&gt;&lt;br /&gt;I think it is not ideal to first split the message in the driver and then combine it again in the application. That is a waste of resources. Better would be not to split it in the first place.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Easier would be if the driver had a ring buffer with a maximum number of bytes for each delivery to application. This way the driver would always be able to deliver short timeout messages in one piece.&lt;br /&gt;The same could be achieved if the driver only used each buffer one time. Then the application would arrange the ring buffer handling and the driver always have a new empty buffer to fill.&lt;br /&gt;&lt;br /&gt;-----------------&lt;br /&gt;&lt;br /&gt;As an example. We receive &amp;quot;John&amp;quot; in two different situations: &lt;br /&gt;Baudrate 1200. Buffer length 250. Timeout 50 ms.&lt;br /&gt;&lt;br /&gt;1a)&lt;br /&gt;Application combine.&lt;br /&gt;&lt;br /&gt;End of first buffer: &amp;quot;Joh&amp;quot;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br /&gt;Beginning of second buffer: &amp;quot;n&amp;quot;&lt;br /&gt;&lt;br /&gt;The application can handle this nice and get a combine &amp;quot;John&amp;quot; 50 ms after &amp;quot;n&amp;quot; arrived.&lt;br /&gt;&lt;br /&gt;1b)&lt;br /&gt;Application combine.&lt;br /&gt;&lt;br /&gt;End of first buffer: &amp;quot;John&amp;quot;&lt;br /&gt;Beginning of second buffer: nothing, not used yet&lt;br /&gt;&lt;br /&gt;The application do not know if more characters is coming and has to wait &lt;br /&gt;50 ms + (249 x 8,33ms) = 2,13 s before having &amp;quot;John&amp;quot; finished. &lt;br /&gt;This is to long time, it will give time out in other parts of the system.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2a)&lt;br /&gt;Driver with ring buffer or single use buffer.&lt;br /&gt;&lt;br /&gt;Driver deliver &amp;quot;John&amp;quot; 50 ms after &amp;quot;n&amp;quot; arrived. Nice.&lt;br /&gt;&lt;br /&gt;2b)&lt;br /&gt;Driver with ring buffer or single use buffers.&lt;br /&gt;&lt;br /&gt;We get one message to the application with &amp;quot;John&amp;quot; 50 ms after &amp;quot;n&amp;quot; arrived.&lt;br /&gt;A good solution.&lt;br /&gt;&lt;br /&gt;Of course we can try and reduce the buffer length and make the timeout different for different baud-rates.&lt;br /&gt;But I think driver have better possibilities to handle this.&lt;br /&gt;&lt;br /&gt;------------------&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Are there any uart driver available that can do ring buffer or single use of buffers?&lt;br /&gt;How complex is it to make an modified driver?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I am almost new to this RTOS programming and is used to minimalistic bare metal programming. It surprises me that it is so difficult to get a simple ring buffer for received uart data.&lt;br /&gt;(I wrote a TCP/IP-stack without OS already in the end of previous century and used Intel iRMX RTOS in the 1980&amp;acute;s).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Asynchronous UART and circular buffer?</title><link>https://devzone.nordicsemi.com/thread/521029?ContentTypeID=1</link><pubDate>Mon, 03 Feb 2025 07:57:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e04517a0-87b6-4aa5-b371-58d087588b3b</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;I agree with answer above.&amp;nbsp;The only way I see to avoid this is if the length of the received data always matches the length of the DMA buffer. If you have to wait for the timeout to expire on the last chunk of data, it is because the last chunk did not fill the DMA buffer.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Asynchronous UART and circular buffer?</title><link>https://devzone.nordicsemi.com/thread/520964?ContentTypeID=1</link><pubDate>Sat, 01 Feb 2025 10:30:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:40a55a53-97e0-49d4-9121-9e31bab901a9</guid><dc:creator>Jakob Ruhe</dc:creator><description>&lt;p&gt;This is something your application needs to handle. Even though your firmware sends a message in one chunk it is not good practice to assume that this chunk will end up as one chunk also in your application. That is why a separator, such as CR, is typically used so that some part of your application can read bytes up to the CR and then forward the received line to&amp;nbsp;an upper layer for further processing.&lt;/p&gt;
&lt;p&gt;Buffering also on sender side before transmission&amp;nbsp;is sometimes&amp;nbsp;a good idea and sometimes not needed. It depends on how the bytes are actually sent over the air/wire.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>