<?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>How to know the remaining room in UART fifo?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/43716/how-to-know-the-remaining-room-in-uart-fifo</link><description>Dear Sirs, 
 I use the standard printf() function to communicate via UART (with retargeting). 
 Unfortunately could not find a way to not overwrite a buffer. 
 The only workaround I have found is an additional delay as below: 
 printf(&amp;quot;nRF52: command</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sat, 05 Mar 2022 01:53:07 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/43716/how-to-know-the-remaining-room-in-uart-fifo" /><item><title>RE: How to know the remaining room in UART fifo?</title><link>https://devzone.nordicsemi.com/thread/356418?ContentTypeID=1</link><pubDate>Sat, 05 Mar 2022 01:53:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e3e0de0b-04a3-4a44-964e-9a76740ecb70</guid><dc:creator>Chris Ergo</dc:creator><description>&lt;p&gt;I still had to edit app_uart_fifo.c, but I wrote this function instead because I prefer it (less code, and returns 0 for no space instead of -1):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint32_t app_uart_free(void) 
{
    uint32_t free = 0;
    app_fifo_write(&amp;amp;m_tx_fifo, NULL, &amp;amp;free);
    return (free);
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to know the remaining room in UART fifo?</title><link>https://devzone.nordicsemi.com/thread/171216?ContentTypeID=1</link><pubDate>Thu, 14 Feb 2019 16:36:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ed0b7813-d155-4055-a09e-f2c18eae9954</guid><dc:creator>studzinski</dc:creator><description>&lt;p&gt;What splendid idea &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Have a good evening&lt;/p&gt;
&lt;p&gt;Andre&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to know the remaining room in UART fifo?</title><link>https://devzone.nordicsemi.com/thread/171203?ContentTypeID=1</link><pubDate>Thu, 14 Feb 2019 15:55:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b4ef1ace-67e3-4947-93cd-5e1b690a8003</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;It&amp;#39;s just one file!&lt;/p&gt;
&lt;p&gt;If you really don&amp;#39;t want to modify it, then take a copy and use that.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to know the remaining room in UART fifo?</title><link>https://devzone.nordicsemi.com/thread/171199?ContentTypeID=1</link><pubDate>Thu, 14 Feb 2019 15:45:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9d1b831e-4113-4ea6-9ee5-9edc8800d211</guid><dc:creator>studzinski</dc:creator><description>&lt;p&gt;OK, thank you.&lt;/p&gt;
&lt;p&gt;You are right. However, it is exactly what I would like to avoid... (to modify library files).&lt;/p&gt;
&lt;p&gt;It is pity that there is no another, more elegant, way without modifying library.&lt;br /&gt;BTW, it would be very logical to add such function to UART fifo management library...&lt;/p&gt;
&lt;p&gt;Cordially&lt;/p&gt;
&lt;p&gt;Andre&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to know the remaining room in UART fifo?</title><link>https://devzone.nordicsemi.com/thread/171191?ContentTypeID=1</link><pubDate>Thu, 14 Feb 2019 15:09:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3899e131-3fde-49fb-8a3b-79c91955e426</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;Yes - as I said earlier:&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;&lt;strong&gt;Either&lt;/strong&gt; &lt;/em&gt;you need to put that code into the app_uart_fifo.c file - because that&amp;#39;s the only place where&amp;nbsp;m_tx_fifo is in scope&lt;br /&gt;&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;&lt;strong&gt;Or&lt;/strong&gt; &lt;/em&gt;you make&amp;nbsp;m_tx_fifo global&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to know the remaining room in UART fifo?</title><link>https://devzone.nordicsemi.com/thread/171188?ContentTypeID=1</link><pubDate>Thu, 14 Feb 2019 15:01:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6e3888fc-88c8-4810-a098-5738f29d7148</guid><dc:creator>studzinski</dc:creator><description>&lt;p&gt;&lt;span&gt;The function&amp;nbsp; app_fifo&amp;nbsp;_write()&lt;/span&gt; is just what I used.&lt;br /&gt;This is a generic function and can be (I suppose) applied to all fifi using the same structure.&lt;br /&gt;UART fifo has the same data structure...&lt;/p&gt;
&lt;p&gt;I know to write a function using this library. I think the only problem is the UART&amp;nbsp; fifo variable scope...&lt;/p&gt;
&lt;p&gt;I asked you for help, just &lt;strong&gt;to not write my own redundant&lt;/strong&gt; code, because such fifo is already initialized by APP_UART_FIFO_INIT macro...&lt;/p&gt;
&lt;p&gt;Cordially&lt;/p&gt;
&lt;p&gt;Andre&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to know the remaining room in UART fifo?</title><link>https://devzone.nordicsemi.com/thread/171174?ContentTypeID=1</link><pubDate>Thu, 14 Feb 2019 14:12:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:60c60987-44af-4630-84c6-0d83adc4edc7</guid><dc:creator>awneil</dc:creator><description>&lt;p&gt;Ah - you&amp;#39;re looking at app_uart_fifo, which uses the app_fifo library.&lt;/p&gt;
&lt;p&gt;&lt;span&gt;app_uart_fifo doesn&amp;#39;t expose an&amp;nbsp;app_uart_fifo&amp;nbsp;_write() - so you will have to write your own.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;eg, using the code from&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v14.2.0/lib_fifo.html?cp=4_0_2_3_14_7#lib_app_fifo_size"&gt;https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v14.2.0/lib_fifo.html?cp=4_0_2_3_14_7#lib_app_fifo_size&lt;/a&gt;&amp;nbsp;:&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;int32_t app_uart_fifo_free( void )
{
   uint32_t err_code;
   uint32_t data_len;

   // Request number of elements that can be written to the FIFO
   err_code = app_fifo_write(&amp;amp;m_tx_fifo, NULL, &amp;amp;data_len);
   
   // Check if request was successful
   if (err_code == NRF_SUCCESS)
   {
       // data_len contains the number of bytes that can be written
       return data_len;
   }
   else if (err_code == NRF_ERROR_NO_MEM)
   {
       // FIFO is full
       return -1;
   }
   else
   {
      // API parameters incorrect, should not happen
      retrun -2;
   }
}   &lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;(just typed into the forum - untested)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to know the remaining room in UART fifo?</title><link>https://devzone.nordicsemi.com/thread/171156?ContentTypeID=1</link><pubDate>Thu, 14 Feb 2019 13:35:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:08062472-7b78-46d0-a474-da5905801152</guid><dc:creator>awneil</dc:creator><description>[quote userid="16701" url="~/f/nordic-q-a/43716/how-to-know-the-remaining-room-in-uart-fifo/171134"]Is there any direct way in 14.2 SDK library without writing a custom fifo??[/quote]
&lt;p&gt;Surely, you&amp;#39;ve already answered that - use the&amp;nbsp;&lt;strong&gt;app_fifo_write() &lt;/strong&gt;function ?&lt;/p&gt;
&lt;p&gt;You just need to&amp;nbsp;use a buffer that is in-scope at the point of the call&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v14.2.0/lib_fifo.html?cp=4_0_2_3_14_7#lib_app_fifo_size"&gt;infocenter.nordicsemi.com/.../lib_fifo.html&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to know the remaining room in UART fifo?</title><link>https://devzone.nordicsemi.com/thread/171134?ContentTypeID=1</link><pubDate>Thu, 14 Feb 2019 12:46:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b7b4fce5-b981-4b7b-a20d-0670c6bcc5f4</guid><dc:creator>studzinski</dc:creator><description>&lt;p&gt;Of course, I said ARM, because I use it...&lt;/p&gt;
&lt;p&gt;But my question was simple:&lt;/p&gt;
&lt;p&gt;How to know the UART fifo remaining room (initialized by UART_FIFO_INIT macro)?&lt;/p&gt;
&lt;p&gt;Is there any direct way in 14.2 SDK library without writing a custom fifo??&lt;/p&gt;
&lt;p&gt;Cordially&lt;/p&gt;
&lt;p&gt;Andre&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to know the remaining room in UART fifo?</title><link>https://devzone.nordicsemi.com/thread/171129?ContentTypeID=1</link><pubDate>Thu, 14 Feb 2019 12:35:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cfcc5e61-03da-49ba-a573-43c61ab752f7</guid><dc:creator>awneil</dc:creator><description>[quote userid="16701" url="~/f/nordic-q-a/43716/how-to-know-the-remaining-room-in-uart-fifo/171128"]as static, so the ARM compiler limits the scope to the file[/quote]
&lt;p&gt;That&amp;#39;s&amp;nbsp;what the &amp;#39;C&amp;#39; standard defines - nothing specifically to do with ARM!&lt;/p&gt;
&lt;p&gt;If you want the symbol to be accessible from outside that file, you will either have to make it global, or provide an &amp;quot;accessor&amp;quot; function.&lt;/p&gt;
&lt;p&gt;Or you could use a buffer of your own?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to know the remaining room in UART fifo?</title><link>https://devzone.nordicsemi.com/thread/171128?ContentTypeID=1</link><pubDate>Thu, 14 Feb 2019 12:31:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:486e1aab-4313-4283-bac7-e8ca1f2b06eb</guid><dc:creator>studzinski</dc:creator><description>&lt;p&gt;&lt;span&gt;The &lt;strong&gt;m_tx_fifo variable &lt;/strong&gt;is well declared in &lt;strong&gt;app_uart_fifo.c.&amp;nbsp; &lt;/strong&gt;However as static, so the ARM compiler limits the scope to the file. And I do not want to write anything in library file...&lt;strong&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The &lt;strong&gt;app_fifo_write(&amp;amp;m_tx_fifo, NULL, &amp;amp;data_len); &lt;/strong&gt;is used to get the room, as specified in the library documentation...&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;My question is: do you know an another way to get the remaining room in fifo, or the way to know a pointer to actual (assigned) UART fifo in order to use this function?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Cordially&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Andre&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to know the remaining room in UART fifo?</title><link>https://devzone.nordicsemi.com/thread/171114?ContentTypeID=1</link><pubDate>Thu, 14 Feb 2019 12:08:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8ad3670e-a0ee-47f7-b65a-cd5e070330f3</guid><dc:creator>awneil</dc:creator><description>[quote userid="16701" url="~/f/nordic-q-a/43716/how-to-know-the-remaining-room-in-uart-fifo"] I do not know how to get a pointer to the tx fifo buffer[/quote]
&lt;p&gt;That doesn&amp;#39;t seem to have anything to do with the question of finding the remaining space in the buffer?&lt;/p&gt;
&lt;p&gt;Surely, if you have the buffer, then getting a pointer to it is just basic &amp;#39;C&amp;#39; ? Please clarfiy what you&amp;#39;ve tried, and where you&amp;#39;re stuck.&lt;/p&gt;
[quote userid="16701" url="~/f/nordic-q-a/43716/how-to-know-the-remaining-room-in-uart-fifo"]..\..\..\main.c(1041): error:&amp;nbsp; #20: identifier &amp;quot;m_tx_fifo&amp;quot; is undefined[/quote]
&lt;p&gt;It&amp;#39;s telling you that you have not defined &amp;#39;&lt;span&gt;&lt;strong&gt;m_tx_fifo&lt;/strong&gt;&amp;#39; - so you need to define it!&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The &amp;#39;C&amp;#39; programming language requires that you declare things before you use them ...&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>