<?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>FIFO buffer clogging</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/20029/fifo-buffer-clogging</link><description>-----------------------------EDIT-------------------------------------- 
 I&amp;#39;ve changed topic name, because not buffer overwrite is the problem. 
 I need some mechanism for checking if my data packet can fit into FIFO buffer.
If not, it should be just</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 29 Mar 2017 07:09:39 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/20029/fifo-buffer-clogging" /><item><title>RE: FIFO buffer clogging</title><link>https://devzone.nordicsemi.com/thread/77963?ContentTypeID=1</link><pubDate>Wed, 29 Mar 2017 07:09:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:72cb9eb1-d522-4cfb-84f4-c7397b18207d</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;Unfortunately the logging API in SDK v11 is not thread safe, and if you are pushing a lot of data then it is possible to get data corruption.&lt;/p&gt;
&lt;p&gt;In SDK v12 a deferred mode was introduced, which should allow you to push updates without fear of corruption.&lt;/p&gt;
&lt;p&gt;If you are unable to upgrade to SDK v12 or v13 then you would probably need to implement something similar in the application, where you store the log messages temporarily in a buffer, and push them to the UART in thread (main) context from the main loop. Then you are also able to detect buffer overflow on your application buffer, and handle the situation as you see fit.&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;
Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FIFO buffer clogging</title><link>https://devzone.nordicsemi.com/thread/77961?ContentTypeID=1</link><pubDate>Thu, 02 Mar 2017 19:11:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3fef3490-f9a0-4963-bcde-80fb9fb879e3</guid><dc:creator>Pawel</dc:creator><description>&lt;p&gt;&lt;code&gt;UART_TX_BUF_SIZE 2048&lt;/code&gt;
&lt;code&gt;UART_RX_BUF_SIZE 512&lt;/code&gt;
So it is power of 2.
I removed the static keyword before the fifo struct, because I need to have access to them in my function for checking how much space left in fifo buffer.
I need to check if my data packet can fit in fifo buffer to prevent printing corrupted data.
Example of correct output:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;@scan:abcdef12345
@scan:abcdef12345
@scan:abcdef12345
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Example of corrupted output because of fifo buffer overwrites, when a lot of NRF_LOG called:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;@scan:abcdef12345
@scan:abcdef12345
@scan:abcd@scan:abcd12@sca@sc
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;How can I prevent it without editing SDK files?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: FIFO buffer clogging</title><link>https://devzone.nordicsemi.com/thread/77962?ContentTypeID=1</link><pubDate>Tue, 28 Feb 2017 11:38:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:00c5871f-b635-45ea-b42e-db40c2e1e78d</guid><dc:creator>Ole Bauck</dc:creator><description>&lt;p&gt;If the FIFO is full the app_uart_put(..) function should return NRF_ERROR_NO_MEM as this should be the return code from app_fifo_put(..).&lt;/p&gt;
&lt;p&gt;Do you change the UART_TX_BUF_SIZE to something higher? &lt;strong&gt;This should be a power of two&lt;/strong&gt; or else the fifo will not work correctly (the size check uses bitmask).&lt;/p&gt;
&lt;p&gt;Why do you remove the static keyword before the fifo structs? This ensures that the fifo is not placed on the stack. I see you use malloc for the receive buffer, but I would much rather use static (malloc is generally not a good idea on an embedded system).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>