<?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 can I check printf&amp;#39;s buffer?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/94541/how-can-i-check-printf-s-buffer</link><description>Hi 
 Using nRF52DK + SDK17.1 + S112 
 I have retarget enabled &amp;amp; using printf to output over UART (no DMA) 
 What&amp;#39;s the best way to check if printf is busy outputting data? I want to disable the UART after a print to save power but need to wait until all</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 06 Dec 2022 16:35:30 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/94541/how-can-i-check-printf-s-buffer" /><item><title>RE: How can I check printf's buffer?</title><link>https://devzone.nordicsemi.com/thread/399250?ContentTypeID=1</link><pubDate>Tue, 06 Dec 2022 16:35:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bc44f27e-368d-41d2-821e-875328f903c3</guid><dc:creator>Nick_RA</dc:creator><description>&lt;p&gt;OK thanks. I&amp;#39;ll probably use a housekeeping timer ISR anyway so I&amp;#39;ll put a timeout on it which I can reset when I print.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How can I check printf's buffer?</title><link>https://devzone.nordicsemi.com/thread/399212?ContentTypeID=1</link><pubDate>Tue, 06 Dec 2022 13:53:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0ef2f854-2d93-4e09-8d36-252c728539c0</guid><dc:creator>Vidar Berg</dc:creator><description>&lt;p&gt;Hi Nick,&lt;/p&gt;
&lt;p&gt;The app uart libary used by retarget.c does not expose an API to check&amp;nbsp;if there are pending TX transfers. So, the simplest solution is probably to add a small busy-wait (nrf_delay_ms(), etc) before you disable the&amp;nbsp;peripheral.&amp;nbsp;Otherwise, you would have to modify app_uart_fifo.c to include a function to check if there are bytes left in the TX fifo.&lt;/p&gt;
&lt;p&gt;Possibly something&amp;nbsp;like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;bool app_uart_tx_in_progress(void)
{
    bool fifo_empty = false;
    uint32_t size;

    if (FIFO_LENGTH(m_tx_fifo) == 0)
    {
        fifo_empty = true;
    }
    
    return (fifo_empty == false);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Vidar&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>