<?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>nRF9160 flush UART buffer.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/82217/nrf9160-flush-uart-buffer</link><description>Hello! 
 I&amp;#39;m currently working on a project that uses an Icarus IoT board that is connected to a camera through UART. The board is taking pictures with the camera, gathers the picture data through UART, and then sends the picture to AWS with the help</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 02 Dec 2021 08:53:28 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/82217/nrf9160-flush-uart-buffer" /><item><title>RE: nRF9160 flush UART buffer.</title><link>https://devzone.nordicsemi.com/thread/341652?ContentTypeID=1</link><pubDate>Thu, 02 Dec 2021 08:53:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:17a095f4-9af8-43b3-8610-e145f47d1ac1</guid><dc:creator>Baowz</dc:creator><description>&lt;p&gt;Thank you! I will test this out.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF9160 flush UART buffer.</title><link>https://devzone.nordicsemi.com/thread/341626?ContentTypeID=1</link><pubDate>Thu, 02 Dec 2021 07:31:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e45c3d0d-b627-4e68-be50-6da85b17a65a</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;Very crude code below, but goes something like this&lt;/p&gt;
&lt;p&gt;If you have&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;uart_irq_callback_set(dev, uart_irq_handler);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;then in&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void uart_irq_handler(const struct device *dev, void *context)
{
	uint8_t buf;
	while (uart_irq_rx_ready(dev)) {
		uint8_t buf[10];
		int len = uart_fifo_read(dev, buf, sizeof(buf));

		if (len) {
			printk(&amp;quot;read %d bytes\n&amp;quot;, len);
		}
	}
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF9160 flush UART buffer.</title><link>https://devzone.nordicsemi.com/thread/341577?ContentTypeID=1</link><pubDate>Wed, 01 Dec 2021 16:28:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6a933347-58da-4926-b5b4-b45e9e294699</guid><dc:creator>Baowz</dc:creator><description>&lt;p&gt;Not flushing TX should be fine, it&amp;#39;s the RX that receives the biggest amount of data. When you say that it party works and manually flush the RX by reading the whole RX fifo. Do you mind showing me an example of how you would use uart_fifo_read in this case? It would be much appreciated!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF9160 flush UART buffer.</title><link>https://devzone.nordicsemi.com/thread/341539?ContentTypeID=1</link><pubDate>Wed, 01 Dec 2021 13:59:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:57f51915-6137-4825-afee-4460871ab12b</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;partly. This callback is called when there is uart irq triggered nd you can atleast manually flush the rx by reading the whole rx fifo using&amp;nbsp;uart_fifo_read. There is no API natively to flush TX fifo as deep as i can see.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF9160 flush UART buffer.</title><link>https://devzone.nordicsemi.com/thread/341376?ContentTypeID=1</link><pubDate>Tue, 30 Nov 2021 17:59:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1eaa01df-ad82-43cb-81c6-2c2296d97b85</guid><dc:creator>Baowz</dc:creator><description>&lt;p&gt;I&amp;#39;ve added &amp;quot;uart_irq_callback_set(uart, uart_cb)&amp;quot; to the last code snipped instead of k_free(read_buf). The code is not rebooting and might be a solution. Does it seem correct?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF9160 flush UART buffer.</title><link>https://devzone.nordicsemi.com/thread/341372?ContentTypeID=1</link><pubDate>Tue, 30 Nov 2021 17:05:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c6ee5fd6-85b2-4763-95f1-62d533460f12</guid><dc:creator>Baowz</dc:creator><description>&lt;p&gt;These are the cases the buffer is being used:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;/* Buffers for reading UART */
static uint8_t uart_buf[64];
uint8_t read_buf[READ_BUF_SIZE];
uint32_t read_buf_ptr = 0;&lt;/pre&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;void uart_cb(struct device *x) {
	uart_irq_update(x);
	int data_length = 0;

	if (uart_irq_rx_ready(x)) {
		data_length = uart_fifo_read(x, uart_buf, sizeof(uart_buf));
		uart_buf[data_length] = 0;
	}

    // Considering it reads just one character per time
	uint8_t read_char = uart_buf[0];
	read_buf[read_buf_ptr] = read_char;
    read_buf_ptr++;
}&lt;/pre&gt;&lt;br /&gt;I can elaborate further on the code if you have any questions.&lt;br /&gt;&lt;br /&gt;the usage of k_free is more a desperate measure than a reasonable one given the lack of alternatives. I saw it being used in one of Nordics UART samples and tried to recreate it.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF9160 flush UART buffer.</title><link>https://devzone.nordicsemi.com/thread/341283?ContentTypeID=1</link><pubDate>Tue, 30 Nov 2021 12:38:18 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9bab8ceb-ce7d-42f8-a3c1-d2871e01e6cc</guid><dc:creator>Susheel Nuguru</dc:creator><description>&lt;p&gt;app_uart_flush was relying on app_fifo_flush. Fifos are application level buffers that could be controlled in app, but I do not think you can do that when you are using Zephyr system calls to interfact with UART driver.&amp;nbsp;&lt;/p&gt;
[quote user=""]I&amp;#39;ve tried to use k_free(*name of buffer*), but I&amp;#39;m not certain if this is the correct function. The board just ends up rebooting as soon as it reaches this part of the code.[/quote]
&lt;p&gt;Not sure why you are trying k_free here, are the buffers dynamically allocated? if so how k_free would help communicating with the uart driver to flush the driver.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Can you add more code snippets on how you are using&amp;nbsp;read_buf in your code, i am confused by the use of k_free on the buffers and your interpretation of connecting this to uart?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>